From a46a46abc407dd22f48f9dc7c6913eaba3ef8b8f Mon Sep 17 00:00:00 2001 From: Shivam Garg Date: Wed, 28 Jun 2017 15:28:15 +0900 Subject: [PATCH] Some bugs have been fixed in arastorage regarding remove relation, integer size in bplustree, flushing of buffer during remove operation and small query byte size. --- framework/src/arastorage/aql_exec.c | 2 +- framework/src/arastorage/db_options.h | 2 +- framework/src/arastorage/index_bplustree.c | 25 ++++++++++++++++++------- framework/src/arastorage/index_manager.c | 1 + framework/src/arastorage/relation.c | 14 ++++++-------- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/framework/src/arastorage/aql_exec.c b/framework/src/arastorage/aql_exec.c index da39a68..a1173bb 100644 --- a/framework/src/arastorage/aql_exec.c +++ b/framework/src/arastorage/aql_exec.c @@ -168,7 +168,7 @@ db_result_t db_exec(char *format) } optype = AQL_GET_EXEC_TYPE(AQL_GET_TYPE(&adt)); - if (optype != AQL_TYPE_CREATE_RELATION) { + if (optype != AQL_TYPE_CREATE_RELATION && optype != AQL_TYPE_REMOVE_RELATION) { rel = aql_get_relation(&adt); if (rel == NULL) { DB_LOG_E("DB : get relation Failed\n"); diff --git a/framework/src/arastorage/db_options.h b/framework/src/arastorage/db_options.h index e9d959d..9a3731b 100644 --- a/framework/src/arastorage/db_options.h +++ b/framework/src/arastorage/db_options.h @@ -101,7 +101,7 @@ /* The maximum size of the LVM bytecode compiled from a single database query. */ #ifndef DB_VM_BYTECODE_SIZE -#define DB_VM_BYTECODE_SIZE 32 +#define DB_VM_BYTECODE_SIZE 128 #endif /* DB_VM_BYTECODE_SIZE */ /*----------------------------------------------------------------------------*/ diff --git a/framework/src/arastorage/index_bplustree.c b/framework/src/arastorage/index_bplustree.c index 0ea6614..2356668 100644 --- a/framework/src/arastorage/index_bplustree.c +++ b/framework/src/arastorage/index_bplustree.c @@ -74,7 +74,7 @@ #define NODE_DEPTH 2 #define LEAF_NODES pow(BRANCH_FACTOR, NODE_DEPTH) #define EMPTY_NODE(node) (node)->val[BRANCH_FACTOR-1] == 0 -#define KEY_MAX 32768 +#define KEY_MAX INT_MAX #define ROW_XOR 0xf6U #define NODE_STATE_VALID 1 #define NODE_STATE_LOCK 2 @@ -128,13 +128,13 @@ * Private Types ****************************************************************************/ struct key_value_pair_s { - uint16_t key; + int key; uint16_t value; }; typedef struct key_value_pair_s pair_t; struct tree_node_s { - uint16_t val[BRANCH_FACTOR]; + int val[BRANCH_FACTOR]; uint16_t id[BRANCH_FACTOR]; uint16_t is_leaf; }; @@ -281,8 +281,10 @@ static db_result_t release(index_t *); static db_result_t insert(index_t *, attribute_value_t *, tuple_id_t); static db_result_t delete(index_t *, attribute_value_t *); static tuple_id_t get_next(index_iterator_t *, uint8_t); -static db_result_t vacuum(tree_t *, relation_t *); +#ifdef DB_WIP +static db_result_t vacuum(tree_t *, relation_t *); +#endif /**************************************************************************** * Private Functions ****************************************************************************/ @@ -811,8 +813,8 @@ static tuple_id_t get_next(index_iterator_t *iterator, uint8_t matched_condition }; int i; static struct iteration_cache cache; - uint16_t key_max; - uint16_t key_min; + int key_max; + int key_min; tree_t *tree; key_min = *(int *)&iterator->min_value; key_max = *(int *)&iterator->max_value; @@ -879,9 +881,11 @@ static tuple_id_t get_next(index_iterator_t *iterator, uint8_t matched_condition if (matched_condition == FALSE) { modify_cache(tree, cache.bucket_id, BUCKET, INVALIDATE); cache_write_bucket(tree, cache.bucket_id, cache.bucket); - if ((double)(tree->deleted) / tree->inserted >= VACUUM_THRESHOLD) { +#ifdef DB_WIP + if ((int)((double)(tree->deleted) * 100 / tree->inserted) >= VACUUM_THRESHOLD) { vacuum(tree, iterator->index->rel); } +#endif } else { modify_cache(tree, cache.bucket_id, BUCKET, UNLOCK); } @@ -929,6 +933,9 @@ static tuple_id_t get_next(index_iterator_t *iterator, uint8_t matched_condition return get_next(iterator, matched_condition); } + + +#ifdef DB_WIP /**************************************************************************** * Name: vacuum * @@ -1010,6 +1017,7 @@ static db_result_t vacuum(tree_t *tree, relation_t *rel) storage_remove(old_rel.tuple_filename); return DB_OK; } +#endif /**************************************************************************** * Name: modify_cache @@ -1437,6 +1445,8 @@ static pair_t *tree_find(tree_t *tree, int key) return NULL; } + +#if (DEBUG & DEBUG_VERBOSE) || (DEBUG & DEBUG_ENABLE) /**************************************************************************** * Name: tree_print * @@ -1477,6 +1487,7 @@ void tree_print(tree_t *tree, int id) modify_cache(tree, id, NODE, UNLOCK); DB_LOG_D("Node End\n"); } +#endif /**************************************************************************** * Name: bucket_read diff --git a/framework/src/arastorage/index_manager.c b/framework/src/arastorage/index_manager.c index 88d7e6d..0d427d2 100644 --- a/framework/src/arastorage/index_manager.c +++ b/framework/src/arastorage/index_manager.c @@ -226,6 +226,7 @@ db_result_t index_destroy(index_t *index) index->rel = NULL; index->attr->index = NULL; index->attr = NULL; + index = NULL; return DB_OK; } diff --git a/framework/src/arastorage/relation.c b/framework/src/arastorage/relation.c index 66f56b7..2698590 100644 --- a/framework/src/arastorage/relation.c +++ b/framework/src/arastorage/relation.c @@ -435,7 +435,12 @@ db_result_t relation_remove(char *name, int remove_tuples) if (rel->references > 1) { return DB_BUSY_ERROR; } - +#ifdef CONFIG_ARASTORAGE_ENABLE_WRITE_BUFFER + /* Flush insert buffer to make sure of writing tuples before removing relation */ + if (DB_SUCCESS(storage_flush_insert_buffer())) { + DB_LOG_D("DB : flush insert buffer!!\n"); + } +#endif result = storage_drop_relation(rel, remove_tuples); relation_free(rel); return result; @@ -983,13 +988,6 @@ db_result_t relation_process_remove(db_handle_t **handle, db_cursor_t *cursor) end_removal: DB_LOG_E("DB: Finished removing tuples. Result relation has %d tuples\n", (*handle)->result_rel->cardinality); -#ifdef CONFIG_ARASTORAGE_ENABLE_WRITE_BUFFER - /* Flush insert buffer to make sure of writing tuples in new relation */ - if (DB_SUCCESS(storage_flush_insert_buffer())) { - DB_LOG_D("DB : flush insert buffer!!\n"); - } -#endif - relation_release((*handle)->rel); /* Rename the name of new relation to old relation */ -- 2.7.4