Elektra  0.8.18
Functions
split.c File Reference

Interna of splitting functionality. More...

#include <kdberrors.h>
#include <kdbinternal.h>
Include dependency graph for split.c:

Functions

Split * elektraSplitNew (void)
 Allocates a new split object. More...
 
void elektraSplitDel (Split *keysets)
 Delete a split object. More...
 
void elektraSplitRemove (Split *split, size_t where)
 Remove one part of split. More...
 
void elektraSplitResize (Split *split)
 Doubles the size of how many parts of keysets can be appended. More...
 
ssize_t elektraSplitAppend (Split *split, Backend *backend, Key *parentKey, int syncbits)
 Increases the size of split and appends a new empty keyset. More...
 
ssize_t elektraSplitSearchBackend (Split *split, Backend *backend, Key *parent)
 Determines if the backend is already inserted or not. More...
 
int elektraSplitSearchRoot (Split *split, Key *parentKey)
 
int elektraSplitBuildup (Split *split, KDB *kdb, Key *parentKey)
 Walks through kdb->split and adds all backends below parentKey to split. More...
 
int elektraSplitDivide (Split *split, KDB *handle, KeySet *ks)
 Splits up the keysets and search for a sync bit in every key. More...
 
void elektraSplitUpdateFileName (Split *split, KDB *handle, Key *key)
 Update the (configuration) file name for the parent key. More...
 
int elektraSplitAppoint (Split *split, KDB *handle, KeySet *ks)
 Appoints all keys from ks to yet unsynced splits. More...
 
int elektraSplitGet (Split *split, Key *warningKey, KDB *handle)
 Does some work after getting of backends is finished. More...
 
int elektraSplitCheckSize (Split *split)
 Check if any of the split is uninitialized. More...
 
int elektraSplitUpdateSize (Split *split)
 Also update sizes after kdbSet() to recognize multiple kdbSet() attempts. More...
 
int elektraSplitMerge (Split *split, KeySet *dest)
 Merges together all parts of split into dest. More...
 
int elektraSplitSync (Split *split)
 Add sync bits everywhere keys were removed/added. More...
 
void elektraSplitPrepare (Split *split)
 Prepares for kdbSet() mainloop afterwards. More...
 

Detailed Description

Interna of splitting functionality.

Function Documentation

ssize_t elektraSplitAppend ( 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
splitthe split object to work with
backendthe backend which should be appended
parentKeythe parentKey which should be appended
syncbitsthe initial syncstate which should be appended
Return values
-1if no split is found
Returns
the position of the new element: size-1
int elektraSplitAppoint ( Split *  split,
KDB *  handle,
KeySet *  ks 
)

Appoints all keys from ks to yet unsynced splits.

Precondition
elektraSplitBuildup() need to be executed before.
Parameters
splitthe split object to work with
handleto determine to which backend a key belongs
ksthe keyset to appoint to split
Return values
1on success
-1if no backend was found for a key
int elektraSplitBuildup ( 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 elektraSplitNew().
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
splitwill get all backends appended
kdbthe handle to get information about backends
parentKeythe information below which key the backends are from interest
Return values
1always
int elektraSplitCheckSize ( Split *  split)

Check if any of the split is uninitialized.

Parameters
split
Return values
-1if size is wrong
1if everything is ok
void elektraSplitDel ( Split *  keysets)

Delete a split object.

Will free all allocated resources of a split keyset.

Parameters
keysetsthe split object to work with
int elektraSplitDivide ( 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 elektraSplitSync() for the next step.

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

Precondition
elektraSplitBuildup() need to be executed before.
Parameters
splitthe split object to work with
handleto get information where the individual keys belong
ksthe keyset to divide
Return values
0if there were no sync bits
1if there were sync bits
-1if no backend was found for any key
int elektraSplitGet ( Split *  split,
Key *  warningKey,
KDB *  handle 
)

Does some work after getting of backends is finished.

  • Update sizes
  • Removal of wrong keys
Precondition
elektraSplitAppoint() needs to be executed before.
  • check if keys are in correct backend
  • remove syncbits
  • update sizes in the backends
Parameters
splitthe split object to work with
warningKeypostcondition violations are reported here
handlethe handle to preprocess the keys
Return values
1on success
-1if no backend was found for a key or split->parents has invalid namespace
int elektraSplitMerge ( Split *  split,
KeySet *  dest 
)

Merges together all parts of split into dest.

Parameters
splitthe split object to work with
destthe destination keyset where all keysets are appended.
Return values
1on success
Split* elektraSplitNew ( 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
elektraSplitDel()
void elektraSplitPrepare ( 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
splitthe split object to work with
void elektraSplitRemove ( Split *  split,
size_t  where 
)

Remove one part of split.

Parameters
splitthe split object to work with
wherethe position to cut away
Precondition
where must be within the size of the split
Postcondition
split will be removed
void elektraSplitResize ( Split *  split)

Doubles the size of how many parts of keysets can be appended.

Parameters
splitthe split object to work with
ssize_t elektraSplitSearchBackend ( Split *  split,
Backend *  backend,
Key *  parent 
)

Determines if the backend is already inserted or not.

Warning
If no parent Key is given, the default/root backends won't be searched.
Parameters
splitthe split object to work with
backendthe backend to search for
parentthe key to check for domains in default/root backends.
Returns
pos of backend if it already exist
Return values
-1if it does not exist
int elektraSplitSearchRoot ( Split *  split,
Key *  parentKey 
)
Return values
1if one of the backends in split has all keys below parentKey
0if parentKey == 0 or there are keys below or same than parentKey which do not fit in any of split keysets
Parameters
splitthe split object to work with
parentKeythe key which relation is searched for
int elektraSplitSync ( 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 elektraSplitDivide() together with this function can really decide if sync is needed or not.

Precondition
split needs to be processed with elektraSplitDivide() before.
Return values
0if kdbSet() is not needed
1if kdbSet() is needed
-1on wrong keys (also has assert, should not happen)
-2wrong spec state: kdbGet() was not executed before
-3wrong dir state: kdbGet() was not executed before
-4wrong user state: kdbGet() was not executed before
-5wrong system state: kdbGet() was not executed before
Precondition
user/system was split before.
Parameters
splitthe split object to work with
void elektraSplitUpdateFileName ( Split *  split,
KDB *  handle,
Key *  key 
)

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

Parameters
splitthe split to work with
handlethe handle to work with
keythe parentKey that should be updated (name must be correct)
int elektraSplitUpdateSize ( Split *  split)

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

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