From 0f555d80dd8ac7ced0b0e5a231e9a197a6054107 Mon Sep 17 00:00:00 2001
From: Rich Prohaska <prohaska@tokutek.com>
Date: Tue, 23 Sep 2008 18:05:41 +0000
Subject: [PATCH] move the root_put_counter to the brt_header. closes #1054

git-svn-id: file:///svn/tokudb.1131b+1080a@6279 c7de825b-a66e-492c-adef-691d508d4ae1
---
 newbrt/brt-internal.h        |  7 ++++---
 newbrt/brt.c                 | 14 +++++++-------
 newbrt/valgrind.suppressions |  8 ++++++++
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/newbrt/brt-internal.h b/newbrt/brt-internal.h
index 02e61d36d7d..ff410587476 100644
--- a/newbrt/brt-internal.h
+++ b/newbrt/brt-internal.h
@@ -127,13 +127,15 @@ struct brt_header {
     int layout_version;
     unsigned int nodesize;
     int n_named_roots; /* -1 if the only one is unnamed */
-    char  **names;             // an array of names.  NULL if subdatabases are not allowed.
+    char  **names;              // an array of names.  NULL if subdatabases are not allowed.
     BLOCKNUM *roots;            // An array of the roots of the various dictionaries.  Element 0 holds the element if no subdatabases allowed.
     struct remembered_hash *root_hashes;     // an array of hashes of the root offsets.
-    unsigned int *flags_array; // an array of flags.  Element 0 holds the element if no subdatabases allowed.
+    unsigned int *flags_array;  // an array of flags.  Element 0 holds the element if no subdatabases allowed.
     
     FIFO fifo; // all the abort and commit commands.  If the header gets flushed to disk, we write the fifo contents beyond the unused_memory.
 
+    u_int64_t root_put_counter; // the generation number of the brt
+
     // This is the map from block numbers to offsets
     //int n_blocks, n_blocks_array_size;
     //struct block_descriptor *blocks;
@@ -173,7 +175,6 @@ struct brt {
 
     OMT txns; // transactions that are using this OMT (note that the transaction checks the cf also)
     u_int64_t txn_that_created; // which txn created it.  Use  0 if no such txn.
-    u_int64_t root_put_counter;
 
 };
 
diff --git a/newbrt/brt.c b/newbrt/brt.c
index 1534f8e74bd..012bf04cabf 100644
--- a/newbrt/brt.c
+++ b/newbrt/brt.c
@@ -2166,7 +2166,7 @@ static int brt_alloc_init_header(BRT t, const char *dbname, TOKUTXN txn) {
     // printf("%s:%d translated_blocknum_limit=%ld, block_translation_address_on_disk=%ld\n", __FILE__, __LINE__, t->h->translated_blocknum_limit, t->h->block_translation_address_on_disk);
     create_block_allocator(&t->h->block_allocator, t->nodesize, BLOCK_ALLOCATOR_ALIGNMENT);
     toku_fifo_create(&t->h->fifo);
-    t->root_put_counter = global_root_put_counter++; 
+    t->h->root_put_counter = global_root_put_counter++; 
     if (dbname) {
         t->h->n_named_roots = 1;
         if ((MALLOC_N(1, t->h->names))==0)             { assert(errno==ENOMEM); r=ENOMEM; if (0) { died4: if (dbname) toku_free(t->h->names); } goto died3; }
@@ -2589,7 +2589,7 @@ int toku_brt_root_put_cmd(BRT brt, BRT_CMD cmd, TOKULOGGER logger) {
     //assert(0==toku_cachetable_assert_all_unpinned(brt->cachetable));
     assert(brt->h);
 
-    brt->root_put_counter = global_root_put_counter++;
+    brt->h->root_put_counter = global_root_put_counter++;
     u_int32_t fullhash;
     rootp = toku_calculate_root_offset_pointer(brt, &fullhash);
     //assert(fullhash==toku_cachetable_hash(brt->cf, *rootp));
@@ -3005,7 +3005,7 @@ int toku_brt_search(BRT brt, brt_search_t *search, DBT *newkey, DBT *newval, TOK
 
     assert(brt->h);
 
-    *root_put_counter = brt->root_put_counter;
+    *root_put_counter = brt->h->root_put_counter;
 
     u_int32_t fullhash;
     CACHEKEY *rootp = toku_calculate_root_offset_pointer(brt, &fullhash);
@@ -3368,7 +3368,7 @@ static int brt_cursor_next_shortcut (BRT_CURSOR cursor, DBT *outkey, DBT *outval
 {
     if (toku_omt_cursor_is_valid(cursor->omtcursor)) {
 	{
-	    u_int64_t h_counter = cursor->brt->root_put_counter;
+	    u_int64_t h_counter = cursor->brt->h->root_put_counter;
 	    if (h_counter != cursor->root_put_counter) return -1;
 	}
 	OMTVALUE le;
@@ -3406,7 +3406,7 @@ int toku_brt_cursor_peek_prev(BRT_CURSOR cursor, DBT *outkey, DBT *outval) {
     if (toku_omt_cursor_is_valid(cursor->omtcursor)) {
 	{
 	    assert(cursor->brt->h);
-	    u_int64_t h_counter = cursor->brt->root_put_counter;
+	    u_int64_t h_counter = cursor->brt->h->root_put_counter;
 	    if (h_counter != cursor->root_put_counter) return -1;
 	}
 	OMTVALUE le;
@@ -3432,7 +3432,7 @@ int toku_brt_cursor_peek_next(BRT_CURSOR cursor, DBT *outkey, DBT *outval) {
     if (toku_omt_cursor_is_valid(cursor->omtcursor)) {
 	{
 	    assert(cursor->brt->h);
-	    u_int64_t h_counter = cursor->brt->root_put_counter;
+	    u_int64_t h_counter = cursor->brt->h->root_put_counter;
 	    if (h_counter != cursor->root_put_counter) return -1;
 	}
 	OMTVALUE le;
@@ -3521,7 +3521,7 @@ static int brt_cursor_prev_shortcut (BRT_CURSOR cursor, DBT *outkey, DBT *outval
 {
     if (toku_omt_cursor_is_valid(cursor->omtcursor)) {
 	{
-	    u_int64_t h_counter = cursor->brt->root_put_counter;
+	    u_int64_t h_counter = cursor->brt->h->root_put_counter;
 	    if (h_counter != cursor->root_put_counter) return -1;
 	}
 	OMTVALUE le;
diff --git a/newbrt/valgrind.suppressions b/newbrt/valgrind.suppressions
index df8faa7faeb..12816032631 100644
--- a/newbrt/valgrind.suppressions
+++ b/newbrt/valgrind.suppressions
@@ -24,3 +24,11 @@
    fun:deflate
    fun:compress2
 }
+{
+   compress_is_not_valgrind_clean3_32
+   Memcheck:Cond
+   obj:/usr/lib/libz.so.1.2.3
+   obj:/usr/lib/libz.so.1.2.3
+   fun:deflate
+   fun:compress2
+}
-- 
2.30.9