Skip to content

Commit 9948f6f

Browse files
authored
Merge pull request #185 from ROSS-org/develop
Misc Develop and Tiebreaker Work
2 parents a2b6bfc + a562993 commit 9948f6f

29 files changed

+1194
-195
lines changed

core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ if (USE_DAMARIS)
113113
SET(ross_srcs ${ross_srcs} ${ROSS_Damaris_SOURCE_DIR}/core/damaris.h)
114114
ENDIF(USE_DAMARIS)
115115

116+
# Use deterministic unbiased RNG tiebreaker for event ties
117+
OPTION(USE_RAND_TIEBREAKER "Build with deterministic unbiased tiebreaker for event ties" ON)
118+
116119
# Use debugging-friendly memory allocation
117120
OPTION(ROSS_ALLOC_DEBUG "Use naive allocator to be more friendly to memory debugging tools" OFF)
118121

core/avl_tree.c

Lines changed: 79 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,31 @@ avlSearch(AvlTree t, tw_event *key)
4545

4646
if (TW_STIME_CMP(key->recv_ts, t->key->recv_ts) == 0) {
4747
// Timestamp is the same
48-
if (key->event_id == t->key->event_id) {
49-
// Event ID is the same
50-
if (key->send_pe == t->key->send_pe) {
51-
// send_pe is the same
52-
return 1;
48+
#ifdef USE_RAND_TIEBREAKER
49+
//this is OK to only compare first tiebreaker because the event ID and PE will settle collisions
50+
if (key->sig.event_tiebreaker[0] == t->key->sig.event_tiebreaker[0]) {
51+
#endif
52+
if (key->event_id == t->key->event_id) {
53+
// Event ID is the same
54+
if (key->send_pe == t->key->send_pe) {
55+
// send_pe is the same
56+
return 1;
57+
}
58+
else {
59+
// send_pe is different
60+
return avlSearch(t->child[key->send_pe > t->key->send_pe], key);
61+
}
62+
}
63+
else {
64+
// Event ID is different
65+
return avlSearch(t->child[key->event_id > t->key->event_id], key);
66+
}
67+
#ifdef USE_RAND_TIEBREAKER
5368
}
5469
else {
55-
// send_pe is different
56-
return avlSearch(t->child[key->send_pe > t->key->send_pe], key);
70+
return avlSearch(t->child[key->sig.event_tiebreaker[0] > t->key->sig.event_tiebreaker[0]], key);
5771
}
58-
}
59-
else {
60-
// Event ID is different
61-
return avlSearch(t->child[key->event_id > t->key->event_id], key);
62-
}
72+
#endif
6373
}
6474
else {
6575
// Timestamp is different
@@ -184,22 +194,32 @@ avlInsert(AvlTree *t, tw_event *key)
184194
}
185195

186196
if (TW_STIME_CMP(key->recv_ts, (*t)->key->recv_ts) == 0) {
187-
// We have a timestamp tie, check the event ID
188-
if (key->event_id == (*t)->key->event_id) {
189-
// We have a event ID tie, check the send_pe
190-
if (key->send_pe == (*t)->key->send_pe) {
191-
// This shouldn't happen but we'll allow it
192-
tw_printf(TW_LOC, "The events are identical!!!\n");
197+
#ifdef USE_RAND_TIEBREAKER
198+
// We have a timestamp tie, check the event tiebreaker
199+
if (key->sig.event_tiebreaker[0] == (*t)->key->sig.event_tiebreaker[0]) {
200+
#endif
201+
if (key->event_id == (*t)->key->event_id) {
202+
// We have a event ID tie, check the send_pe
203+
if (key->send_pe == (*t)->key->send_pe) {
204+
// This shouldn't happen but we'll allow it
205+
tw_printf(TW_LOC, "The events are identical!!!\n");
206+
}
207+
avlInsert(&(*t)->child[key->send_pe > (*t)->key->send_pe], key);
208+
avlRebalance(t);
209+
}
210+
else {
211+
// Event IDs are different
212+
avlInsert(&(*t)->child[key->event_id > (*t)->key->event_id], key);
213+
avlRebalance(t);
214+
}
215+
#ifdef USE_RAND_TIEBREAKER
193216
}
194-
avlInsert(&(*t)->child[key->send_pe > (*t)->key->send_pe], key);
195-
avlRebalance(t);
196-
}
197-
else {
198-
// Event IDs are different
199-
avlInsert(&(*t)->child[key->event_id > (*t)->key->event_id], key);
200-
avlRebalance(t);
201-
}
202-
return;
217+
else {
218+
// event tiebreakers are different
219+
avlInsert(&(*t)->child[key->sig.event_tiebreaker[0] > (*t)->key->sig.event_tiebreaker[0]], key);
220+
avlRebalance(t);
221+
}
222+
#endif
203223
}
204224
else {
205225
// Timestamps are different
@@ -259,33 +279,44 @@ avlDelete(AvlTree *t, tw_event *key)
259279
}
260280

261281
if (TW_STIME_CMP(key->recv_ts, (*t)->key->recv_ts) == 0) {
262-
// We have a timestamp tie, check the event ID
263-
if (key->event_id == (*t)->key->event_id) {
264-
// We have a event ID tie, check the send_pe
265-
if (key->send_pe == (*t)->key->send_pe) {
266-
// This is actually the one we want to delete
267-
target = (*t)->key;
268-
/* do we have a right child? */
269-
if ((*t)->child[1] != AVL_EMPTY) {
270-
/* give root min value in right subtree */
271-
(*t)->key = avlDeleteMin(&(*t)->child[1]);
282+
#ifdef USE_RAND_TIEBREAKER
283+
if (key->sig.event_tiebreaker[0] == (*t)->key->sig.event_tiebreaker[0]) {
284+
//we have an event tiebreaker tie, (same event but different version)
285+
#endif
286+
if (key->event_id == (*t)->key->event_id) {
287+
// We have a event ID tie, check the send_pe
288+
if (key->send_pe == (*t)->key->send_pe) {
289+
// This is actually the one we want to delete
290+
291+
target = (*t)->key;
292+
/* do we have a right child? */
293+
if ((*t)->child[1] != AVL_EMPTY) {
294+
/* give root min value in right subtree */
295+
(*t)->key = avlDeleteMin(&(*t)->child[1]);
296+
}
297+
else {
298+
/* splice out root */
299+
oldroot = (*t);
300+
*t = (*t)->child[0];
301+
avl_free(oldroot);
302+
}
303+
}
304+
else {
305+
// Timestamp and event IDs are the same, but different send_pe
306+
target = avlDelete(&(*t)->child[key->send_pe > (*t)->key->send_pe], key);
307+
}
272308
}
273309
else {
274-
/* splice out root */
275-
oldroot = (*t);
276-
*t = (*t)->child[0];
277-
avl_free(oldroot);
310+
// Timestamps are the same but event IDs differ
311+
target = avlDelete(&(*t)->child[key->event_id > (*t)->key->event_id], key);
278312
}
313+
#ifdef USE_RAND_TIEBREAKER
279314
}
280315
else {
281-
// Timestamp and event IDs are the same, but different send_pe
282-
target = avlDelete(&(*t)->child[key->send_pe > (*t)->key->send_pe], key);
316+
// event tiebreakers are different
317+
target = avlDelete(&(*t)->child[key->sig.event_tiebreaker[0] > (*t)->key->sig.event_tiebreaker[0]], key);
283318
}
284-
}
285-
else {
286-
// Timestamps are the same but event IDs differ
287-
target = avlDelete(&(*t)->child[key->event_id > (*t)->key->event_id], key);
288-
}
319+
#endif
289320
}
290321
else {
291322
// Timestamps are different
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)