Skip to content

Commit f7ca30d

Browse files
committed
Fixed fp path bug that caused issue in 30
1 parent 45bfe5f commit f7ca30d

6 files changed

Lines changed: 85 additions & 84 deletions

File tree

‎.vscode/launch.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"type": "cppdbg",
1010
"request": "launch",
1111
"program": "${workspaceFolder}/build/quart_stail",
12-
"args": ["-N", "50000000", "-f", "../bods/workloads/workload_N50000000_K10_L10.bin"],
12+
"args": ["-N", "50000000", "-f", "../bods/workloads/workload_N50000000_K30_L60.bin"],
1313
"environment": [],
1414
"cwd": "${workspaceFolder}",
1515
"MIMode": "gdb"

‎ArtNodeNewMethods.cpp‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,6 @@ namespace ART {
722722

723723
if (child == tree->fp) {
724724
tree->fp_ref = &this->child[pos];
725-
tree->fp_path[tree->fp_path_length] = child;
726-
tree->fp_path[tree->fp_path_length - 1 ] = this;
727-
tree->fp_path_length++;
728725
}
729726

730727
} else {
@@ -853,6 +850,17 @@ namespace ART {
853850
newNode->count = this->count;
854851
copyPrefix(this, newNode);
855852
*nodeRef = newNode;
853+
delete this;
854+
855+
856+
/*
857+
for (int i = 0; i < tree->fp_path[tree->fp_path_length - 2]->count; i++) {
858+
if (tree->fp_path[tree->fp_path_length - 2]->child[i] == this) {
859+
printf("Child pointer points to this node: %p, Child pointer address: %p\n",
860+
static_cast<void*>(this), static_cast<void*>(&this->child[i]));
861+
}
862+
}
863+
*/
856864

857865
if (tree->fp == this) {
858866
tree->fp = newNode;
@@ -869,7 +877,6 @@ namespace ART {
869877
}
870878
}
871879

872-
delete this;
873880
return newNode->insertNode256OnlyUpdateFp(tree, nodeRef, keyByte, child);
874881
}
875882
}

‎QuARTVariants/QuART_stail.h‎

