From: Shivam Garg Date: Tue, 13 Jun 2017 04:03:20 +0000 (+0900) Subject: Fixed some bugs in arastorage X-Git-Tag: 1.1_Public_Release~514^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3dc3df273b14480fcd8fecb0872ef3c569f4bc58;p=rtos%2Ftinyara.git Fixed some bugs in arastorage --- diff --git a/framework/src/arastorage/db_options.h b/framework/src/arastorage/db_options.h index 3b26f14..e9d959d 100644 --- a/framework/src/arastorage/db_options.h +++ b/framework/src/arastorage/db_options.h @@ -230,6 +230,9 @@ #define DB_TREE_CACHE_LIMIT 10 #endif +#ifdef DB_WIP +#undef DB_WIP /* DB WORK IN PROGRESS */ +#endif /*----------------------------------------------------------------------------*/ /* LVM options. */ diff --git a/framework/src/arastorage/index_bplustree.c b/framework/src/arastorage/index_bplustree.c index cbdf9d3..0ea6614 100644 --- a/framework/src/arastorage/index_bplustree.c +++ b/framework/src/arastorage/index_bplustree.c @@ -54,6 +54,7 @@ #include #include #include +#include #include "result.h" #include "db_options.h" @@ -336,7 +337,10 @@ static db_result_t create(index_t *index) int offset = 0; db_result_t result; uint8_t success = 0; + int curtime; + curtime = time(NULL); + random_init(curtime); tree_t *tree = malloc(sizeof(tree_t)); if (tree == NULL) { DB_LOG_E("DB: Failed to allocate a tree\n"); @@ -715,7 +719,6 @@ static db_result_t insert(index_t *index, attribute_value_t *key, tuple_id_t val { tree_t *tree; long long_key; - qnode_t *tmp_node; tree = (tree_t *)index->opaque_data; long_key = db_value_to_long(key); @@ -730,9 +733,18 @@ static db_result_t insert(index_t *index, attribute_value_t *key, tuple_id_t val DB_LOG_E("DB: Failed to insert key %ld into a bplus-tree index\n", long_key); return DB_INDEX_ERROR; } + + /*************************************************************************************** + * The following code is to implement write through caching structure. + * The write back cache gives better performance as compared to write through cache + * and write back is preferred. + ***************************************************************************************/ +#ifdef DB_WIP + qnode_t *tmp_node; storage_write_to(tree->tree_storage, tree, 0, sizeof(tree_t)); /* Bucket Cache being flushed */ + tmp_node = tree->buck_cache->in_cache.head->next; while (tmp_node != tree->buck_cache->in_cache.tail) { if ((tmp_node->node_state & NODE_STATE_DIRTY) && (tmp_node->node_state & NODE_STATE_VALID)) { @@ -749,7 +761,7 @@ static db_result_t insert(index_t *index, attribute_value_t *key, tuple_id_t val } tmp_node = tmp_node->next; } - +#endif return DB_OK; } diff --git a/framework/src/arastorage/index_manager.c b/framework/src/arastorage/index_manager.c index 7e9980e..92fce29 100644 --- a/framework/src/arastorage/index_manager.c +++ b/framework/src/arastorage/index_manager.c @@ -214,9 +214,11 @@ db_result_t index_destroy(index_t *index) } } list_remove(indices, index); - res = storage_remove(index->descriptor_file); - if (DB_ERROR(res)) { - return res; + if (index->descriptor_file[0] != '\0') { + res = storage_remove(index->descriptor_file); + if (DB_ERROR(res)) { + return res; + } } if (DB_ERROR(storage_remove_index(index->rel, index->attr))) { return DB_STORAGE_ERROR; @@ -384,8 +386,6 @@ tuple_id_t index_get_next(index_iterator_t *iterator, uint8_t matched_condition) if ((iterator->index->attr->flags & ATTRIBUTE_FLAG_UNIQUE) && iterator->next_item_no == 1) { min = db_value_to_long(&iterator->min_value); max = db_value_to_long(&iterator->max_value); - printf("%d\n", __LINE__); - sleep(1); if (min == max) { /* * We stop if this is an equivalence search on an attribute @@ -452,7 +452,9 @@ db_result_t db_indexing(relation_t *rel) DB_LOG_E("DB: Failed to allocate row\n"); return DB_ALLOCATION_ERROR; } - +#ifdef CONFIG_ARASTORAGE_ENABLE_WRITE_BUFFER + storage_flush_insert_buffer(); +#endif DB_LOG_D("DB: Loading the index for %s.%s...\n", index->rel->name, index->attr->name); offset = 0; @@ -478,14 +480,14 @@ db_result_t db_indexing(relation_t *rel) for (tuple_id = 0; tuple_id < cardinality; tuple_id++) { memset(row, 0, sizeof(row)); + DB_LOG_V("DB: Indexing Tuple id %d\n",tuple_id); result = storage_get_row(rel, &tuple_id, row); if (DB_ERROR(result)) { DB_LOG_E("DB: Failed to get a row in relation %s!\n", rel->name); goto errout; } - row += offset; - result = db_phy_to_value(&value, index->attr, row); + result = db_phy_to_value(&value, index->attr, row + offset); if (DB_ERROR(result)) { DB_LOG_E("DB: Failed to get value from row\n"); goto errout; diff --git a/framework/src/arastorage/storage_interface.c b/framework/src/arastorage/storage_interface.c index f5d87d3..59aad94 100644 --- a/framework/src/arastorage/storage_interface.c +++ b/framework/src/arastorage/storage_interface.c @@ -497,7 +497,7 @@ db_result_t storage_get_row(relation_t *rel, tuple_id_t *tuple_id, storage_row_t } if (*tuple_id >= nrows) { - DB_LOG_E("DB : tuple_id : %d nrows : %d\n", &tuple_id, row); + DB_LOG_E("DB : tuple_id : %d nrows : %d\n", *tuple_id, nrows); return DB_FINISHED; }