MCPcopy Create free account
hub / github.com/couchbase/forestdb / btree_insert

Function btree_insert

src/btree.cc:909–1131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

907}
908
909btree_result btree_insert(struct btree *btree, void *key, void *value)
910{
911 void *addr;
912 size_t nsplitnode = 1;
913 uint8_t *k = alca(uint8_t, btree->ksize);
914 uint8_t *v = alca(uint8_t, btree->vsize);
915 // index# and block ID for each level
916 idx_t *idx = alca(idx_t, btree->height);
917 bid_t *bid = alca(bid_t, btree->height);
918 bid_t _bid;
919 // flags
920 int8_t *modified = alca(int8_t, btree->height);
921 int8_t *moved = alca(int8_t, btree->height);
922 int8_t *ins = alca(int8_t, btree->height);
923 int8_t *minkey_replace = alca(int8_t, btree->height);
924 int8_t height_growup;
925
926 // key, value to be inserted
927 struct list *kv_ins_list = alca(struct list, btree->height);
928 struct kv_ins_item *kv_item;
929 struct list_elem *e;
930
931 // index# where kv is inserted
932 idx_t *idx_ins = alca(idx_t, btree->height);
933 struct bnode **node = alca(struct bnode *, btree->height);
934 int i, j, _is_update = 0;
935
936 // initialize flags
937 for (i=0;i<btree->height;++i) {
938 moved[i] = modified[i] = ins[i] = minkey_replace[i] = 0;
939 }
940 height_growup = 0;
941
942 // initialize temporary variables
943 if (btree->kv_ops->init_kv_var) {
944 btree->kv_ops->init_kv_var(btree, k, v);
945 for (i=0;i<btree->height;++i){
946 list_init(&kv_ins_list[i]);
947 }
948 }
949
950 // copy key-value pair to be inserted into leaf node
951 kv_item = _kv_ins_item_create(btree, key, value);
952 list_push_back(&kv_ins_list[0], &kv_item->le);
953
954 ins[0] = 1;
955
956 // set root node
957 bid[btree->height-1] = btree->root_bid;
958
959 // find path from root to leaf
960 for (i=btree->height-1; i>=0; --i){
961 // read block using bid
962 addr = btree->blk_ops->blk_read(btree->blk_handle, bid[i]);
963 // fetch node structure from block
964 node[i] = _fetch_bnode(btree, addr, i+1);
965
966 // lookup key in current node

Callers 15

fdb_gather_stale_blocksFunction · 0.85
basic_testFunction · 0.85
split_testFunction · 0.85
remove_testFunction · 0.85
flush_testFunction · 0.85
metadata_testFunction · 0.85
seqtree_testFunction · 0.85
basic_testFunction · 0.85
iterator_testFunction · 0.85

Calls 15

_kv_ins_item_createFunction · 0.85
list_push_backFunction · 0.85
_fetch_bnodeFunction · 0.85
_btree_find_entryFunction · 0.85
_bnode_size_checkFunction · 0.85
_btree_add_entryFunction · 0.85
list_nextFunction · 0.85
_btree_get_nsplitnodeFunction · 0.85
_btree_split_nodeFunction · 0.85
list_removeFunction · 0.85
_kv_ins_item_freeFunction · 0.85

Tested by 12

basic_testFunction · 0.68
split_testFunction · 0.68
remove_testFunction · 0.68
flush_testFunction · 0.68
metadata_testFunction · 0.68
seqtree_testFunction · 0.68
basic_testFunction · 0.68
iterator_testFunction · 0.68
two_btree_testFunction · 0.68
range_testFunction · 0.68
subblock_testFunction · 0.68