Pārlūkot izejas kodu

Ticket 49310 - remove sds logging in debug builds

Bug Description:  During a load test we noticed that debug builds
would output a large amount of sds logging. Because this uses
stdout, this locks the print buffer causing a serialisation point.

Fix Description:  Macro the SDS logging to -DSDS_DEBUG which is
only required for working on the library.

https://pagure.io/389-ds-base/issue/49310

Author: wibrown

Review by: mreynolds (Thanks!)
William Brown 8 gadi atpakaļ
vecāks
revīzija
8f42060fa5

+ 6 - 6
src/libsds/external/csiphash/csiphash.c

@@ -97,13 +97,13 @@ uint64_t sds_siphash13(const void *src, size_t src_sz, const char key[16]) {
     uint8_t *m = (uint8_t *)in;
 
     switch (src_sz) {
-        case 7: pt[6] = m[6];
-        case 6: pt[5] = m[5];
-        case 5: pt[4] = m[4];
+        case 7: pt[6] = m[6]; /* FALLTHRU */
+        case 6: pt[5] = m[5]; /* FALLTHRU */
+        case 5: pt[4] = m[4]; /* FALLTHRU */
         case 4: *((uint32_t*)&pt[0]) = *((uint32_t*)&m[0]); break;
-        case 3: pt[2] = m[2];
-        case 2: pt[1] = m[1];
-        case 1: pt[0] = m[0];
+        case 3: pt[2] = m[2]; /* FALLTHRU */
+        case 2: pt[1] = m[1]; /* FALLTHRU */
+        case 1: pt[0] = m[0]; /* FALLTHRU */
     }
     b |= _le64toh(t);
 

+ 2 - 2
src/libsds/include/sds.h

@@ -426,7 +426,7 @@ typedef struct _sds_bptree_transaction {
  * and leaves of the structure.
  */
 typedef struct _sds_bptree_node {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     /**
      * checksum of the structure data to detect errors. Must be the first element
      * in the struct.
@@ -1367,7 +1367,7 @@ typedef struct _sds_ht_node {
     uint32_t checksum;
     uint64_t txn_id;
     uint_fast32_t count;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     uint64_t depth;
 #endif
     struct _sds_ht_node *parent;

+ 19 - 19
src/libsds/sds/bpt/bpt.c

@@ -13,7 +13,7 @@
 sds_result
 sds_bptree_init(sds_bptree_instance **binst_ptr, uint16_t checksumming, int64_t (*key_cmp_fn)(void *a, void *b), void (*value_free_fn)(void *value), void (*key_free_fn)(void *key), void *(*key_dup_fn)(void *key) ) {
     if (binst_ptr == NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_btree_init", "Invalid pointer");
 #endif
         return SDS_NULL_POINTER;
@@ -31,7 +31,7 @@ sds_bptree_init(sds_bptree_instance **binst_ptr, uint16_t checksumming, int64_t
     (*binst_ptr)->root = sds_bptree_node_create();
 
     // Now update the checksums
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if ((*binst_ptr)->offline_checksumming) {
         sds_bptree_crc32c_update_node((*binst_ptr)->root);
         sds_bptree_crc32c_update_instance(*binst_ptr);
@@ -77,7 +77,7 @@ sds_bptree_insert(sds_bptree_instance *binst, void *key, void *value) {
     sds_bptree_node *next_node = NULL;
     void *next_key = key;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_insert", "==> Beginning insert of %d", key);
 #endif
 
@@ -118,7 +118,7 @@ sds_bptree_insert(sds_bptree_instance *binst, void *key, void *value) {
 
     }
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_insert", "<== Finishing insert of %d", key);
 #endif
 
@@ -134,7 +134,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
     sds_bptree_node *next_node = NULL;
     sds_bptree_node *deleted_node = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_delete", "==> Beginning delete of %d", key);
 #endif
 
@@ -197,7 +197,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
         sds_bptree_node *left = NULL;
         sds_bptree_node *right = NULL;
         sds_bptree_node_siblings(next_node, &left, &right);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_bptree_delete", " %p -> %p -> %p", left, next_node, right);
         sds_log("sds_bptree_delete", " next_node->item_count = %d", next_node->item_count);
         if (right != NULL) {
@@ -209,7 +209,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
 #endif
         if (right != NULL && right->item_count > SDS_BPTREE_HALF_CAPACITY) {
             /* Does right have excess keys? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_delete", "Right leaf borrow");
 #endif
             sds_bptree_leaf_right_borrow(binst, next_node, right);
@@ -217,13 +217,13 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
             next_node = right;
         } else if (left != NULL && left->item_count > SDS_BPTREE_HALF_CAPACITY) {
             /* Does left have excess keys? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_delete", "Left leaf borrow");
 #endif
             sds_bptree_leaf_left_borrow(binst, left, next_node);
         } else if (right != NULL && right->item_count <= SDS_BPTREE_HALF_CAPACITY) {
             /* Does right want to merge? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_delete", "Right leaf contract");
 #endif
             sds_bptree_leaf_compact(binst, next_node, right);
@@ -231,7 +231,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
             deleted_node = right;
         } else if (left != NULL && left->item_count <= SDS_BPTREE_HALF_CAPACITY) {
             /* Does left want to merge? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_delete", "Left leaf contract");
 #endif
             sds_bptree_leaf_compact(binst, left, next_node);
@@ -268,7 +268,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
 
             if (deleted_node != NULL) {
                 /* Make sure we delete this value from our branch */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_bptree_delete", "Should be removing %p from branch %p here!", deleted_node, target_node);
 #endif
                 sds_bptree_branch_delete(binst, target_node, deleted_node);
@@ -276,7 +276,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
                 deleted_node = NULL;
             } else {
                 /* It means a borrow was probably done somewhere, so we need to fix the path */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_bptree_delete", "Should be fixing %p key to child %p here!", target_node, next_node);
 #endif
                 sds_bptree_branch_key_fixup(binst, target_node, next_node);
@@ -304,7 +304,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
                  * the merge by a fraction, to allow space for 3 keys and 3 keys.
                  *
                  */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_bptree_delete", " %p -> %p -> %p", left, next_node, right);
                 sds_log("sds_bptree_delete", " next_node->item_count = %d", next_node->item_count);
                 if (right != NULL) {
@@ -317,7 +317,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
 
                 if (right != NULL && right->item_count >= SDS_BPTREE_HALF_CAPACITY) {
                     /* Does right have excess keys? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_delete", "Right branch borrow");
 #endif
                     sds_bptree_branch_right_borrow(binst, next_node, right);
@@ -325,13 +325,13 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
                     next_node = right;
                 } else if (left != NULL && left->item_count >= SDS_BPTREE_HALF_CAPACITY) {
                     /* Does left have excess keys? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_delete", "Left branch borrow");
 #endif
                     sds_bptree_branch_left_borrow(binst, left, next_node);
                 } else if (right != NULL && right->item_count < SDS_BPTREE_HALF_CAPACITY) {
                     /* Does right want to merge? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_delete", "Right branch contract");
 #endif
                     sds_bptree_branch_compact(binst, next_node, right);
@@ -340,7 +340,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
                     deleted_node = right;
                 } else if (left != NULL && left->item_count < SDS_BPTREE_HALF_CAPACITY) {
                     /* Does left want to merge? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_delete", "Left branch contract");
 #endif
                     sds_bptree_branch_compact(binst, left, next_node);
@@ -352,7 +352,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
             } else if (target_node == NULL && next_node->item_count == 0) {
                 /* It's time to compact the root! */
                 /* We only have one child at this point, so they become the new root */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_bptree_delete", "Should be deleting root here!");
                 if (binst->root != next_node) {
                     result = SDS_UNKNOWN_ERROR;
@@ -365,7 +365,7 @@ sds_bptree_delete(sds_bptree_instance *binst, void *key) {
         } // While target node
     } // If under half capacity
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
 fail:
     sds_log("sds_bptree_insert", "<== Finishing delete of %d", key);
 #endif

+ 1 - 1
src/libsds/sds/bpt/bpt.h

@@ -12,7 +12,7 @@
 #include "../sds_internal.h"
 #include <sds.h>
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
 sds_result sds_bptree_crc32c_verify_instance(sds_bptree_instance *binst);
 void sds_bptree_crc32c_update_instance(sds_bptree_instance *binst);
 sds_result sds_bptree_crc32c_verify_node(sds_bptree_node *node);

+ 35 - 35
src/libsds/sds/bpt/common.c

@@ -20,7 +20,7 @@ sds_bptree_node_create() {
     node->parent = NULL;
     node->txn_id = 0;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_node_create", "Creating node_%p item_count=%d\n", node, node->item_count);
 #endif
 
@@ -30,7 +30,7 @@ sds_bptree_node_create() {
 
 sds_result
 sds_bptree_node_destroy(sds_bptree_instance *binst, sds_bptree_node *node) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_node_destroy", "Freeing node_%p", node);
 #endif
     for (size_t i = 0; i < node->item_count; i += 1) {
@@ -45,7 +45,7 @@ sds_bptree_node_destroy(sds_bptree_instance *binst, sds_bptree_node *node) {
 
     sds_free(node);
     // Since we updated the node id.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     // binst->node_count -= 1;
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_instance(binst);
@@ -97,7 +97,7 @@ sds_bptree_node_node_index(sds_bptree_node *parent, sds_bptree_node *child) {
 // How can we make this handle errors safely?
 void
 sds_bptree_node_node_replace(sds_bptree_node *target_node, sds_bptree_node *origin_node, sds_bptree_node *replace_node) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_node_node_replace", "Replace node_%p to overwrite node_%p in node_%p\n", origin_node, replace_node, target_node);
 #endif
     size_t index = sds_bptree_node_node_index(target_node, origin_node);
@@ -180,7 +180,7 @@ sds_bptree_node_list_to_tree(sds_bptree_instance *binst, sds_bptree_node *node)
     void *next_key = NULL;
 
     binst->root = node;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(node);
         sds_bptree_crc32c_update_instance(binst);
@@ -201,7 +201,7 @@ sds_bptree_node_list_to_tree(sds_bptree_instance *binst, sds_bptree_node *node)
 void
 sds_bptree_leaf_insert(sds_bptree_instance *binst, sds_bptree_node *node, void *key, void *new_value) {
     /* This is called when you know you have space already */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_leaf_insert", "node_%p key %" PRIu64 " ", node, key);
 #endif
     size_t index = sds_bptree_node_key_lt_index(binst->key_cmp_fn, node, key);
@@ -218,7 +218,7 @@ sds_bptree_leaf_insert(sds_bptree_instance *binst, sds_bptree_node *node, void *
     node->item_count = node->item_count + 1;
 
     // Update the checksum.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(node);
     }
@@ -300,7 +300,7 @@ sds_bptree_insert_leaf_node(sds_bptree_instance *binst, sds_bptree_node *tnode,
 void
 sds_bptree_branch_insert(sds_bptree_instance *binst, sds_bptree_node *node, void *key, sds_bptree_node *new_node) {
     /* Remember, we already checked for duplicate keys! */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_branch_insert", "new_node %p key %" PRIu64 " to node %p", new_node, key, node);
 #endif
 
@@ -334,7 +334,7 @@ sds_bptree_branch_insert(sds_bptree_instance *binst, sds_bptree_node *node, void
     new_node->parent = node;
 
     // Update the checksum.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(node);
         sds_bptree_crc32c_update_node(new_node);
@@ -346,7 +346,7 @@ sds_bptree_branch_insert(sds_bptree_instance *binst, sds_bptree_node *node, void
 void
 sds_bptree_leaf_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *left_node, sds_bptree_node *right_node, void *key, void *new_value) {
     /* Remember, we already checked for duplicate keys! */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_leaf_split_and_insert", "left %p -> right %p key %" PRIu64 " ", left_node, right_node, key);
 #endif
 
@@ -373,7 +373,7 @@ sds_bptree_leaf_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *le
     if (binst->key_cmp_fn(key, right_node->keys[0]) >= 1) {
         /* Insert to the right */
         // Update the checksum.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (binst->offline_checksumming) {
             sds_bptree_crc32c_update_node(left_node);
         }
@@ -382,7 +382,7 @@ sds_bptree_leaf_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *le
     } else {
         /* Insert to the left */
         // Update the checksum.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (binst->offline_checksumming) {
             sds_bptree_crc32c_update_node(right_node);
         }
@@ -396,7 +396,7 @@ sds_bptree_branch_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *
     /* !!!!! STARTING TO CHANGE THE NODE !!!!!! */
     /*  Right node is always new! */
     sds_bptree_node *rchild = NULL;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_branch_split_and_insert", "left %p -> right %p key %" PRIu64 "", left_node, right_node, key);
 #endif
 
@@ -413,7 +413,7 @@ sds_bptree_branch_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *
         rchild = (sds_bptree_node *)right_node->values[i + 1];
         rchild->parent = right_node;
         right_node->item_count += 1;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (binst->offline_checksumming) {
             sds_bptree_crc32c_update_node(rchild);
         }
@@ -427,7 +427,7 @@ sds_bptree_branch_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *
     right_node->values[0] = left_node->values[SDS_BPTREE_HALF_CAPACITY];
     rchild = (sds_bptree_node *)right_node->values[0];
     rchild->parent = right_node;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(rchild);
     }
@@ -438,14 +438,14 @@ sds_bptree_branch_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *
      * it up the tree at this point. No need to dup!
      */
     *excluded_key = left_node->keys[SDS_BPTREE_HALF_CAPACITY - 1];
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_branch_split_and_insert", "excluding %d", *excluded_key);
 #endif
     left_node->keys[SDS_BPTREE_HALF_CAPACITY - 1] = NULL;
     left_node->item_count -= 1;
 
     if (binst->key_cmp_fn(key, *excluded_key) < 0) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (binst->offline_checksumming) {
             sds_bptree_crc32c_update_node(right_node);
         }
@@ -453,7 +453,7 @@ sds_bptree_branch_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *
         /* Now trigger the insert to the left node. */
         sds_bptree_branch_insert(binst, left_node, key, new_node);
     } else {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (binst->offline_checksumming) {
             sds_bptree_crc32c_update_node(left_node);
         }
@@ -465,7 +465,7 @@ sds_bptree_branch_split_and_insert(sds_bptree_instance *binst, sds_bptree_node *
 
 void
 sds_bptree_root_insert(sds_bptree_instance *binst, sds_bptree_node *left_node, sds_bptree_node *right_node, void *key) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_root_insert", "left_node %p, key %d, right_node %p", left_node, key, right_node);
 #endif
     sds_bptree_node *root_node = sds_bptree_node_create();
@@ -486,7 +486,7 @@ sds_bptree_root_insert(sds_bptree_instance *binst, sds_bptree_node *left_node, s
     right_node->parent = root_node;
     binst->root = root_node;
     // Update the checksum.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(root_node);
         sds_bptree_crc32c_update_node(left_node);
@@ -498,7 +498,7 @@ sds_bptree_root_insert(sds_bptree_instance *binst, sds_bptree_node *left_node, s
 
 void
 sds_bptree_leaf_delete(sds_bptree_instance *binst, sds_bptree_node *node, void *key) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_leaf_delete", "deleting %d from %p", key, node);
 #endif
     /* Find the value */
@@ -522,7 +522,7 @@ sds_bptree_leaf_delete(sds_bptree_instance *binst, sds_bptree_node *node, void *
     node->keys[index] = NULL;
     node->values[index] = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(node);
     }
@@ -544,7 +544,7 @@ sds_bptree_leaf_compact(sds_bptree_instance *binst, sds_bptree_node *left, sds_b
     right->item_count = 0;
     sds_bptree_node_destroy(binst, right);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(left);
     }
@@ -557,7 +557,7 @@ sds_bptree_leaf_right_borrow(sds_bptree_instance *binst, sds_bptree_node *left,
     left->keys[left->item_count] = right->keys[0];
     left->values[left->item_count] = right->values[0];
     left->item_count += 1;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     assert(right->item_count > 0);
 #endif
     for (size_t i = 0; i < (size_t)(right->item_count - 1); i++) {
@@ -568,7 +568,7 @@ sds_bptree_leaf_right_borrow(sds_bptree_instance *binst, sds_bptree_node *left,
     right->keys[right->item_count] = NULL;
     right->values[right->item_count] = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(left);
         sds_bptree_crc32c_update_node(right);
@@ -590,7 +590,7 @@ sds_bptree_leaf_left_borrow(sds_bptree_instance *binst, sds_bptree_node *left, s
     left->keys[left->item_count] = NULL;
     left->values[left->item_count] = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(left);
         sds_bptree_crc32c_update_node(right);
@@ -604,7 +604,7 @@ sds_bptree_root_promote(sds_bptree_instance *binst, sds_bptree_node *root) {
     binst->root = (sds_bptree_node *)root->values[0];
     sds_bptree_node_destroy(binst, root);
     binst->root->parent = NULL;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(binst->root);
         sds_bptree_crc32c_update_instance(binst);
@@ -632,7 +632,7 @@ sds_bptree_branch_delete(sds_bptree_instance *binst, sds_bptree_node *node, sds_
     node->keys[node->item_count] = NULL;
     node->values[node->item_count + 1] = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(node);
     }
@@ -674,7 +674,7 @@ sds_bptree_branch_key_fixup(sds_bptree_instance *binst, sds_bptree_node *parent,
     binst->key_free_fn(parent->keys[index]);
     parent->keys[index] = binst->key_dup_fn(sds_bptree_node_leftmost_child_key(child));
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(parent);
     }
@@ -690,7 +690,7 @@ sds_bptree_branch_compact(sds_bptree_instance *binst, sds_bptree_node *left, sds
 
     rchild = (sds_bptree_node *)right->values[0];
     rchild->parent = left;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(rchild);
     }
@@ -704,7 +704,7 @@ sds_bptree_branch_compact(sds_bptree_instance *binst, sds_bptree_node *left, sds
         left->keys[left->item_count] = right->keys[i];
         rchild = (sds_bptree_node *)right->values[i + 1];
         rchild->parent = left;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (binst->offline_checksumming) {
             sds_bptree_crc32c_update_node(rchild);
         }
@@ -718,7 +718,7 @@ sds_bptree_branch_compact(sds_bptree_instance *binst, sds_bptree_node *left, sds
     right->item_count = 0;
     sds_bptree_node_destroy(binst, right);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(left);
     }
@@ -736,7 +736,7 @@ sds_bptree_branch_right_borrow(sds_bptree_instance *binst, sds_bptree_node *left
     rchild->parent = left;
     left->values[left->item_count + 1] = rchild;
     left->item_count += 1;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     assert(right->item_count > 0);
 #endif
     for (size_t i = 0; i < (size_t)(right->item_count - 1); i++) {
@@ -748,7 +748,7 @@ sds_bptree_branch_right_borrow(sds_bptree_instance *binst, sds_bptree_node *left
     right->item_count -= 1;
     right->keys[right->item_count] = NULL;
     right->values[right->item_count + 1] = NULL;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(left);
         sds_bptree_crc32c_update_node(right);
@@ -782,7 +782,7 @@ sds_bptree_branch_left_borrow(sds_bptree_instance *binst, sds_bptree_node *left,
     binst->key_free_fn(left->keys[left->item_count]);
     left->keys[left->item_count] = NULL;
     left->values[left->item_count + 1] = NULL;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_node(left);
         sds_bptree_crc32c_update_node(right);

+ 13 - 11
src/libsds/sds/bpt/map.c

@@ -32,7 +32,7 @@ sds_bptree_map_nodes(sds_bptree_instance *binst, sds_bptree_node *root, sds_resu
     sds_result result = SDS_SUCCESS;
 
     while (cur != NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         // sds_log("sds_bptree_map_nodes", "node_%p ...", cur->node);
 #endif
         if (cur->node->level > 0) {
@@ -49,7 +49,7 @@ sds_bptree_map_nodes(sds_bptree_instance *binst, sds_bptree_node *root, sds_resu
         }
         result = fn(binst, cur->node);
         if (result != SDS_SUCCESS) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_map_nodes", "node_%p failed %d", cur->node, result);
 #endif
             final_result = result;
@@ -67,7 +67,7 @@ sds_bptree_verify_instance(sds_bptree_instance *binst)
 {
     sds_result result = SDS_SUCCESS;
     // check the checksum.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         result = sds_bptree_crc32c_verify_instance(binst);
     }
@@ -79,7 +79,7 @@ sds_bptree_verify_instance(sds_bptree_instance *binst)
 sds_result
 sds_bptree_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
     // - verify the hash of the node metadata
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_result result = sds_bptree_crc32c_verify_node(node);
         if (result != SDS_SUCCESS) {
@@ -92,7 +92,9 @@ sds_bptree_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
     for (size_t i = 0; i < node->item_count; i++) {
         if (node->keys[i] == NULL)
         {
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_verify_node", "%d \n", node->item_count);
+#endif
             return SDS_INVALID_KEY;
         }
 
@@ -124,7 +126,7 @@ sds_bptree_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
             return SDS_INVALID_NODE;
         }
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         /*
         // - verify the value hashes
         // Now that we are sure of all value sizes and pointers, lets do the checksum of the data in the values
@@ -209,7 +211,7 @@ sds_bptree_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
                         /* This checks that all left keys *and* their children are less */
                         int64_t result = binst->key_cmp_fn(lnode->keys[j], node->keys[i]);
                         if (result >= 0) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                             sds_log("sds_bptree_verify_node", "    fault is in node %p with left child %p", node, lnode);
 #endif
                             return SDS_INVALID_KEY_ORDER;
@@ -229,7 +231,7 @@ sds_bptree_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
                         /* This checks that all right keys are greatr or equal and their children */
                         int64_t result = binst->key_cmp_fn(rnode->keys[j], node->keys[i]);
                         if (result < 0) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                             sds_log("sds_bptree_verify_node", "    fault is in node %p with right child %p", node, rnode);
 #endif
                             return SDS_INVALID_KEY_ORDER;
@@ -253,7 +255,7 @@ sds_bptree_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
 
 sds_result
 sds_bptree_verify(sds_bptree_instance *binst) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_verify", "==> Beginning verification of instance %p", binst);
 #endif
     // How do we get *all* the errors here, for every node? ...
@@ -274,7 +276,7 @@ sds_bptree_verify(sds_bptree_instance *binst) {
         total_result = result;
     }
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_verify", "==> Completing verification of instance %p %d", binst, total_result);
 #endif
 
@@ -327,12 +329,12 @@ sds_bptree_display(sds_bptree_instance *binst) {
     sds_result result = SDS_SUCCESS;
 
     char *path = malloc(sizeof(char) * 20);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_display", "Writing step %03d\n", binst->print_iter);
 #endif
     sprintf(path, "/tmp/graph_%03d.dot", binst->print_iter);
     binst->print_iter += 1;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_bptree_crc32c_update_instance(binst);
     }

+ 10 - 10
src/libsds/sds/bpt/search.c

@@ -21,7 +21,7 @@ sds_bptree_search_node(sds_bptree_instance *binst, sds_bptree_node *root, void *
     int64_t (*key_cmp_fn)(void *a, void *b) = binst->key_cmp_fn;
 
     /* We do this first, as we need the node to pass before we access it! */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->search_checksumming) {
         sds_result result = sds_bptree_crc32c_verify_instance(binst);
         if (result != SDS_SUCCESS) {
@@ -39,7 +39,7 @@ branch_loop:
         while (i < target_node->item_count) {
             if (key_cmp_fn(key, (target_node)->keys[i]) < 0) {
                 target_node = (sds_bptree_node *)target_node->values[i];
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 if (binst->search_checksumming) {
                     sds_result result = sds_bptree_crc32c_verify_node(target_node);
                     if (result != SDS_SUCCESS) {
@@ -63,12 +63,12 @@ branch_loop:
 sds_result
 sds_bptree_search_internal(sds_bptree_instance *binst, sds_bptree_node *root, void *key) {
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_search_internal", "<== Beginning search of %d", key);
 #endif
 
     sds_bptree_node *target_node;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_result result = sds_bptree_search_node(binst, root, key, &target_node);
     if (result != SDS_SUCCESS) {
         return result;
@@ -79,13 +79,13 @@ sds_bptree_search_internal(sds_bptree_instance *binst, sds_bptree_node *root, vo
 
     for (size_t i = 0; i < target_node->item_count; i++) {
         if (binst->key_cmp_fn(key, (target_node)->keys[i]) == 0) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_search_internal", "<== Completing search of %d", key);
 #endif
             return SDS_KEY_PRESENT;
         }
     }
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_search_internal", "==> Failing search of %d", key);
 #endif
     return SDS_KEY_NOT_PRESENT;
@@ -96,12 +96,12 @@ sds_result
 sds_bptree_retrieve_internal(sds_bptree_instance *binst, sds_bptree_node *root, void *key, void **target) {
     // This is the public retrieve function
     // It's basically the same as search.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_retrieve_internal", "==> Beginning retrieve of %d", key);
 #endif
     sds_bptree_node *target_node = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->search_checksumming) {
         sds_result result = sds_bptree_crc32c_verify_instance(binst);
         if (result != SDS_SUCCESS) {
@@ -110,7 +110,7 @@ sds_bptree_retrieve_internal(sds_bptree_instance *binst, sds_bptree_node *root,
     }
 #endif
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_result result = sds_bptree_search_node(binst, root, key, &target_node);
     if (result != SDS_SUCCESS) {
         return result;
@@ -120,7 +120,7 @@ sds_bptree_retrieve_internal(sds_bptree_instance *binst, sds_bptree_node *root,
 #endif
     /* Now get the key from the node. */
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_retrieve_internal", "==> Completing retrieve of %d", key);
 #endif
     return sds_bptree_node_retrieve_key(binst->key_cmp_fn, target_node, key, target);

+ 4 - 2
src/libsds/sds/bpt/set.c

@@ -13,7 +13,9 @@
 sds_result
 sds_bptree_instance_clone(sds_bptree_instance *binst, sds_bptree_instance **binst_ptr) {
     if (binst_ptr == NULL) {
+#ifdef SDS_DEBUG
         sds_log("sds_btree_init", "Invalid pointer");
+#endif
         return SDS_NULL_POINTER;
     }
 
@@ -27,7 +29,7 @@ sds_bptree_instance_clone(sds_bptree_instance *binst, sds_bptree_instance **bins
     (*binst_ptr)->key_dup_fn = binst->key_dup_fn;
 
     // Now update the checksums
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if ((*binst_ptr)->offline_checksumming) {
         sds_bptree_crc32c_update_instance(*binst_ptr);
     }
@@ -39,7 +41,7 @@ sds_bptree_instance_clone(sds_bptree_instance *binst, sds_bptree_instance **bins
 sds_result
 sds_bptree_list_advance(sds_bptree_node **item, size_t *index) {
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_list_advance", "%p current index is %" PRIu64"", *item, *index);
 #endif
     /* Now, if we have the ability */

+ 1 - 1
src/libsds/sds/bpt/verify.c

@@ -10,7 +10,7 @@
 #include "bpt.h"
 
 /* Node checksumming functions. */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
 
 sds_result
 sds_bptree_crc32c_verify_instance(sds_bptree_instance *binst) {

+ 28 - 26
src/libsds/sds/bpt_cow/bpt_cow.c

@@ -25,7 +25,7 @@ static uint64_t print_iter = 0;
 
 sds_result sds_bptree_cow_init(sds_bptree_cow_instance **binst_ptr, uint16_t checksumming, int64_t (*key_cmp_fn)(void *a, void *b), void (*value_free_fn)(void *value), void *(*value_dup_fn)(void *key), void (*key_free_fn)(void *key), void *(*key_dup_fn)(void *key)) {
     if (binst_ptr == NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_btree_init", "Invalid pointer");
 #endif
         return SDS_NULL_POINTER;
@@ -67,7 +67,7 @@ sds_result sds_bptree_cow_init(sds_bptree_cow_instance **binst_ptr, uint16_t che
     sds_bptree_node_list_release(&((*binst_ptr)->txn->created));
 
     // Update our checksums.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if ((*binst_ptr)->bi->offline_checksumming) {
         sds_bptree_crc32c_update_instance((*binst_ptr)->bi);
         sds_bptree_crc32c_update_cow_instance(*binst_ptr);
@@ -84,7 +84,7 @@ sds_result sds_bptree_cow_init(sds_bptree_cow_instance **binst_ptr, uint16_t che
 
 sds_result sds_bptree_cow_destroy(sds_bptree_cow_instance *binst) {
     sds_result result = SDS_SUCCESS;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_destroy", "    Destroying instance %p", binst);
 #endif
 
@@ -127,7 +127,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
     sds_bptree_node *target_node = NULL;
     sds_bptree_node *next_node = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_delete", "==> Beginning delete of %d", key);
 #endif
     // Need to fail if txn is RO
@@ -171,7 +171,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
         sds_bptree_node *right = NULL;
         /* This updates the left and right parent paths, but does NOT cow!!! */
         sds_bptree_cow_node_siblings(next_node, &left, &right);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_bptree_cow_delete", " %p -> %p -> %p", left, next_node, right);
         sds_log("sds_bptree_cow_delete", " next_node->item_count = %d", next_node->item_count);
         if (right != NULL) {
@@ -190,7 +190,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
 #endif
         if (right != NULL && right->item_count > SDS_BPTREE_HALF_CAPACITY) {
             /* Does right have excess keys? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_cow_delete", "Right leaf borrow");
 #endif
             cow_node = sds_bptree_cow_node_prepare(btxn, right);
@@ -199,7 +199,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
             next_node = cow_node;
         } else if (left != NULL && left->item_count > SDS_BPTREE_HALF_CAPACITY) {
             /* Does left have excess keys? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_cow_delete", "Left leaf borrow");
 #endif
             cow_node = sds_bptree_cow_node_prepare(btxn, left);
@@ -207,7 +207,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
             /* This does NOT need to set next_node, because everthing is higher than us */
         } else if (right != NULL && right->item_count <= SDS_BPTREE_HALF_CAPACITY) {
             /* Does right want to merge? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_cow_delete", "Right leaf contract");
 #endif
             /* WARNING: DO NOT COW THE RIGHT NODE */
@@ -217,7 +217,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
             /* Next node is correct, and ready for FIXUP */
         } else if (left != NULL && left->item_count <= SDS_BPTREE_HALF_CAPACITY) {
             /* Does left want to merge? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_cow_delete", "Left leaf contract");
 #endif
             cow_node = sds_bptree_cow_node_prepare(btxn, left);
@@ -239,7 +239,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
              */
             if (deleted_node != NULL) {
                 /* Make sure we delete this value from our branch */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_bptree_cow_delete", "Should be removing %p from branch %p here!", deleted_node, target_node);
 #endif
                 sds_bptree_branch_delete(btxn->bi, target_node, deleted_node);
@@ -247,7 +247,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
                 deleted_node = NULL;
             } else {
                 /* It means a borrow was probably done somewhere, so we need to fix the path */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_bptree_cow_delete", "Should be fixing %p key to child %p here!", target_node, next_node);
 #endif
                 sds_bptree_branch_key_fixup(btxn->bi, target_node, next_node);
@@ -273,7 +273,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
                  * the merge by a fraction, to allow space for 3 keys and 3 keys.
                  *
                  */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_bptree_cow_delete", " %p -> %p -> %p", left, next_node, right);
                 sds_log("sds_bptree_cow_delete", " next_node->item_count = %d", next_node->item_count);
                 if (right != NULL) {
@@ -291,7 +291,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
 #endif
                 if (right != NULL && right->item_count >= SDS_BPTREE_HALF_CAPACITY) {
                     /* Does right have excess keys? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_cow_delete", "Right branch borrow");
 #endif
                     /* Since we are about to borrow, we need to cow RIGHT */
@@ -302,7 +302,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
                     next_node = cow_node;
                 } else if (left != NULL && left->item_count >= SDS_BPTREE_HALF_CAPACITY) {
                     /* Does left have excess keys? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_cow_delete", "Left branch borrow");
 #endif
                     /* Since we are about to borrow, we need to cow LEFT */
@@ -312,7 +312,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
                     /* Next node is still on right, key fix will work next loop. */
                 } else if (right != NULL && right->item_count < SDS_BPTREE_HALF_CAPACITY) {
                     /* Does right want to merge? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_cow_delete", "Right branch contract");
 #endif
                     /* WARNING: DO NOT COW THE RIGHT NODE */
@@ -322,7 +322,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
                     deleted_node = right;
                 } else if (left != NULL && left->item_count < SDS_BPTREE_HALF_CAPACITY) {
                     /* Does left want to merge? */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_cow_delete", "Left branch contract");
 #endif
                     /* Since we are about to merge, we need to cow left */
@@ -336,11 +336,13 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
                 }
 
             } else if ( target_node == NULL && next_node->item_count == 0) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_bptree_cow_delete", "Begin deleting the root");
 #endif
                 if (btxn->root != next_node) {
+#ifdef SDS_DEBUG
                     sds_log("sds_bptree_cow_delete", "Transaction is corrupted");
+#endif
                     result = SDS_UNKNOWN_ERROR;
                     goto fail;
                 }
@@ -352,7 +354,7 @@ sds_result sds_bptree_cow_delete(sds_bptree_transaction *btxn, void *key) {
     } // End of cow_node capacity check.
 
 fail:
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_delete", "<== finishing delete of %d", key);
 #endif
 
@@ -364,7 +366,7 @@ sds_result sds_bptree_cow_insert(sds_bptree_transaction *btxn, void *key, void *
     sds_bptree_node *cow_node = NULL;
     sds_bptree_node *target_node = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_insert", "==> Beginning insert of %d", key);
 #endif
     // Need to fail if txn is RO
@@ -406,7 +408,7 @@ sds_result sds_bptree_cow_insert(sds_bptree_transaction *btxn, void *key, void *
         sds_bptree_cow_leaf_split_and_insert(btxn, cow_node, insert_key, value);
     }
     // Else, insert to leaf and let things happen.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_insert", "<== Finishing insert of %p", key);
 #endif
 
@@ -418,7 +420,7 @@ sds_result sds_bptree_cow_update(sds_bptree_transaction *btxn, void *key, void *
     sds_bptree_node *cow_node = NULL;
     sds_bptree_node *target_node = NULL;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_update", "==> Beginning update of %d", key);
 #endif
     // Need to fail if txn is RO
@@ -448,7 +450,7 @@ sds_result sds_bptree_cow_update(sds_bptree_transaction *btxn, void *key, void *
     }
 
     // Else, insert to leaf and let things happen.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_update", "<== Finishing update of %d", key);
 #endif
     return SDS_SUCCESS;
@@ -459,7 +461,7 @@ sds_result
 sds_bptree_cow_verify(sds_bptree_cow_instance *binst) {
     sds_result result = SDS_SUCCESS;
     // Verify the instance
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->bi->offline_checksumming) {
         result = sds_bptree_crc32c_verify_cow_instance(binst);
         if (result != SDS_SUCCESS) {
@@ -480,7 +482,7 @@ sds_bptree_cow_verify(sds_bptree_cow_instance *binst) {
     }
 
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->bi->offline_checksumming) {
         result = sds_bptree_crc32c_verify_btxn(btxn);
         if (result != SDS_SUCCESS) {
@@ -495,7 +497,7 @@ sds_bptree_cow_verify(sds_bptree_cow_instance *binst) {
     /* Close the txn */
     sds_bptree_cow_rotxn_close(&btxn);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_verify", "--> Verification result %d\n", result);
 #endif
 
@@ -549,7 +551,7 @@ sds_bptree_cow_display(sds_bptree_transaction *btxn) {
 
     char *path = malloc(sizeof(char) * 20);
     print_iter += 1;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_display", "Writing step %03d\n", print_iter);
 #endif
     sprintf(path, "/tmp/graph_%03"PRIu64".dot", print_iter);

+ 1 - 1
src/libsds/sds/bpt_cow/bpt_cow.h

@@ -18,7 +18,7 @@ sds_result sds_bptree_cow_txn_destroy_all(sds_bptree_cow_instance *binst);
 
 /* Verification */
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
 sds_result sds_bptree_crc32c_verify_cow_instance(sds_bptree_cow_instance *binst);
 void sds_bptree_crc32c_update_cow_instance(sds_bptree_cow_instance *binst);
 sds_result sds_bptree_crc32c_verify_btxn(sds_bptree_transaction *btxn);

+ 3 - 3
src/libsds/sds/bpt_cow/delete.c

@@ -39,7 +39,7 @@ sds_bptree_cow_leaf_compact(sds_bptree_transaction *btxn, sds_bptree_node *left,
      */
     sds_bptree_node_list_push(&(btxn->owned), right);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->bi->offline_checksumming) {
         sds_bptree_crc32c_update_node(left);
         // Update this becuase we are updating the owned node lists.
@@ -70,7 +70,7 @@ sds_bptree_cow_branch_compact(sds_bptree_transaction *btxn, sds_bptree_node *lef
 
     sds_bptree_node_list_push(&(btxn->owned), right);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->bi->offline_checksumming) {
         sds_bptree_crc32c_update_node(left);
         // Update this becuase we are updating the owned node lists.
@@ -86,7 +86,7 @@ sds_bptree_cow_root_promote(sds_bptree_transaction *btxn, sds_bptree_node *root)
     btxn->root = (sds_bptree_node *)root->values[0];
     sds_bptree_node_list_push(&(btxn->owned), root);
     btxn->root->parent = NULL;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->bi->offline_checksumming) {
         sds_bptree_crc32c_update_node(btxn->root);
         sds_bptree_crc32c_update_btxn(btxn);

+ 6 - 6
src/libsds/sds/bpt_cow/insert.c

@@ -12,7 +12,7 @@
 void
 sds_bptree_cow_root_insert(sds_bptree_transaction *btxn, sds_bptree_node *left_node, sds_bptree_node *right_node, void *key)
 {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_root_insert", "left_node %p, key %d, right_node %p", left_node, key, right_node);
 #endif
     // Just make the new root, add the nodes, and update the root in the txn.
@@ -32,7 +32,7 @@ sds_bptree_cow_root_insert(sds_bptree_transaction *btxn, sds_bptree_node *left_n
     right_node->parent = root_node; */
     btxn->root = root_node;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->bi->offline_checksumming) {
         sds_bptree_crc32c_update_node(root_node);
         sds_bptree_crc32c_update_node(left_node);
@@ -53,7 +53,7 @@ sds_bptree_cow_leaf_node_insert(sds_bptree_transaction *btxn, sds_bptree_node *l
     sds_bptree_node *parent_node = lnode->parent;
     void *next_key = key;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_leaf_node_insert", "parent_node %p, left_node %p, key %d, right_node %p", parent_node, left_node, key, next_right_node);
 #endif
 
@@ -109,7 +109,7 @@ sds_bptree_cow_leaf_node_insert(sds_bptree_transaction *btxn, sds_bptree_node *l
 void
 sds_bptree_cow_leaf_split_and_insert(sds_bptree_transaction *btxn, sds_bptree_node *left_node, void *key, void *value)
 {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_leaf_split_and_insert", "left_node %p, key %d, right_node TBA", left_node, key);
 #endif
     void *next_key = NULL;
@@ -130,14 +130,14 @@ sds_bptree_cow_leaf_split_and_insert(sds_bptree_transaction *btxn, sds_bptree_no
     }
 
     if (btxn->bi->key_cmp_fn(key, right_node->keys[0]) >= 1) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (btxn->bi->offline_checksumming) {
             sds_bptree_crc32c_update_node(left_node);
         }
 #endif
         sds_bptree_leaf_insert(btxn->bi, right_node, key, value);
     } else {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (btxn->bi->offline_checksumming) {
             sds_bptree_crc32c_update_node(right_node);
         }

+ 12 - 12
src/libsds/sds/bpt_cow/node.c

@@ -9,7 +9,7 @@
 
 #include "bpt_cow.h"
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
 static sds_result
 sds_bptree_cow_node_path_verify(sds_bptree_transaction *btxn, sds_bptree_node *node) {
     // Verify that the node has a valid parent path back to the root!
@@ -77,7 +77,7 @@ sds_bptree_cow_node_clone(sds_bptree_transaction *btxn, sds_bptree_node *node) {
     sds_bptree_node_list_push(&(btxn->owned), node);
     sds_bptree_node_list_push(&(btxn->created), clone_node);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_node_clone", "Cloning node_%p item_count=%d --> clone node_%p\n", node, node->item_count, clone_node);
     sds_log("sds_bptree_cow_node_clone", "txn_%p tentatively owns node_%p for cleaning\n", btxn->parent_txn, node);
 #endif
@@ -102,7 +102,7 @@ sds_bptree_cow_node_clone(sds_bptree_transaction *btxn, sds_bptree_node *node) {
 static void
 sds_bptree_cow_branch_clone(sds_bptree_transaction *btxn, sds_bptree_node *origin_node, sds_bptree_node *clone_node) {
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_branch_clone", "Cloning branch from node_%p\n", clone_node);
 #endif
     // Right, we have now cloned the node. We need to walk up the tree and clone
@@ -122,7 +122,7 @@ sds_bptree_cow_branch_clone(sds_bptree_transaction *btxn, sds_bptree_node *origi
             sds_bptree_node_node_replace(parent_node, former_origin_node, former_clone_node);
 
 // TODO: This probably needs to update csums of the nodes along the branch.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_cow_branch_clone", "Branch parent node_%p already within txn, finishing...\n", parent_node);
             if (btxn->bi->offline_checksumming) {
                 // Update this becuase we are updating the owned node lists.
@@ -134,7 +134,7 @@ sds_bptree_cow_branch_clone(sds_bptree_transaction *btxn, sds_bptree_node *origi
         } else {
             // Is the parent node NOT in this txn?
             // We need to clone the parent, and then replace ourselves in it ....
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_cow_branch_clone", "Branch parent node_%p NOT within txn, cloning...\n", parent_node);
 #endif
             // This is actually the important part!
@@ -142,7 +142,7 @@ sds_bptree_cow_branch_clone(sds_bptree_transaction *btxn, sds_bptree_node *origi
             sds_bptree_node_node_replace(parent_clone_node, former_origin_node, former_clone_node);
 
             // TODO: This probably needs to update csums of the nodes along the branch.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             if (btxn->bi->offline_checksumming) {
                 // Update this becuase we are updating the owned node lists.
                 sds_bptree_crc32c_update_node(parent_clone_node);
@@ -160,7 +160,7 @@ sds_bptree_cow_branch_clone(sds_bptree_transaction *btxn, sds_bptree_node *origi
     }
     // We have hit the root, update the root.
     // Origin is root, update the txn root.
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_branch_clone", "Updating txn_%p root from node_%p to node_%p\n", btxn, btxn->root, former_clone_node);
 #endif
     btxn->root = former_clone_node;
@@ -168,7 +168,7 @@ sds_bptree_cow_branch_clone(sds_bptree_transaction *btxn, sds_bptree_node *origi
 
 sds_bptree_node *
 sds_bptree_cow_node_prepare(sds_bptree_transaction *btxn, sds_bptree_node *node) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_node_prepare", " --> prepare node %p for txn_%p", node, btxn);
     sds_log("sds_bptree_node_prepare", "     prepare current tree root node_%p", btxn->root);
 #endif
@@ -185,7 +185,7 @@ sds_bptree_cow_node_prepare(sds_bptree_transaction *btxn, sds_bptree_node *node)
 
         // TODO: Need to update the btxn checksum?
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (btxn->bi->offline_checksumming) {
             // Update this becuase we are updating the owned node lists.
             sds_bptree_crc32c_update_btxn(btxn);
@@ -194,7 +194,7 @@ sds_bptree_cow_node_prepare(sds_bptree_transaction *btxn, sds_bptree_node *node)
 
         result_node = clone_node;
     }
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (sds_bptree_cow_node_path_verify(btxn, result_node)!= SDS_SUCCESS) {
         sds_log("sds_bptree_cow_node_prepare", "!!! Invalid path from cow_node to root!");
         return NULL;
@@ -218,7 +218,7 @@ sds_bptree_cow_node_create(sds_bptree_transaction *btxn) {
 
     sds_bptree_node_list_push(&(btxn->created), node);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->bi->offline_checksumming) {
         // Update this becuase we are updating the created node lists.
         sds_bptree_crc32c_update_btxn(btxn);
@@ -237,7 +237,7 @@ sds_bptree_cow_node_update(sds_bptree_transaction *btxn, sds_bptree_node *node,
     btxn->bi->value_free_fn(node->values[index]);
     // insert.
     node->values[index] = value;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->bi->offline_checksumming) {
     	sds_bptree_crc32c_update_node(node);
 	}

+ 4 - 4
src/libsds/sds/bpt_cow/search.c

@@ -22,7 +22,7 @@ sds_bptree_search_node_path(sds_bptree_transaction *btxn, void *key, sds_bptree_
     int64_t (*key_cmp_fn)(void *a, void *b) = btxn->bi->key_cmp_fn;
 
     /* We do this first, as we need the node to pass before we access it! */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->bi->search_checksumming) {
         sds_result result = sds_bptree_crc32c_verify_btxn(btxn);
         if (result != SDS_SUCCESS) {
@@ -42,7 +42,7 @@ sds_bptree_search_node_path(sds_bptree_transaction *btxn, void *key, sds_bptree_
 branch_loop:
     while (target_node->level != 0) {
         target_node->parent = parent_node;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (btxn->bi->search_checksumming) {
             sds_bptree_crc32c_update_node(target_node);
         }
@@ -60,7 +60,7 @@ branch_loop:
         parent_node = target_node;
         target_node = (sds_bptree_node *)target_node->values[target_node->item_count];
         i = 0;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (btxn->bi->search_checksumming) {
             sds_result result = sds_bptree_crc32c_verify_node(target_node);
             if (result != SDS_SUCCESS) {
@@ -70,7 +70,7 @@ branch_loop:
 #endif
     }
     target_node->parent = parent_node;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->bi->search_checksumming) {
         sds_bptree_crc32c_update_node(target_node);
     }

+ 20 - 20
src/libsds/sds/bpt_cow/txn.c

@@ -55,7 +55,7 @@ sds_bptree_txn_create(sds_bptree_cow_instance *binst) {
     // Atomically set this to 0.
     __atomic_and_fetch(&(btxn->reference_count), 0, __ATOMIC_SEQ_CST);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     // Update our needed checksums
     if (binst->bi->offline_checksumming) {
         sds_bptree_crc32c_update_btxn(btxn);
@@ -78,13 +78,13 @@ sds_bptree_txn_create(sds_bptree_cow_instance *binst) {
 // Should be caled by txn decrement.
 static void
 sds_bptree_txn_free(sds_bptree_transaction *btxn) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_txn_free", "        Freeing READ txn_%p rc %d", btxn, btxn->reference_count);
 #endif
     sds_bptree_node *target_node = sds_bptree_node_list_pop(&(btxn->owned));
     // This frees only the nodes *related* to this txn.
     while (target_node != NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_bptree_txn_free", "        READ txn_%p owned node node_%p", btxn, target_node);
 #endif
         sds_bptree_node_destroy(btxn->binst->bi, target_node);
@@ -92,7 +92,7 @@ sds_bptree_txn_free(sds_bptree_transaction *btxn) {
         target_node = sds_bptree_node_list_pop(&(btxn->owned));
     }
     sds_free(btxn);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_txn_free", "        Freed READ txn");
 #endif
 }
@@ -111,7 +111,7 @@ sds_bptree_txn_increment(sds_bptree_transaction *btxn) {
     __atomic_add_fetch(&(btxn->reference_count), 1, __ATOMIC_SEQ_CST);
 
     // PR_AtomicIncrement(&(btxn->reference_count));
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn->binst->bi->offline_checksumming) {
         sds_bptree_crc32c_update_btxn(btxn);
     }
@@ -129,7 +129,7 @@ sds_bptree_txn_increment(sds_bptree_transaction *btxn) {
 
 static void
 sds_bptree_txn_decrement(sds_bptree_transaction *btxn) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_txn_decrement", "    txn_%p %d - 1", btxn, btxn->reference_count );
 #endif
     sds_bptree_cow_instance *binst = btxn->binst;
@@ -140,7 +140,7 @@ sds_bptree_txn_decrement(sds_bptree_transaction *btxn) {
     /* WARNING: After this point, another thread MAY free btxn under us.
      * You MUST *not* deref btxn after this point.
      */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_txn_decrement", "                        == %d", result );
     /* WARNING: This *may* in some cases trigger a HUAF ... 
      * Is this reason to ditch the checksum of the txn, or to make a txn lock?
@@ -152,7 +152,7 @@ sds_bptree_txn_decrement(sds_bptree_transaction *btxn) {
     // If the counter is 0 && we are the tail transaction.
     if (result == 0) {
         while (result == 0 && btxn != NULL && btxn == binst->tail_txn) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_txn_decrement", "    txn_%p has reached 0, and is at the tail, vacuumming!", btxn);
 #endif
             binst->tail_txn = btxn->child_txn;
@@ -169,7 +169,7 @@ sds_bptree_txn_decrement(sds_bptree_transaction *btxn) {
             }
         }
     }
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (btxn != NULL) {
         sds_log("sds_bptree_txn_decrement", "    txn_%p is at count %d, and is at the tail, NOT vacuumming!", btxn, result);
     } else {
@@ -177,7 +177,7 @@ sds_bptree_txn_decrement(sds_bptree_transaction *btxn) {
     }
 #endif
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     // Update our needed checksums
     if (binst->bi->offline_checksumming) {
         sds_bptree_crc32c_update_cow_instance(binst);
@@ -199,7 +199,7 @@ sds_bptree_txn_decrement(sds_bptree_transaction *btxn) {
 sds_result
 sds_bptree_cow_rotxn_begin(sds_bptree_cow_instance *binst, sds_bptree_transaction **btxn) {
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_result result = SDS_SUCCESS;
     if (binst->bi->offline_checksumming) {
         result = sds_bptree_crc32c_verify_cow_instance(binst);
@@ -224,7 +224,7 @@ sds_bptree_cow_rotxn_begin(sds_bptree_cow_instance *binst, sds_bptree_transactio
     }
     /* Unlock */
     pthread_rwlock_unlock(binst->read_lock);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (*btxn != NULL) {
         sds_log("sds_bptree_cow_rotxn_begin", "==> Beginning READ txn_%p rc %d", *btxn, (*btxn)->reference_count);
     } else {
@@ -252,7 +252,7 @@ sds_bptree_cow_rotxn_close(sds_bptree_transaction **btxn) {
         return SDS_INVALID_TXN;
     }
     /* Decrement the counter */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_rotxn_close", "==> Closing READ txn_%p rc %d - 1", *btxn, (*btxn)->reference_count);
 #endif
     sds_bptree_txn_decrement(*btxn);
@@ -271,7 +271,7 @@ sds_bptree_cow_rotxn_close(sds_bptree_transaction **btxn) {
  */
 
 sds_result sds_bptree_cow_wrtxn_begin(sds_bptree_cow_instance *binst, sds_bptree_transaction **btxn) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_result result = SDS_SUCCESS;
     if (binst->bi->offline_checksumming) {
         result = sds_bptree_crc32c_verify_cow_instance(binst);
@@ -289,7 +289,7 @@ sds_result sds_bptree_cow_wrtxn_begin(sds_bptree_cow_instance *binst, sds_bptree
     // Create the txn
     *btxn = sds_bptree_txn_create(binst);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_wrtxn_begin", "==> Beginning WRITE txn_%p", *btxn);
 #endif
 
@@ -313,7 +313,7 @@ sds_result sds_bptree_cow_wrtxn_abort(sds_bptree_transaction **btxn) {
     (*btxn)->state = SDS_TXN_READ;
     // Unlock the write lock.
     pthread_mutex_unlock((*btxn)->binst->write_lock);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_wrtxn_abort", "==> Aborting WRITE txn_%p", *btxn);
 #endif
     // Free and *remove* the list of nodes that we created, they are irrelevant!
@@ -345,14 +345,14 @@ sds_result sds_bptree_cow_wrtxn_commit(sds_bptree_transaction **btxn) {
     if (btxn == NULL || *btxn == NULL) {
         return SDS_INVALID_TXN;
     }
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_bptree_cow_wrtxn_commit", "==> Committing WRITE txn_%p", *btxn);
 #endif
 
     // This prevents a huaf in decrement at the tail of this fn
     sds_bptree_transaction *parent_txn = (*btxn)->parent_txn;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_result result = SDS_SUCCESS;
     if ((*btxn)->binst->bi->offline_checksumming) {
         result = sds_bptree_crc32c_verify_btxn(*btxn);
@@ -393,7 +393,7 @@ sds_result sds_bptree_cow_wrtxn_commit(sds_bptree_transaction **btxn) {
     (*btxn)->binst->txn = *btxn;
     // Update our parent to reference us.
     parent_txn->child_txn = *btxn;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     // Update our needed checksums
     if ((*btxn)->binst->bi->offline_checksumming) {
         sds_bptree_crc32c_update_cow_instance((*btxn)->binst);
@@ -452,7 +452,7 @@ sds_bptree_cow_txn_destroy_all(sds_bptree_cow_instance *binst)
     }
     pthread_rwlock_unlock(binst->read_lock);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     // Update our needed checksums
     if (binst->bi->offline_checksumming) {
         sds_bptree_crc32c_update_cow_instance(binst);

+ 6 - 4
src/libsds/sds/bpt_cow/verify.c

@@ -10,7 +10,7 @@
 #include "bpt_cow.h"
 
 /* Node checksumming functions. */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
 sds_result
 sds_bptree_crc32c_verify_btxn(sds_bptree_transaction *btxn) {
     uint32_t checksum = sds_crc32c(0, (const unsigned char *)btxn + sizeof(uint32_t), sizeof(sds_bptree_transaction) - sizeof(uint32_t));
@@ -64,7 +64,7 @@ sds_bptree_crc32c_update_cow_instance(sds_bptree_cow_instance *binst) {
 sds_result
 sds_bptree_cow_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
     // - verify the hash of the node metadata
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (binst->offline_checksumming) {
         sds_result result = sds_bptree_crc32c_verify_node(node);
         if (result != SDS_SUCCESS) {
@@ -78,7 +78,9 @@ sds_bptree_cow_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
     for (size_t i = 0; i < node->item_count; i++) {
         if (node->keys[i] == NULL)
         {
+#ifdef SDS_DEBUG
             sds_log("sds_bptree_cow_verify_node", "%d \n", node->item_count);
+#endif
             return SDS_INVALID_KEY;
         }
 
@@ -182,7 +184,7 @@ sds_bptree_cow_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
                         /* This checks that all left keys *and* their children are less */
                         int64_t result = binst->key_cmp_fn(lnode->keys[j], node->keys[i]);
                         if (result >= 0) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                             sds_log("sds_bptree_verify_node", "    fault is in node %p with left child %p", node, lnode);
 #endif
                             return SDS_INVALID_KEY_ORDER;
@@ -202,7 +204,7 @@ sds_bptree_cow_verify_node(sds_bptree_instance *binst, sds_bptree_node *node) {
                         /* This checks that all right keys are greatr or equal and their children */
                         int64_t result = binst->key_cmp_fn(rnode->keys[j], node->keys[i]);
                         if (result < 0) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                             sds_log("sds_bptree_verify_node", "    fault is in node %p with right child %p", node, rnode);
 #endif
                             return SDS_INVALID_KEY_ORDER;

+ 24 - 19
src/libsds/sds/core/utils.c

@@ -10,6 +10,28 @@
 #include "../sds_internal.h"
 #include <sds.h>
 
+/*
+ * sds_log
+ *
+ * This allows us to write a log message to an output.
+ * Similar to malloc, by defining this, we can change the impl later.
+ */
+#ifndef SDS_DEBUG
+static void
+#else
+void
+#endif
+__attribute__((format (printf, 2 , 3)))
+sds_log(char *id, char *msg, ...) {
+    printf("%s: ", id);
+    va_list subs;
+    va_start(subs, msg);
+    vprintf(msg, subs);
+    va_end(subs);
+    printf("\n");
+    return;
+}
+
 /* uint64_t as a key functions. */
 
 int64_t
@@ -26,7 +48,7 @@ sds_uint64_t_compare(void *a, void *b) {
 
 void *
 sds_uint64_t_dup(void *key) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_uint64_t_dup", "dup %" PRIu64" ", key);
 #endif
     uint64_t *newkey = sds_malloc(sizeof(uint64_t));
@@ -37,7 +59,7 @@ sds_uint64_t_dup(void *key) {
 void
 sds_uint64_t_free(void *key) {
     uint64_t *ukey = key;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_uint64_t_free", "freeing %" PRIu64"  @ %p", *ukey, key);
 #endif
     sds_free(ukey);
@@ -61,23 +83,6 @@ sds_strdup(void *key) {
 }
 
 
-/*
- * sds_log
- *
- * This allows us to write a log message to an output.
- * Similar to malloc, by defining this, we can change the impl later.
- */
-void
-sds_log(char *id, char *msg, ...) {
-    printf("%s: ", id);
-    va_list subs;
-    va_start(subs, msg);
-    vprintf(msg, subs);
-    va_end(subs);
-    printf("\n");
-    return;
-}
-
 /*
  * sds_malloc
  *

+ 4 - 4
src/libsds/sds/ht/ht.c

@@ -18,7 +18,7 @@ sds_ht_init(sds_ht_instance **ht_ptr,
             )
 {
     if (ht_ptr == NULL ) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_ht_init", "Invalid pointer");
 #endif
         return SDS_NULL_POINTER;
@@ -34,7 +34,7 @@ sds_ht_init(sds_ht_instance **ht_ptr,
 
     (*ht_ptr)->root = sds_ht_node_create();
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     (*ht_ptr)->root->depth = 15;
     sds_ht_crc32c_update_node((*ht_ptr)->root);
     sds_ht_crc32c_update_instance(*ht_ptr);
@@ -50,7 +50,7 @@ sds_ht_destroy(sds_ht_instance *ht_ptr)
         return SDS_NULL_POINTER;
     }
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (sds_ht_crc32c_verify_instance(ht_ptr) != SDS_SUCCESS) {
         return SDS_CHECKSUM_FAILURE;
     }
@@ -58,7 +58,7 @@ sds_ht_destroy(sds_ht_instance *ht_ptr)
     // Free the tree
     sds_result result = sds_ht_map_nodes(ht_ptr, sds_ht_node_destroy);
     if (result != SDS_SUCCESS) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_ht_destroy", "Failed to destroy instance %d\n", result);
 #endif
         return result;

+ 5 - 3
src/libsds/sds/ht/map.c

@@ -11,7 +11,7 @@
 sds_result
 sds_ht_map_nodes(sds_ht_instance *ht_ptr, sds_result (*map_fn)(sds_ht_instance *ht_ptr, sds_ht_node *node))
 {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     //verify instance
     if (sds_ht_crc32c_verify_instance(ht_ptr) != SDS_SUCCESS) {
         sds_log("sds_ht_map_nodes", "ht_ptr failed verification");
@@ -25,7 +25,7 @@ sds_ht_map_nodes(sds_ht_instance *ht_ptr, sds_result (*map_fn)(sds_ht_instance *
     sds_ht_node *work_node = ht_ptr->root;
     // while node is true
     while (work_node != NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (sds_ht_crc32c_verify_node(work_node) != SDS_SUCCESS) {
             sds_log("sds_ht_map_nodes", "ht_node_%p failed verification", work_node);
             result = SDS_CHECKSUM_FAILURE;
@@ -44,7 +44,7 @@ sds_ht_map_nodes(sds_ht_instance *ht_ptr, sds_result (*map_fn)(sds_ht_instance *
         sds_result internal_result = map_fn(ht_ptr, work_node);
         if (internal_result != SDS_SUCCESS) {
             result = internal_result;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_ht_map_nodes", "Encountered an issue with ht_node_%p: %d\n", work_node, internal_result);
             goto out;
 #endif
@@ -56,7 +56,9 @@ sds_ht_map_nodes(sds_ht_instance *ht_ptr, sds_result (*map_fn)(sds_ht_instance *
         }
     }
 
+#ifdef SDS_DEBUG
 out:
+#endif
     sds_queue_destroy(node_q);
     return result;
 

+ 5 - 5
src/libsds/sds/ht/node.c

@@ -12,7 +12,7 @@ sds_ht_node *
 sds_ht_node_create(void)
 {
     sds_ht_node *node = sds_calloc(sizeof(sds_ht_node));
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_node_create", "Creating ht_node_%p", node);
 #endif
     return node;
@@ -22,12 +22,12 @@ sds_ht_value *
 sds_ht_value_create(void *key, void *value)
 {
     sds_ht_value *ht_value = sds_calloc(sizeof(sds_ht_value));
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_value_create", "Creating ht_value_%p", ht_value);
 #endif
     ht_value->key = key;
     ht_value->value = value;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_ht_crc32c_update_value(ht_value);
 #endif
     return ht_value;
@@ -35,7 +35,7 @@ sds_ht_value_create(void *key, void *value)
 
 void
 sds_ht_value_destroy(sds_ht_instance *ht_ptr, sds_ht_value *value) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_value_destroy", "Destroying ht_value_%p", value);
 #endif
     ht_ptr->key_free_fn(value->key);
@@ -48,7 +48,7 @@ sds_ht_value_destroy(sds_ht_instance *ht_ptr, sds_ht_value *value) {
 sds_result
 sds_ht_node_destroy(sds_ht_instance *ht_ptr, sds_ht_node *node)
 {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_node_destroy", "Destroying ht_node_%p", node);
 #endif
     for (size_t i = 0; i < HT_SLOTS; i++) {

+ 31 - 31
src/libsds/sds/ht/op.c

@@ -12,11 +12,11 @@
 inline static size_t __attribute__((always_inline))
 sds_ht_hash_slot(int64_t depth, uint64_t hash)
 {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     assert(depth <= 15 && depth >= 0);
 #endif
     size_t c_slot = (hash >> (depth * 4)) & 0xF;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     assert(c_slot < 16);
 #endif
     return c_slot;
@@ -25,7 +25,7 @@ sds_ht_hash_slot(int64_t depth, uint64_t hash)
 sds_result
 sds_ht_insert(sds_ht_instance *ht_ptr, void *key, void *value)
 {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_insert", "==> begin");
     if (sds_ht_crc32c_verify_instance(ht_ptr) != SDS_SUCCESS) {
         return SDS_CHECKSUM_FAILURE;
@@ -43,7 +43,7 @@ sds_ht_insert(sds_ht_instance *ht_ptr, void *key, void *value)
 
     // Use an internal search to find the node and slot we need to occupy
     uint64_t hashout = sds_siphash13(key, ht_ptr->key_size_fn(key), ht_ptr->hkey);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_insert", "hash key %p -> 0x%"PRIx64, key, hashout);
 #endif
     int64_t depth = 15;
@@ -53,7 +53,7 @@ sds_ht_insert(sds_ht_instance *ht_ptr, void *key, void *value)
 
     while (depth >= 0) {
         c_slot = sds_ht_hash_slot(depth, hashout);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (sds_ht_crc32c_verify_node(work_node) != SDS_SUCCESS) {
             sds_log("sds_ht_insert", "ht_node_%p failed verification", work_node);
             return SDS_CHECKSUM_FAILURE;
@@ -64,7 +64,7 @@ sds_ht_insert(sds_ht_instance *ht_ptr, void *key, void *value)
         slot = &(work_node->slots[c_slot]);
         // Now look at the slot, and see if it's full, empty or branch.
         if (slot->state == SDS_HT_EMPTY) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_ht_insert", "c_slot 0x%"PRIx64" state=EMPTY", c_slot);
 #endif
             // This is where we can insert.
@@ -72,27 +72,27 @@ sds_ht_insert(sds_ht_instance *ht_ptr, void *key, void *value)
             slot->state = SDS_HT_VALUE;
             // Remember to dup the key.
             slot->slot.value = sds_ht_value_create(ht_ptr->key_dup_fn(key), value);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_ht_crc32c_update_node(work_node);
             sds_log("sds_ht_insert", "<== complete");
 #endif
             return SDS_SUCCESS;
         } else if (slot->state == SDS_HT_BRANCH) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_ht_insert", "c_slot 0x%"PRIx64" state=BRANCH", c_slot);
 #endif
             depth--;
             work_node = slot->slot.node;
             // Keep looping!
         } else {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_ht_insert", "ht_node_%p at c_slot 0x%"PRIx64" state=VALUE", work_node, c_slot);
 #endif
             // Must be a value, let's break out and process it.
             if (ht_ptr->key_cmp_fn(key, slot->slot.value->key) == 0) {
                 // Yep, it's a dup.
                 return SDS_KEY_PRESENT;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_insert", "<== complete");
 #endif
             }
@@ -106,7 +106,7 @@ sds_ht_insert(sds_ht_instance *ht_ptr, void *key, void *value)
                 sds_ht_slot *ex_slot = &(new_node->slots[ex_c_slot]);
                 ex_slot->state = SDS_HT_VALUE;
                 ex_slot->slot.value = slot->slot.value;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_insert", "existing c_slot 0x%"PRIx64" to new ht_node_%p c_slot 0x%"PRIx64, c_slot, new_node, ex_c_slot);
                 new_node->depth = depth;
 #endif
@@ -116,7 +116,7 @@ sds_ht_insert(sds_ht_instance *ht_ptr, void *key, void *value)
                 // Now make the existing worknode slot point to our new leaf..
                 slot->state = SDS_HT_BRANCH;
                 slot->slot.node = new_node;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_ht_crc32c_update_node(work_node);
                 sds_ht_crc32c_update_node(new_node);
 #endif
@@ -138,7 +138,7 @@ sds_ht_search(sds_ht_instance *ht_ptr, void *key, void **value)
 {
     // Search the tree. if key is found, SDS_KEY_PRESENT and *value is set.
     // Else, SDS_KEY_NOT_PRESENT
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_search", "==> begin");
     if (sds_ht_crc32c_verify_instance(ht_ptr) != SDS_SUCCESS) {
         return SDS_CHECKSUM_FAILURE;
@@ -160,7 +160,7 @@ sds_ht_search(sds_ht_instance *ht_ptr, void *key, void **value)
 
     // Use an internal search to find the node and slot we need to occupy
     uint64_t hashout = sds_siphash13(key, ht_ptr->key_size_fn(key), ht_ptr->hkey);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_search", "hash key %p -> 0x%"PRIx64, key, hashout);
 #endif
     int64_t depth = 15;
@@ -170,7 +170,7 @@ sds_ht_search(sds_ht_instance *ht_ptr, void *key, void **value)
 
     while (depth >= 0) {
         c_slot = sds_ht_hash_slot(depth, hashout);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         if (sds_ht_crc32c_verify_node(work_node) != SDS_SUCCESS) {
             sds_log("sds_ht_search", "ht_node_%p failed verification", work_node);
             sds_log("sds_ht_search", "==> complete");
@@ -189,19 +189,19 @@ sds_ht_search(sds_ht_instance *ht_ptr, void *key, void **value)
             if (ht_ptr->key_cmp_fn(key, slot->slot.value->key) == 0) {
                 // WARNING: If depth == 0, check for LL
                 *value = slot->slot.value->value;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_search", "<== complete");
 #endif
                 return SDS_KEY_PRESENT;
             } else {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_search", "<== complete");
 #endif
                 return SDS_KEY_NOT_PRESENT;
             }
         } else {
             // We got to the hash point where this should be but it's not here ....
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_ht_search", "==> complete");
 #endif
             return SDS_KEY_NOT_PRESENT;
@@ -218,7 +218,7 @@ sds_ht_node_cleanup(sds_ht_instance *ht_ptr, sds_ht_node *node)
     sds_ht_node *work_node = node;
     sds_ht_node *parent_node = node->parent;
     while (work_node->count <= 1 && parent_node != NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_ht_node_cleanup", "Cleaning ht_node_%p into parent ht_node_%p", node, parent_node);
         sds_result post_result = sds_ht_verify_node(ht_ptr, work_node);
         if (post_result != SDS_SUCCESS) {
@@ -229,7 +229,7 @@ sds_ht_node_cleanup(sds_ht_instance *ht_ptr, sds_ht_node *node)
 #endif
         // We need to know where we are in the parent.
         sds_ht_slot *ex_p_slot = &(parent_node->slots[work_node->parent_slot]);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_ht_node_cleanup", "Slot %p of parent ht_node_%p", work_node->parent_slot, parent_node);
 #endif
 
@@ -247,13 +247,13 @@ sds_ht_node_cleanup(sds_ht_instance *ht_ptr, sds_ht_node *node)
         }
         assert (r_slot < HT_SLOTS);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_ht_node_cleanup", "Remaining slot %p of ht_node_%p", r_slot, work_node);
 #endif
 
         // Now, put our remaining slot into the parent.
         ex_p_slot->state = SDS_HT_VALUE;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_ht_node_cleanup", "Move slot %p of ht_node_%p to %p of ht_node_%p", r_slot, work_node, work_node->parent_slot, parent_node);
 #endif
         ex_p_slot->slot.value = ex_r_slot->slot.value;
@@ -265,7 +265,7 @@ sds_ht_node_cleanup(sds_ht_instance *ht_ptr, sds_ht_node *node)
 
         work_node = parent_node;
         parent_node = work_node->parent;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_ht_crc32c_update_node(work_node);
 #endif
     }
@@ -277,7 +277,7 @@ sds_ht_delete(sds_ht_instance *ht_ptr, void *key)
 {
     // Search the tree. if key is found, SDS_KEY_PRESENT and *value is set.
     // Else, SDS_KEY_NOT_PRESENT
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_delete", "==> begin");
     if (sds_ht_crc32c_verify_instance(ht_ptr) != SDS_SUCCESS) {
         return SDS_CHECKSUM_FAILURE;
@@ -295,7 +295,7 @@ sds_ht_delete(sds_ht_instance *ht_ptr, void *key)
 
     // Use an internal search to find the node and slot we need to occupy
     uint64_t hashout = sds_siphash13(key, ht_ptr->key_size_fn(key), ht_ptr->hkey);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_delete", "hash key %p -> 0x%"PRIx64, key, hashout);
 #endif
     int64_t depth = 15;
@@ -305,7 +305,7 @@ sds_ht_delete(sds_ht_instance *ht_ptr, void *key)
 
     while (depth >= 0) {
         c_slot = sds_ht_hash_slot(depth, hashout);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_result result = sds_ht_verify_node(ht_ptr, work_node);
         if (result != SDS_SUCCESS) {
             sds_log("sds_ht_delete", "ht_node_%p failed verification", work_node);
@@ -322,14 +322,14 @@ sds_ht_delete(sds_ht_instance *ht_ptr, void *key)
             depth--;
         } else if (slot->state == SDS_HT_EMPTY) {
             // We got to the hash point where this should be but it's not here ....
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_ht_delete", "==> complete");
 #endif
             return SDS_KEY_NOT_PRESENT;
         } else {
             if (ht_ptr->key_cmp_fn(key, slot->slot.value->key) == 0) {
                 // WARNING: If depth == 0, check for LL
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_delete", "deleting from ht_node_%p", work_node);
 #endif
                 // Free the value, this frees the key + value.
@@ -337,17 +337,17 @@ sds_ht_delete(sds_ht_instance *ht_ptr, void *key)
                 slot->slot.value = NULL;
                 slot->state = SDS_HT_EMPTY;
                 work_node->count--;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_ht_crc32c_update_node(work_node);
 #endif
                 // How much left in this node? if <= 1, need to start merging up.
                 sds_ht_node_cleanup(ht_ptr, work_node);
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_delete", "<== complete");
 #endif
                 return SDS_KEY_PRESENT;
             } else {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_delete", "<== complete");
 #endif
                 return SDS_KEY_NOT_PRESENT;

+ 18 - 4
src/libsds/sds/ht/verify.c

@@ -8,7 +8,7 @@
 
 #include "ht.h"
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
 
 void
 sds_ht_crc32c_update_node(sds_ht_node *node)
@@ -70,15 +70,19 @@ sds_ht_verify_node(sds_ht_instance *ht_ptr, sds_ht_node *node)
 
         if (slot->state == SDS_HT_EMPTY) {
             if (slot->slot.value != NULL) {
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_verify_node", "Failing ht_node_%p - invalid empty node c_slot 0x%"PRIu64, node, i);
+#endif
                 return SDS_INVALID_NODE;
             }
         } else if (slot->state == SDS_HT_VALUE) {
             if (slot->slot.value == NULL) {
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_verify_node", "Failing ht_node_%p - invalid value pointer of NULL c_slot 0x%"PRIu64, node);
+#endif
                 return SDS_INVALID_POINTER;
             }
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             if (sds_ht_crc32c_verify_value(slot->slot.value) != SDS_SUCCESS) {
                 sds_log("sds_ht_verify_node", "Failing ht_node_%p - invalid value checksum", node);
                 return SDS_CHECKSUM_FAILURE;
@@ -88,35 +92,45 @@ sds_ht_verify_node(sds_ht_instance *ht_ptr, sds_ht_node *node)
         } else {
             // It's a branch
             if (slot->slot.node == NULL ) {
+#ifdef SDS_DEBUG
                 sds_log("sds_ht_verify_node", "Failing ht_node_%p - invalid branch, can not be NULL", node);
+#endif
                 return SDS_INVALID_POINTER;
             }
         }
 
     }
     if (count != node->count) {
+#ifdef SDS_DEBUG
         sds_log("sds_ht_verify_node", "Failing ht_node_%p - invalid item count, doesn't match", node);
+#endif
         return SDS_INVALID_NODE;
     }
 
     // Check that our parent and parent slot match
     if (node->parent != NULL || node->parent_slot != 0) {
         if (node->count == 0) {
+#ifdef SDS_DEBUG
             sds_log("sds_ht_verify_node", "Failing ht_node_%p - invalid item count of 0", node);
+#endif
             return SDS_INVALID_NODE;
         }
         sds_ht_slot *ex_p_slot = &(node->parent->slots[node->parent_slot]);
         if (ex_p_slot->state != SDS_HT_BRANCH) {
+#ifdef SDS_DEBUG
             sds_log("sds_ht_verify_node", "Failing ht_node_%p - invalid parent, slot state is not branch", node);
+#endif
             return SDS_INVALID_POINTER;
         }
         if (ex_p_slot->slot.node != node) {
+#ifdef SDS_DEBUG
             sds_log("sds_ht_verify_node", "Failing ht_node_%p - invalid parent, slot node pointer is not to us", node);
+#endif
             return SDS_INVALID_POINTER;
         }
     }
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_ht_verify_node", "ht_node_%p depth= %"PRIu64" count=%"PRIu64, node, node->depth, node->count);
 #endif
     return SDS_SUCCESS;
@@ -125,7 +139,7 @@ sds_ht_verify_node(sds_ht_instance *ht_ptr, sds_ht_node *node)
 sds_result
 sds_ht_verify(sds_ht_instance *ht_ptr)
 {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     //verify instance
     if (sds_ht_crc32c_verify_instance(ht_ptr) != SDS_SUCCESS) {
         return SDS_CHECKSUM_FAILURE;

+ 6 - 6
src/libsds/sds/queue/lqueue.c

@@ -82,7 +82,7 @@ typedef struct _sds_lqueue_gc {
 
 static void
 sds_lqueue_tprivate_cleanup(void *priv) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_lqueue_tprivate_cleanup", "Closing thread GC");
 #endif
     sds_lqueue_gc *gc = (sds_lqueue_gc *)priv;
@@ -99,11 +99,11 @@ sds_lqueue_tprivate_cleanup(void *priv) {
 
 sds_result
 sds_lqueue_init(sds_lqueue **q_ptr, void (*value_free_fn)(void *value)) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_lqueue_init", "Creating lock free queue");
 #endif
     if (q_ptr == NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_lqueue_init", "Invalid q_ptr");
 #endif
         return SDS_NULL_POINTER;
@@ -114,7 +114,7 @@ sds_lqueue_init(sds_lqueue **q_ptr, void (*value_free_fn)(void *value)) {
 
     /* Create the thread local storage for GC */
     if (PR_NewThreadPrivateIndex(&((*q_ptr)->gc_index), sds_lqueue_tprivate_cleanup) != PR_SUCCESS) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_lqueue_init", "Unable to create private index");
 #endif
         sds_free(*q_ptr);
@@ -148,7 +148,7 @@ sds_lqueue_tprep(sds_lqueue *q) {
 
 sds_result
 sds_lqueue_enqueue(sds_lqueue *q, void *elem) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_lqueue_enqueue", "<== lf Queue %p elem %p", q, elem);
 #endif
     struct lfds711_queue_umm_element *qe = sds_malloc(sizeof(struct lfds711_queue_umm_element));
@@ -159,7 +159,7 @@ sds_lqueue_enqueue(sds_lqueue *q, void *elem) {
 
 sds_result
 sds_lqueue_dequeue(sds_lqueue *q, void **elem) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_lqueue_dequeue", "==> lf Queue %p elem %p", q, elem);
 #endif
     if (elem == NULL) {

+ 11 - 11
src/libsds/sds/queue/queue.c

@@ -15,7 +15,7 @@
 sds_result
 sds_queue_init(sds_queue **q_ptr, void (*value_free_fn)(void *value)) {
     if (q_ptr == NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_queue_init", "Invalid p_ptr");
 #endif
         return SDS_NULL_POINTER;
@@ -31,11 +31,11 @@ sds_queue_init(sds_queue **q_ptr, void (*value_free_fn)(void *value)) {
 
 sds_result
 sds_queue_enqueue(sds_queue *q, void *elem) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_queue_dequeue", "Queue %p - <== enqueuing", q);
 #endif
     sds_queue_node *node = sds_malloc(sizeof(sds_queue_node));
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_queue_enqueue", "Queue %p - Queueing ptr %p to %p", q, elem, node);
 #endif
     node->element = elem;
@@ -45,13 +45,13 @@ sds_queue_enqueue(sds_queue *q, void *elem) {
         q->tail->next = node;
     } else {
         /* If tail is null, head must ALSO be null. */
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_queue_enqueue", "Queue %p - empty, adding %p to head and tail", q, node);
 #endif
         q->head = node;
     }
     q->tail = node;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_queue_enqueue", "Queue %p - complete head: %p tail: %p", q, q->head, q->tail);
 #endif
     return SDS_SUCCESS;
@@ -61,17 +61,17 @@ sds_queue_enqueue(sds_queue *q, void *elem) {
 
 sds_result
 sds_queue_dequeue(sds_queue *q, void **elem) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_queue_dequeue", "Queue %p - ==> dequeuing", q);
 #endif
     if (elem == NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_queue_dequeue", "Queue %p - NULL pointer for **elem", q);
 #endif
         return SDS_NULL_POINTER;
     }
     if (q->head == NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_queue_dequeue", "Queue %p - queue exhausted.", q);
 #endif
         return SDS_LIST_EXHAUSTED;
@@ -86,7 +86,7 @@ sds_queue_dequeue(sds_queue *q, void **elem) {
     } else {
         q->head->prev = NULL;
     }
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_queue_dequeue", "Queue %p - complete head: %p tail: %p", q, q->head, q->tail);
 #endif
     return SDS_SUCCESS;
@@ -99,7 +99,7 @@ sds_queue_dequeue(sds_queue *q, void **elem) {
 
 sds_result
 sds_queue_destroy(sds_queue *q) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_queue_destroy", "Queue %p - destroying", q);
 #endif
     /* Map over the queue and free the elements. */
@@ -108,7 +108,7 @@ sds_queue_destroy(sds_queue *q) {
     while (node != NULL) {
         next = node->next;
         if (q->value_free_fn != NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
             sds_log("sds_queue_destroy", "Queue %p - implicitly freeing %p", q, node->element);
 #endif
             q->value_free_fn(node->element);

+ 2 - 2
src/libsds/sds/queue/tqueue.c

@@ -15,11 +15,11 @@
 
 sds_result
 sds_tqueue_init(sds_tqueue **q_ptr, void (*value_free_fn)(void *value)) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     sds_log("sds_tqueue_init", "Createing mutex locked queue");
 #endif
     if (q_ptr == NULL) {
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         sds_log("sds_tqueue_init", "Invalid p_ptr");
 #endif
         return SDS_NULL_POINTER;

+ 2 - 0
src/libsds/sds/sds_internal.h

@@ -27,6 +27,8 @@
 
 #define SDS_CACHE_ALIGNMENT 64
 
+#ifdef SDS_DEBUG
 void sds_log(char *id, char *msg, ...);
+#endif
 
 

+ 1 - 1
src/libsds/test/benchmark_parwrap.c

@@ -135,7 +135,7 @@ int64_t bptree_cow_read_complete(void **inst __attribute__((unused)), void *read
 int64_t bptree_cow_write_begin(void **inst, void **write_txn) {
     sds_bptree_cow_instance **binst = (sds_bptree_cow_instance **)inst;
     sds_bptree_transaction **txn = (sds_bptree_transaction **)write_txn;
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     assert_int_equal(sds_bptree_cow_verify(*binst), SDS_SUCCESS);
 #endif
     sds_bptree_cow_wrtxn_begin(*binst, txn);

+ 2 - 2
src/libsds/test/test_fixtures.c

@@ -49,7 +49,7 @@ bptree_test_teardown(void **state)
 
     result = sds_bptree_verify(binst);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (result != SDS_SUCCESS) {
         sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
     }
@@ -130,7 +130,7 @@ bptree_test_cow_teardown(void **state)
 
     result = sds_bptree_cow_verify(binst);
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     if (result != SDS_SUCCESS) {
         sds_log("bptree_test_teardown", "FAIL: B+Tree COW verification failed %d binst", result);
     }

+ 42 - 4
src/libsds/test/test_sds_bpt.c

@@ -9,14 +9,16 @@
 
 #include "test_sds.h"
 
-#ifdef DEBUG_TEST_ASAN
+#ifdef SDS_DEBUG_TEST_ASAN
 static void
 test_asan_overflow(void)
 {
     char *test = sds_malloc(4 * sizeof(char));
     test[100] = 'a';
     // At this point, ASAN should explode.
+#ifdef SDS_DEBUG
     sds_log("test_asan", "FAIL: This should not be possible!");
+#endif
 }
 
 static void
@@ -192,7 +194,7 @@ test_11_tamper_with_node(void **state __attribute__((unused))) {
 
     binst->root->keys[0] = (void *)1;
 
-#ifdef DEBUG
+#ifdef SDS_DEBUG
     result = sds_bptree_verify(binst);
     assert_int_equal(result, SDS_CHECKSUM_FAILURE);
 #endif
@@ -214,18 +216,22 @@ test_12_insert_fill_split_and_grow(void **state) {
         assert_int_equal(result, SDS_SUCCESS);
         result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
         if (result != SDS_SUCCESS) {
             sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
         }
+#endif
         assert_int_equal(result, SDS_SUCCESS);
     }
 
     for (uint64_t i = 0; i <= ((SDS_BPTREE_DEFAULT_CAPACITY + 1) << 3) ; i++) {
         uint64_t ti = i + 2;
         result = sds_bptree_search(binst, (void *)&ti);
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can not find %d", ti);
         }
+#endif
         assert_int_equal(result, SDS_KEY_PRESENT);
     }
 
@@ -244,18 +250,22 @@ test_13_insert_fill_split_and_grow_inverse(void **state) {
         assert_int_equal(result, SDS_SUCCESS);
         result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
         if (result != SDS_SUCCESS) {
             sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
         }
+#endif
         assert_int_equal(result, SDS_SUCCESS);
     }
 
     for (uint64_t i = ((SDS_BPTREE_DEFAULT_CAPACITY + 1) << 3) + 1; i > 0  ; i--) {
         uint64_t ti = i + 2;
         result = sds_bptree_search(binst, (void *)&ti);
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can not find %d", ti);
         }
+#endif
         assert_int_equal(result, SDS_KEY_PRESENT);
     }
 }
@@ -272,9 +282,11 @@ test_14_insert_random(void **state) {
 
         result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
         if (result != SDS_SUCCESS) {
             sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
         }
+#endif
         assert_int_equal(result, SDS_SUCCESS);
 
     }
@@ -282,9 +294,11 @@ test_14_insert_random(void **state) {
 
     for (uint64_t i = 0; i < 200 ; i++) {
         result = sds_bptree_search(binst, (void *)&(fill_pattern[i]));
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can not find %d", fill_pattern[i]);
         }
+#endif
         assert_int_equal(result, SDS_KEY_PRESENT);
     }
 }
@@ -491,9 +505,11 @@ test_22_delete_redist_right_leaf(void **state)
 
     result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
     if (result != SDS_SUCCESS) {
         sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
     }
+#endif
     assert_int_equal(result, SDS_SUCCESS);
 
     /* Next delete */
@@ -502,9 +518,11 @@ test_22_delete_redist_right_leaf(void **state)
 
     result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
     if (result != SDS_SUCCESS) {
         sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
     }
+#endif
     assert_int_equal(result, SDS_SUCCESS);
 
 }
@@ -751,9 +769,11 @@ test_28_insert_and_delete_random(void **state) {
 
         result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
         if (result != SDS_SUCCESS) {
             sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
         }
+#endif
         assert_int_equal(result, SDS_SUCCESS);
 
     }
@@ -761,28 +781,36 @@ test_28_insert_and_delete_random(void **state) {
 
     for (uint64_t i = 0; i < 200 ; i++) {
         result = sds_bptree_search(binst, (void *)&(fill_pattern[i]));
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can not find %d", fill_pattern[i]);
         }
+#endif
         assert_int_equal(result, SDS_KEY_PRESENT);
 
         result = sds_bptree_delete(binst, (void *)&(fill_pattern[i]));
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can not delete %d", fill_pattern[i]);
         }
+#endif
         assert_int_equal(result, SDS_KEY_PRESENT);
 
         result = sds_bptree_search(binst, (void *)&(fill_pattern[i]));
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_NOT_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can find %d", fill_pattern[i]);
         }
+#endif
         assert_int_equal(result, SDS_KEY_NOT_PRESENT);
 
         result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
         if (result != SDS_SUCCESS) {
             sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
         }
+#endif
         assert_int_equal(result, SDS_SUCCESS);
 
     }
@@ -800,36 +828,46 @@ test_29_insert_and_delete_random_large(void **state) {
 
         result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
         if (result != SDS_SUCCESS) {
             sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
         }
+#endif
         assert_int_equal(result, SDS_SUCCESS);
 
     }
     for (uint64_t i = 0; i < 2048 ; i++) {
         result = sds_bptree_search(binst, (void *)&(fill_pattern[i]));
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can not find %d", fill_pattern[i]);
         }
+#endif
         assert_int_equal(result, SDS_KEY_PRESENT);
 
         result = sds_bptree_delete(binst, (void *)&(fill_pattern[i]));
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can not delete %d", fill_pattern[i]);
         }
+#endif
         assert_int_equal(result, SDS_KEY_PRESENT);
 
         result = sds_bptree_search(binst, (void *)&(fill_pattern[i]));
+#ifdef SDS_DEBUG
         if (result != SDS_KEY_NOT_PRESENT) {
             sds_log("bptree_test_teardown", "FAIL: Can find %d", fill_pattern[i]);
         }
+#endif
         assert_int_equal(result, SDS_KEY_NOT_PRESENT);
 
         result = sds_bptree_verify(binst);
 
+#ifdef SDS_DEBUG
         if (result != SDS_SUCCESS) {
             sds_log("bptree_test_teardown", "FAIL: B+Tree verification failed %d binst", result);
         }
+#endif
         assert_int_equal(result, SDS_SUCCESS);
     }
 }
@@ -876,11 +914,11 @@ int
 run_bpt_tests (void) {
     const struct CMUnitTest tests[] = {
         cmocka_unit_test(test_1_invalid_binst_ptr),
-#ifdef DEBUG
+#ifdef SDS_DEBUG
         cmocka_unit_test(test_10_tamper_with_inst),
         cmocka_unit_test(test_11_tamper_with_node),
 #endif
-#ifdef DEBUG_TEST_ASAN
+#ifdef SDS_DEBUG_TEST_ASAN
         cmocka_unit_test_setup_teardown(test_17_insert_and_tamper,
                                         bptree_test_setup,
                                         bptree_test_teardown),

+ 1 - 1
src/libsds/test/test_sds_cow.c

@@ -14,7 +14,7 @@
 #include "test_sds.h"
 
 // Predefine for now ...
-#ifdef DEBUG
+#ifdef SDS_DEBUG
 sds_result sds_bptree_cow_display(sds_bptree_transaction *btxn);
 #endif