Note: You need to rm /tmp/coverage.index* for this testing every time because the configuration (i.e block size and order etc.) in those index files is immutable!
Please wait about 10 seconds for test case generation...
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at cmake/CodeCoverage.cmake:127 (MESSAGE):
lcov not found! Aborting...
Call Stack (most recent call first):
tests/CMakeLists.txt:16 (setup_target_for_coverage)
It seems tree->root dump during tree deinit but in case if a process
has shutdown ungracefully in that case the function bplus_tree_init would
not be able to load the tree because no .boot file is available.
To better understand the code,I add some code annotation in head file(bplustree.h).
I think it miht be nesscary for others to understand.
would you mind to merge it to in-memory branch or I can send PR
code here:
/*
* Copyright (C) 2015, Leo Ma <[email protected]>
*/
#ifndef _BPLUS_TREE_H
#define _BPLUS_TREE_H
#define BPLUS_MIN_ORDER 3
#define BPLUS_MAX_ORDER 64
#define BPLUS_MAX_ENTRIES 64
#define BPLUS_MAX_LEVEL 10
typedef int key_t;
struct list_head {
struct list_head *prev, *next;
};
static inline void list_init(struct list_head *link)
{
link->prev = link;
link->next = link;
}
static inline void
__list_add(struct list_head *link, struct list_head *prev, struct list_head *next)
{
link->next = next;
link->prev = prev;
next->prev = link;
prev->next = link;
}
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
prev->next = next;
next->prev = prev;
}
static inline void list_add(struct list_head *link, struct list_head *prev)
{
__list_add(link, prev, prev->next);
}
static inline void list_add_tail(struct list_head *link, struct list_head *head)
{
__list_add(link, head->prev, head);
}
static inline void list_del(struct list_head *link)
{
__list_del(link->prev, link->next);
list_init(link);
}
static inline int list_is_first(struct list_head *link, struct list_head *head)
{
return link->prev == head;
}
static inline int list_is_last(struct list_head *link, struct list_head *head)
{
return link->next == head;
}
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr) - (size_t)(&((type *)0)->member)))
#define list_next_entry(pos, member) \
list_entry((pos)->member.next, typeof(*(pos)), member)
#define list_prev_entry(pos, member) \
list_entry((pos)->member.prev, typeof(*(pos)), member)
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/**
* b plus tree basic node
*
*
*/
struct bplus_node {
/** type indicates leaf node or not
* BPLUS_TREE_LEAF is 0 and BPLUS_TREE_NON_LEAF is 1
*/
int type;
/** parent_key_idx: index of parent node */
int parent_key_idx;
/** piointer to parent node */
struct bplus_non_leaf *parent;
/** pointer to first node(head) in leaf linked list */
struct list_head link;
/** */
int count;
};
/** b plus tree non-leaf(internal) node
* non-leaf node need to carry children node information
* node contains only keys not key-value-pairs
*/
struct bplus_non_leaf {
/** type indicates leaf node or not
* BPLUS_TREE_LEAF is 0 and BPLUS_TREE_NON_LEAF is 1
*/
int type;
/** parent_key_idx: index of parent node */
int parent_key_idx;
/** piointer to parent node */
struct bplus_non_leaf *parent;
/** pointer to first node(head) in leaf linked list
*/
struct list_head link;
/** number of child node */
int children;
/** key array */
int key[BPLUS_MAX_ORDER - 1];
/** pointers to child node */
struct bplus_node *sub_ptr[BPLUS_MAX_ORDER];
};
/** b plus tree leaf node
* leaf node need to carry key-value-pairs
*/
struct bplus_leaf {
/** type indicates leaf node or not
* BPLUS_TREE_LEAF is 0 and BPLUS_TREE_NON_LEAF is 1
*/
int type;
/** parent_key_idx: index of parent node */
int parent_key_idx;
/** piointer to parent node */
struct bplus_non_leaf *parent;
/** pointer to first node(head) in leaf linked list
*/
struct list_head link;
/** number of actual key-value pairs in leaf node */
int entries;
/** key array */
int key[BPLUS_MAX_ENTRIES];
/** val array */
int data[BPLUS_MAX_ENTRIES];
};
/** b plus tree structure */
struct bplus_tree {
/** The actual number of children for a node, referred to here as order */
int order;
/** number of actual key-value pairs in tree */
int entries;
/** height of the tree */
int level;
struct bplus_node *root;
/** double linked list to search leaf node */
struct list_head list[BPLUS_MAX_LEVEL];
};
/** print the whole tree for debugging
*
* @param tree pointer to bplus tree
*/
void bplus_tree_dump(struct bplus_tree *tree);
/** return value acordding to key
*
* @param tree pointer to bplus tree
* @param key key in key-value pair
*/
int bplus_tree_get(struct bplus_tree *tree, key_t key);
/** insert key-value pair to tree
*
* @param tree pointer to bplus tree
* @param key key in key-value pair
* @param data value in key-value pair
*/
int bplus_tree_put(struct bplus_tree *tree, key_t key, int data);
/** return data between [key1,key2]
*
* @param tree pointer to bplus tree
* @param key1 key in key-value pair
* @param key2 value in key-value pair
*/
int bplus_tree_get_range(struct bplus_tree *tree, key_t key1, key_t key2);
/** init b plus tree
* @return a pointer to tree
*
* @param order The actual number of children for a node, referred to here as order
* @param key1 key in key-value pair
* @param key2 key in key-value pair
*/
struct bplus_tree *bplus_tree_init(int order, int entries);
/** destory the tree safely
* @return a pointer to tree
* @param order The actual number of children for a node, referred to here as order
* @param entries number of actual key-value pairs in tree
*/
void bplus_tree_deinit(struct bplus_tree *tree);
#endif /* _BPLUS_TREE_H */
there is a bplus_tree_get_range method there and it turns out this method only returns the first element of bplustree belong the range. However, this is not so great considering range query.
So how to iterator the results of range query, the interfaces which have been provided currently is not enough. How can do that? help wanted::::
Let's suppose the non_leaf node has 3 entries 7, 17, 25, and max_order
of the tree is 3. If suppose a non_leaf node has received a split node request from children for key 20.
Ideally right_node[1] key should be 25 but as per the condition
memmove(&key(right)[pivot + 1], &key(node)[split], (right->children - 2) * sizeof(key_t));
no key will be copied to right[1] because the number of elements will be 0.
I think It should be right->children - 1. Please correct me if I am wrong.
/home/yxy/桌面/bplustree/tests/bplustree_demo.c: In function ‘bplus_tree_setting’:
/home/yxy/桌面/bplustree/tests/bplustree_demo.c:29:25: error: this statement may fall through [-Werror=implicit-fallthrough=]
printf("\n");
^~~~~~~~~~~~
/home/yxy/桌面/bplustree/tests/bplustree_demo.c:30:17: note: here
case 'q':
^~~~
/home/yxy/桌面/bplustree/tests/bplustree_demo.c:54:25: error: this statement may fall through [-Werror=implicit-fallthrough=]
printf("\n");
^~~~~~~~~~~~
/home/yxy/桌面/bplustree/tests/bplustree_demo.c:55:17: note: here
case 'q':
^~~~
/home/yxy/桌面/bplustree/tests/bplustree_demo.c: In function ‘command_process’:
/home/yxy/桌面/bplustree/tests/bplustree_demo.c:196:28: error: this statement may fall through [-Werror=implicit-fallthrough=]
if (number_process(tree, c) < 0) {
^
/home/yxy/桌面/bplustree/tests/bplustree_demo.c:199:17: note: here
case '\n':
^~~~
cc1: all warnings being treated as errors
您好 前辈 执行./coverage_build.sh 时有如下错误
please wait about 10 seconds for test case generation...
-- The C compiler identification is GNU 4.3.4
-- The CXX compiler identification is GNU 4.3.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/liding/coding/bplustree-disk-io/build
Scanning dependencies of target bplustree_coverage
[ 50%] Building C object tests/CMakeFiles/bplustree_coverage.dir/__/lib/bplustree.c.o
/home/liding/coding/bplustree-disk-io/lib/bplustree.c: In function ‘node_fetch’:
/home/liding/coding/bplustree-disk-io/lib/bplustree.c:128: warning: implicit declaration of function ‘pread’
/home/liding/coding/bplustree-disk-io/lib/bplustree.c: In function ‘node_flush’:
/home/liding/coding/bplustree-disk-io/lib/bplustree.c:154: warning: implicit declaration of function ‘pwrite’
[100%] Building C object tests/CMakeFiles/bplustree_coverage.dir/bplustree_coverage.c.o
Linking C executable ../bin/bplustree_coverage
[100%] Built target bplustree_coverage
Scanning dependencies of target coverage
Deleting all .da files in . and subdirectories
Done.
config node order:39 and leaf entries:39 bplustree_coverage: /home/liding/coding/bplustree-disk-io/lib/bplustree.c:144: node_seek: Assertion `len == _block_size' failed.
make[3]: *** [tests/CMakeFiles/coverage] Aborted
make[2]: *** [tests/CMakeFiles/coverage.dir/all] Error 2
make[1]: *** [tests/CMakeFiles/coverage.dir/rule] Erro