Lines changed: 52 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,6 @@ namespace ART {
3333
return;
3434
}
3535
else {
36-
/*
37-
int lB = (leafValue >> (8 * (maxPrefixLength - 1 - smartIdx))) & 0xFF;
38-
if (lB == 255) {
39-
printf("tail is changing for %lu\n", value);
40-
counter2++;
41-
smartIdx--;
42-
this->fp_path = {this->root};
43-
this->fp_path_length = 1;
44-
QuART_stail::insert_recursive_always_change_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
45-
return;
46-
}
47-
else if (lB + 1 == key[smartIdx]) {
48-
if (smartIdx == 2) {
49-
if (key[1] == 0 && key[0] == 0) {
50-
printf("tail is changing for %lu\n", value);
51-
counter2++;
52-
this->fp_path = {this->root};
53-
this->fp_path_length = 1;
54-
QuART_stail::insert_recursive_always_change_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
55-
return;
56-
}
57-
}
58-
else if (smartIdx == 1) {
59-
if (key[0] == 0) {
60-
printf("tail is changing for %lu\n", value);
61-
counter2++;
62-
this->fp_path = {this->root};
63-
this->fp_path_length = 1;
64-
QuART_stail::insert_recursive_always_change_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
65-
return;
66-
}
67-
}
68-
counter3++;
69-
//printf("tail is not changing for %lu\n", value);
70-
QuART_stail::insert_recursive_only_update_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
71-
return;
72-
}
73-
else {
74-
counter3++;
75-
//printf("tail is not changing for %lu\n", value);
76-
QuART_stail::insert_recursive_only_update_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
77-
return;
78-
}
79-
*/
8036
if (i == 0) {
8137
if ((key[0] == leafByte + 1) && (key[1] == 0) && (key[2] == 0) &&
8238
((leafValue >> 8 * 2) & 0xFF) == 255 && ((leafValue >> 8) & 0xFF) == 255) {
@@ -201,6 +157,8 @@ namespace ART {
201157

202158
// If the changing node was the fp just straight change the node
203159
if (tree->fp_leaf == node) {
160+
this->fp_path[this->fp_path_length] = newNode;
161+
this->fp_path_length++;
204162
this->fp = newNode;
205163
this->fp_ref = nodeRef;
206164
this->fp_depth = depth + newPrefixLength;
@@ -213,40 +171,58 @@ namespace ART {
213171
return;
214172
}
215173

216-
// Handle prefix of inner node
217-
if (node->prefixLength) {
218-
unsigned mismatchPos = prefixMismatch(node, key, depth, maxKeyLength);
219-
if (mismatchPos != node->prefixLength) {
220-
//printf("prefix mismatch at node address: %p\n", (void*)node);
221-
// Prefix differs, create new node
222-
Node4* newNode = new Node4();
223-
*nodeRef = newNode;
224-
newNode->prefixLength = mismatchPos;
225-
memcpy(newNode->prefix, node->prefix,
226-
min(mismatchPos, maxPrefixLength));
227-
// Break up prefix
228-
if (node->prefixLength < maxPrefixLength) {
229-
newNode->insertNode4Smart(this, nodeRef, node->prefix[mismatchPos], node);
230-
node->prefixLength -= (mismatchPos + 1);
231-
memmove(node->prefix, node->prefix + mismatchPos + 1,
232-
min(node->prefixLength, maxPrefixLength));
233-
} else {
234-
node->prefixLength -= (mismatchPos + 1);
235-
uint8_t minKey[maxKeyLength];
236-
loadKey(getLeafValue(minimum(node)), minKey);
237-
newNode->insertNode4Smart(this, nodeRef, minKey[depth + mismatchPos],
238-
node);
239-
memmove(node->prefix, minKey + depth + mismatchPos + 1,
240-
min(node->prefixLength, maxPrefixLength));
174+
// Handle prefix of inner node
175+
if (node->prefixLength) {
176+
unsigned mismatchPos = prefixMismatch(node, key, depth, maxKeyLength);
177+
if (mismatchPos != node->prefixLength) {
178+
// Prefix differs, create new node
179+
Node4* newNode = new Node4();
180+
*nodeRef = newNode;
181+
newNode->prefixLength = mismatchPos;
182+
memcpy(newNode->prefix, node->prefix,
183+
min(mismatchPos, maxPrefixLength));
184+
// Break up prefix
185+
if (node->prefixLength < maxPrefixLength) {
186+
// If the nodes that being changed is in fp_path
187+
auto it = std::find(fp_path.begin(), fp_path.begin() + fp_path_length, node);
188+
if (it != fp_path.begin() + fp_path_length) {
189+
// Find the position of node in fp_path
190+
size_t pos = std::distance(fp_path.begin(), it);
191+
std::copy_backward(fp_path.begin() + pos, fp_path.begin() + fp_path_length, fp_path.begin() + fp_path_length + 1);
192+
fp_path[pos] = newNode;
193+
fp_path_length++;
194+
//tree->fp_depth += node->prefixLength;
195+
}
196+
newNode->insertNode4Smart(this, nodeRef, node->prefix[mismatchPos], node);
197+
node->prefixLength -= (mismatchPos + 1);
198+
memmove(node->prefix, node->prefix + mismatchPos + 1,
199+
min(node->prefixLength, maxPrefixLength));
200+
} else {
201+
node->prefixLength -= (mismatchPos + 1);
202+
uint8_t minKey[maxKeyLength];
203+
loadKey(getLeafValue(minimum(node)), minKey);
204+
// If the nodes that being changed is in fp_path
205+
auto it = std::find(fp_path.begin(), fp_path.begin() + fp_path_length, node);
206+
if (it != fp_path.begin() + fp_path_length) {
207+
// Find the position of node in fp_path
208+
size_t pos = std::distance(fp_path.begin(), it);
209+
std::copy_backward(fp_path.begin() + pos, fp_path.begin() + fp_path_length, fp_path.begin() + fp_path_length + 1);
210+
fp_path[pos] = newNode;
211+
fp_path_length++;
212+
//tree->fp_depth += node->prefixLength;
213+
}
214+
newNode->insertNode4Smart(this, nodeRef, minKey[depth + mismatchPos],
215+
node);
216+
memmove(node->prefix, minKey + depth + mismatchPos + 1,
217+
min(node->prefixLength, maxPrefixLength));
218+
}
219+
newNode->insertNode4(this, nodeRef, key[depth + mismatchPos],
220+
makeLeaf(value));
221+
return;
241222
}
242-
//printf("fp_ref points to at the end %p\n", static_cast<void*>(*tree->fp_ref));
243-
//printf("nodeRef points to at the end %p\n", static_cast<void*>(*nodeRef));
244-
newNode->insertNode4(this, nodeRef, key[depth + mismatchPos],
245-
makeLeaf(value));
246-
return;
223+
depth += node->prefixLength;
247224
}
248-
depth += node->prefixLength;
249-
}
225+
250226

251227
// Recurse
252228
ArtNode** child = findChild(node, key[depth]);

‎benchmarks/art.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ int main(int argc, char** argv) {
6161
insertion_time += duration.count();
6262
}
6363
//cout << endl;
64-
//tree->printTree();
64+
65+
tree->printTree();
6566

6667
// Query tree
6768
long long query_time = 0;

‎benchmarks/quart_stail.cpp‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,28 @@ int main(int argc, char** argv) {
5151

5252
long long insertion_time = 0;
5353
for (uint64_t i = 0; i < N; i++) {
54-
//cout << i << endl;
54+
//cout << "inserting " << keys[i] << endl;
5555
uint8_t key[4];
5656
ART::loadKey(keys[i], key);
5757
auto start = chrono::high_resolution_clock::now();
5858

5959
//cout << keys[i] << endl;
60+
/*
61+
if (keys[i] != 73) {
62+
tree->insert(key, keys[i]);
63+
}
64+
else {
65+
tree->printTree();
66+
tree->insert(key, keys[i]);
67+
tree->printTree();
68+
}
69+
*/
70+
6071
tree->insert(key, keys[i]);
72+
//tree->printTree();
73+
//tree->printFpPath();
74+
75+
6176
//tree->printTree();
6277
//tree->printFpPath();
6378
// cout << "fp_leaf: " << ART::getLeafValue(tree->fp_leaf) << endl;
@@ -72,6 +87,8 @@ int main(int argc, char** argv) {
7287

7388
}
7489

90+
//tree->printTree();
91+
7592
//cout << "number of fast path inserts in stail: " << tree->counter1 << endl;
7693
//cout << "number of fast path changes in stail: " << tree->counter2 << endl;
7794
//cout << "number of regular inserts in stail: " << tree->counter3 << endl;

‎run_experiments.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ for FILE in ../bods/workloads/workload_N*_K*_L*.bin; do
1919
L=$(echo "$BASENAME" | sed -n 's/.*_N[0-9]*_K[0-9]*_L\([0-9]*\).bin/\1/p')
2020
LOGFILE="${LOGDIR}/log_${BASENAME%.txt}_${SUFFIX}.txt"
2121

22-
for TREE in ART QuART_xtail QuART_lil QuART_iglil QuART_stail; do
22+
for TREE in ART QuART_lil QuART_stail; do
2323
INSERT_SUM=0
2424
QUERY_SUM=0
2525

0 commit comments

Comments
 (0)