Scroll to navigation

split.c(3elektra) Elektra split.c(3elektra)

NAME

split.c - Interna of splitting functionality.

SYNOPSIS

#include <kdbassert.h>
#include <kdberrors.h>
#include <kdbinternal.h>

Functions


Split * splitNew (void)
Allocates a new split object. void splitDel (Split *keysets)
Delete a split object. void splitRemove (Split *split, size_t where)
Remove one part of split. ssize_t splitAppend (Split *split, Backend *backend, Key *parentKey, int syncbits)
Increases the size of split and appends a new empty keyset. int splitBuildup (Split *split, KDB *kdb, Key *parentKey)
Walks through kdb->split and adds all backends below parentKey to split. int splitDivide (Split *split, KDB *handle, KeySet *ks)
Splits up the keysets and search for a sync bit in every key. void splitUpdateFileName (Split *split, KDB *handle, Key *key)
Update the (configuration) file name for the parent key. int splitAppoint (Split *split, KDB *handle, KeySet *ks)
Appoints all keys from ks to yet unsynced splits. int splitGet (Split *split, Key *warningKey, KDB *handle)
Does some work after getting of backends is finished. int splitUpdateSize (Split *split)
Also update sizes after kdbSet() to recognize multiple kdbSet() attempts. int splitMerge (Split *split, KeySet *dest)
Merges together all parts of split into dest. int splitSync (Split *split)
Add sync bits everywhere keys were removed/added. void splitPrepare (Split *split)
Prepares for kdbSet() mainloop afterwards.

Detailed Description

Interna of splitting functionality.

Copyright:

BSD License (see LICENSE.md or https://www.libelektra.org)

Function Documentation

ssize_t splitAppend (Split * split, Backend * backend, Key * parentKey, int syncbits)

Increases the size of split and appends a new empty keyset. Initializes the element with the given parameters at size-1 to be used.

Will automatically resize split if needed.

Parameters:

split the split object to work with
backend the backend which should be appended
parentKey the parentKey which should be appended
syncbits the initial syncstate which should be appended

Return values:

-1 if no split is found

Returns:

the position of the new element: size-1

int splitAppoint (Split * split, KDB * handle, KeySet * ks)

Appoints all keys from ks to yet unsynced splits.

Precondition:

splitBuildup() need to be executed before.

Parameters:

split the split object to work with
handle to determine to which backend a key belongs
ks the keyset to appoint to split

Return values:

1 on success
-1 if no backend was found for a key

int splitBuildup (Split * split, KDB * kdb, Key * parentKey)

Walks through kdb->split and adds all backends below parentKey to split. Sets syncbits to 2 if it is a default or root backend (which needs splitting). The information is copied from kdb->split.

Precondition:

split needs to be empty, directly after creation with splitNew().

there needs to be a valid defaultBackend but its ok not to have a trie inside KDB.

parentKey must be a valid key! (could be implemented more generally, but that would require splitting up of keysets of the same backend)

Parameters:

split will get all backends appended
kdb the handle to get information about backends
parentKey the information below which key the backends are from interest

Return values:

1 always

void splitDel (Split * keysets)

Delete a split object. Will free all allocated resources of a split keyset.

Parameters:

keysets the split object to work with

int splitDivide (Split * split, KDB * handle, KeySet * ks)

Splits up the keysets and search for a sync bit in every key. It does not check if there were removed keys, see splitSync() for the next step.

It does not create new backends, this has to be done by buildup before.

Precondition:

splitBuildup() need to be executed before.

Parameters:

split the split object to work with
handle to get information where the individual keys belong
ks the keyset to divide

Return values:

0 if there were no sync bits
1 if there were sync bits
-1 if no backend was found for any key

int splitGet (Split * split, Key * warningKey, KDB * handle)

Does some work after getting of backends is finished.

  • Update sizes
  • Removal of wrong keys

Precondition:

splitAppoint() needs to be executed before.
  • check if keys are in correct backend
  • remove syncbits
  • update sizes in the backends

Parameters:

split the split object to work with
warningKey postcondition violations are reported here
handle the handle to preprocess the keys

Return values:

1 on success
-1 if no backend was found for a key or split->parents has invalid namespace

int splitMerge (Split * split, KeySet * dest)

Merges together all parts of split into dest.

Parameters:

split the split object to work with
dest the destination keyset where all keysets are appended.

Return values:

1 on success

Split* splitNew (void)

Allocates a new split object. Splits up a keyset into multiple keysets where each of them will passed to the correct kdbSet().

Initially the size is 0 and alloc is APPROXIMATE_NR_OF_BACKENDS.

Returns:

a fresh allocated split object

See also:

splitDel()

void splitPrepare (Split * split)

Prepares for kdbSet() mainloop afterwards. All splits which do not need sync are removed and a deep copy of the remaining keysets is done.

Parameters:

split the split object to work with

void splitRemove (Split * split, size_t where)

Remove one part of split.

Parameters:

split the split object to work with
where the position to cut away

Precondition:

where must be within the size of the split

Postcondition:

split will be removed

int splitSync (Split * split)

Add sync bits everywhere keys were removed/added.

  • checks if the size of a previous kdbGet() is unchanged.
  • checks if in correct state (kdbGet() needs to be executed before)

Only splitDivide() together with this function can really decide if sync is needed or not.

Precondition:

split needs to be processed with splitDivide() before.

Return values:

0 if kdbSet() is not needed
1 if kdbSet() is needed
-1 on wrong keys (also has assert, should not happen)
-2 wrong spec state: kdbGet() was not executed before
-3 wrong dir state: kdbGet() was not executed before
-4 wrong user state: kdbGet() was not executed before
-5 wrong system state: kdbGet() was not executed before

Precondition:

user/system was split before.

Parameters:

split the split object to work with

void splitUpdateFileName (Split * split, KDB * handle, Key * key)

Update the (configuration) file name for the parent key.

Parameters:

split the split to work with
handle the handle to work with
key the parentKey that should be updated (name must be correct)

int splitUpdateSize (Split * split)

Also update sizes after kdbSet() to recognize multiple kdbSet() attempts.

Warning:

cant use the same code with splitGet because there is no default split part for kdbSet().

Author

Generated automatically by Doxygen for Elektra from the source code.

Mon Jan 15 2018 Version 0.8.20