From eb04cebb16bf919d7edd3b12923cf27efc1c972e Mon Sep 17 00:00:00 2001 From: Jakub Schmiegel Date: Fri, 11 Jan 2019 15:11:21 +0100 Subject: [PATCH 1/4] Added flushing of reserved modifications, set_value used for initialization of Node child --- lib/pmem/ARTree.cpp | 20 +++++++++++++++++++- lib/pmem/ARTree.h | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/pmem/ARTree.cpp b/lib/pmem/ARTree.cpp index cc8eb0f..621bd4d 100644 --- a/lib/pmem/ARTree.cpp +++ b/lib/pmem/ARTree.cpp @@ -273,6 +273,9 @@ void TreeImpl::allocateFullLevels(persistent_ptr node, actionsCounter++; node256_new->depth = depth; node256_new->type = TYPE256; + pmemobj_flush(_pm_pool.get_handle(), + pmemobj_direct(*node256_new.raw_ptr()), + sizeof(Node256)); children[i] = node256_new; } else if (LEVEL_TYPE[depth] == TYPE_LEAF_COMPRESSED) { nodeLeafCompressed_new = pmemobj_xreserve( @@ -290,6 +293,9 @@ void TreeImpl::allocateFullLevels(persistent_ptr node, nodeLeafCompressed_new->type = TYPE_LEAF_COMPRESSED; // Temporarily disable the node nodeLeafCompressed_new->key = -1; + pmemobj_flush(_pm_pool.get_handle(), + pmemobj_direct(*nodeLeafCompressed_new.raw_ptr()), + sizeof(NodeLeafCompressed)); children[i] = nodeLeafCompressed_new; } @@ -307,7 +313,17 @@ void TreeImpl::allocateFullLevels(persistent_ptr node, throw OperationFailedException(Status(ALLOCATION_ERROR)); } for (int i = 0; i < NODE_SIZE[node->type]; i++) { - node256->children[i] = children[i]; + // node256->children[i] = children[i]; + pmemobj_set_value(_pm_pool.get_handle(), + &(actionsArray[actionsCounter]), + &((node256->children[i]).raw_ptr()->pool_uuid_lo), + children[i].raw_ptr()->pool_uuid_lo); + actionsCounter++; + pmemobj_set_value(_pm_pool.get_handle(), + &(actionsArray[actionsCounter]), + &((node256->children[i]).raw_ptr()->off), + children[i].raw_ptr()->off); + actionsCounter++; } } } @@ -363,6 +379,7 @@ ValueWrapper *TreeImpl::findValueInNode(persistent_ptr current, * the same key. This is still not thread-safe. */ val->location = EMPTY; + pmemobj_flush(_pm_pool.get_handle(), val, sizeof(ValueWrapper)); // Enable the node nodeLeafCompressed->key = keyCalc; return val; @@ -399,6 +416,7 @@ ValueWrapper *TreeImpl::findValueInNode(persistent_ptr current, int actionsCounter = 0; allocateFullLevels(node256, 1, actionsArray, actionsCounter); + pmemobj_drain(_pm_pool.get_handle()); int status = pmemobj_publish(_pm_pool.get_handle(), actionsArray, actionsCounter); actionsCounter = 0; diff --git a/lib/pmem/ARTree.h b/lib/pmem/ARTree.h index 250b8df..f523ce2 100644 --- a/lib/pmem/ARTree.h +++ b/lib/pmem/ARTree.h @@ -54,7 +54,7 @@ const int LEVEL_TYPE[] = {TYPE256, TYPE256, TYPE256, // how many levels will be created on ARTree initialization const int PREALLOC_LEVELS = 1; // size of table for actions for each Node -#define ACTION_NUMBER_NODE256 (1 + 256) +#define ACTION_NUMBER_NODE256 (1 + 256 + 2 * 256) #define ACTION_NUMBER_COMPRESSED 1 #define KEY_SIZE 12 From 6d371088b8497544f29795d2467428756657d722 Mon Sep 17 00:00:00 2001 From: Jakub Schmiegel Date: Tue, 15 Jan 2019 11:09:32 +0100 Subject: [PATCH 2/4] Flushing optimization --- lib/pmem/ARTree.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/pmem/ARTree.cpp b/lib/pmem/ARTree.cpp index 621bd4d..e806613 100644 --- a/lib/pmem/ARTree.cpp +++ b/lib/pmem/ARTree.cpp @@ -294,8 +294,7 @@ void TreeImpl::allocateFullLevels(persistent_ptr node, // Temporarily disable the node nodeLeafCompressed_new->key = -1; pmemobj_flush(_pm_pool.get_handle(), - pmemobj_direct(*nodeLeafCompressed_new.raw_ptr()), - sizeof(NodeLeafCompressed)); + &nodeLeafCompressed_new->depth, 2 * sizeof(int)); children[i] = nodeLeafCompressed_new; } @@ -379,9 +378,12 @@ ValueWrapper *TreeImpl::findValueInNode(persistent_ptr current, * the same key. This is still not thread-safe. */ val->location = EMPTY; - pmemobj_flush(_pm_pool.get_handle(), val, sizeof(ValueWrapper)); + pmemobj_flush(_pm_pool.get_handle(), val->location, + sizeof(ValueWrapper->location)); // Enable the node nodeLeafCompressed->key = keyCalc; + pmemobj_flush(_pm_pool.get_handle(), &(nodeLeafCompressed->key), + sizeof(nodeLeafCompressed->key)); return val; } else { DAQ_DEBUG("findValueInNode: not allocate, keyCalc=" + From 4180d5dc222461620914b0af7e6e20e48b8604f0 Mon Sep 17 00:00:00 2001 From: Jakub Schmiegel Date: Tue, 15 Jan 2019 11:26:07 +0100 Subject: [PATCH 3/4] Minor corrections --- lib/pmem/ARTree.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pmem/ARTree.cpp b/lib/pmem/ARTree.cpp index e806613..910b65a 100644 --- a/lib/pmem/ARTree.cpp +++ b/lib/pmem/ARTree.cpp @@ -378,8 +378,8 @@ ValueWrapper *TreeImpl::findValueInNode(persistent_ptr current, * the same key. This is still not thread-safe. */ val->location = EMPTY; - pmemobj_flush(_pm_pool.get_handle(), val->location, - sizeof(ValueWrapper->location)); + pmemobj_flush(_pm_pool.get_handle(), &(val->location), + sizeof(val->location)); // Enable the node nodeLeafCompressed->key = keyCalc; pmemobj_flush(_pm_pool.get_handle(), &(nodeLeafCompressed->key), From c529c396b85e86946bf0b4c4a87fad19511762f3 Mon Sep 17 00:00:00 2001 From: Jakub Schmiegel Date: Fri, 18 Jan 2019 08:58:26 +0100 Subject: [PATCH 4/4] Removing DRAIN because of PUBLISH --- lib/pmem/ARTree.cpp | 9 +++++++-- lib/pmem/ARTree.h | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/pmem/ARTree.cpp b/lib/pmem/ARTree.cpp index 910b65a..78a3a98 100644 --- a/lib/pmem/ARTree.cpp +++ b/lib/pmem/ARTree.cpp @@ -294,7 +294,11 @@ void TreeImpl::allocateFullLevels(persistent_ptr node, // Temporarily disable the node nodeLeafCompressed_new->key = -1; pmemobj_flush(_pm_pool.get_handle(), - &nodeLeafCompressed_new->depth, 2 * sizeof(int)); + &nodeLeafCompressed_new->depth, sizeof(int)); + pmemobj_flush(_pm_pool.get_handle(), + &nodeLeafCompressed_new->type, sizeof(int)); + pmemobj_flush(_pm_pool.get_handle(), + &nodeLeafCompressed_new->key, sizeof(uint32_t)); children[i] = nodeLeafCompressed_new; } @@ -418,7 +422,8 @@ ValueWrapper *TreeImpl::findValueInNode(persistent_ptr current, int actionsCounter = 0; allocateFullLevels(node256, 1, actionsArray, actionsCounter); - pmemobj_drain(_pm_pool.get_handle()); + // drain is not needed if we are publishing in the same + // thread pmemobj_drain(_pm_pool.get_handle()); int status = pmemobj_publish(_pm_pool.get_handle(), actionsArray, actionsCounter); actionsCounter = 0; diff --git a/lib/pmem/ARTree.h b/lib/pmem/ARTree.h index f523ce2..5192c2e 100644 --- a/lib/pmem/ARTree.h +++ b/lib/pmem/ARTree.h @@ -54,7 +54,9 @@ const int LEVEL_TYPE[] = {TYPE256, TYPE256, TYPE256, // how many levels will be created on ARTree initialization const int PREALLOC_LEVELS = 1; // size of table for actions for each Node -#define ACTION_NUMBER_NODE256 (1 + 256 + 2 * 256) +#define CHILDREN_SETTING_ACTIONS 2 * 256 +#define CHILDREN_NUMBER 256 +#define ACTION_NUMBER_NODE256 (1 + CHILDREN_NUMBER + CHILDREN_SETTING_ACTIONS) #define ACTION_NUMBER_COMPRESSED 1 #define KEY_SIZE 12 @@ -100,6 +102,7 @@ class Node { int depth; // Type of Node: Node256 or compressed int type; + std::atomic counter; }; /*