Commit a5424332 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Make some of the PMA fields be unsigned.

Remove some leading __ (double underbars) from some symbols.  (Addresses #8.)
Improve the verification of node sizes (because recovery is having trouble with this.  Addresses #27.)


git-svn-id: file:///svn/tokudb@944 c7de825b-a66e-492c-adef-691d508d4ae1
parent f9cf264d
...@@ -380,6 +380,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl ...@@ -380,6 +380,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl
toku_pma_set_dup_mode(result->u.l.buffer, flags); toku_pma_set_dup_mode(result->u.l.buffer, flags);
if (flags & TOKU_DB_DUPSORT) toku_pma_set_dup_compare(result->u.l.buffer, dup_compare); if (flags & TOKU_DB_DUPSORT) toku_pma_set_dup_compare(result->u.l.buffer, dup_compare);
//printf("%s:%d r PMA= %p\n", __FILE__, __LINE__, result->u.l.buffer); //printf("%s:%d r PMA= %p\n", __FILE__, __LINE__, result->u.l.buffer);
toku_verify_counts(result);
#define BRT_USE_PMA_BULK_INSERT 1 #define BRT_USE_PMA_BULK_INSERT 1
#if BRT_USE_PMA_BULK_INSERT #if BRT_USE_PMA_BULK_INSERT
{ {
...@@ -388,7 +389,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl ...@@ -388,7 +389,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl
for (i=0; i<n_in_buf; i++) { for (i=0; i<n_in_buf; i++) {
bytevec key; ITEMLEN keylen; bytevec key; ITEMLEN keylen;
bytevec val; ITEMLEN vallen; bytevec val; ITEMLEN vallen;
toku_verify_counts(result); // The counts are wrong here
int idx __attribute__((__unused__)) = rbuf_int(&rc); int idx __attribute__((__unused__)) = rbuf_int(&rc);
rbuf_bytes(&rc, &key, &keylen); /* Returns a pointer into the rbuf. */ rbuf_bytes(&rc, &key, &keylen); /* Returns a pointer into the rbuf. */
toku_fill_dbt(&keys[i], key, keylen); toku_fill_dbt(&keys[i], key, keylen);
...@@ -424,6 +425,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl ...@@ -424,6 +425,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl
result->u.l.n_bytes_in_buffer += keylen + vallen + KEY_VALUE_OVERHEAD + PMA_ITEM_OVERHEAD; result->u.l.n_bytes_in_buffer += keylen + vallen + KEY_VALUE_OVERHEAD + PMA_ITEM_OVERHEAD;
} }
#endif #endif
toku_verify_counts(result);
} }
{ {
unsigned int n_read_so_far = rc.ndone; unsigned int n_read_so_far = rc.ndone;
...@@ -450,6 +452,10 @@ void toku_verify_counts (BRTNODE node) { ...@@ -450,6 +452,10 @@ void toku_verify_counts (BRTNODE node) {
/*foo*/ /*foo*/
if (node->height==0) { if (node->height==0) {
assert(node->u.l.buffer); assert(node->u.l.buffer);
unsigned int sum=0;
PMA_ITERATE(node->u.l.buffer, key __attribute__((__unused__)), keylen, data __attribute__((__unused__)), datalen,
sum+=(PMA_ITEM_OVERHEAD + KEY_VALUE_OVERHEAD + keylen + datalen));
assert(sum==node->u.l.n_bytes_in_buffer);
} else { } else {
unsigned int sum = 0; unsigned int sum = 0;
int i; int i;
......
...@@ -13,7 +13,7 @@ struct pma_cursor { ...@@ -13,7 +13,7 @@ struct pma_cursor {
struct pma { struct pma {
enum typ_tag tag; enum typ_tag tag;
int dup_mode; int dup_mode;
int N; /* How long is the array? Always a power of two >= 4. */ unsigned int N; /* How long is the array? Always a power of two >= 4. */
int n_pairs_present; /* How many array elements are non-null. */ int n_pairs_present; /* How many array elements are non-null. */
struct kv_pair **pairs; struct kv_pair **pairs;
int uplgN; /* The smallest power of two >= lg(N) */ int uplgN; /* The smallest power of two >= lg(N) */
...@@ -38,7 +38,7 @@ int toku_pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi); ...@@ -38,7 +38,7 @@ int toku_pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi);
void toku_pmainternal_calculate_parameters (PMA pma); void toku_pmainternal_calculate_parameters (PMA pma);
int toku_pmainternal_smooth_region (TOKUTXN, FILENUM, DISKOFF, struct kv_pair */*pairs*/[], int /*n*/, int /*idx*/, int /*base*/, PMA /*pma*/, int */*new_idx*/); int toku_pmainternal_smooth_region (TOKUTXN, FILENUM, DISKOFF, struct kv_pair */*pairs*/[], int /*n*/, int /*idx*/, int /*base*/, PMA /*pma*/, int */*new_idx*/);
int toku_pmainternal_printpairs (struct kv_pair *pairs[], int N); int toku_pmainternal_printpairs (struct kv_pair *pairs[], int N);
int toku_pmainternal_make_space_at (TOKUTXN, FILENUM, DISKOFF, PMA pma, int idx, int *new_index); int toku_pmainternal_make_space_at (TOKUTXN, FILENUM, DISKOFF, PMA pma, int idx, unsigned int *new_index);
int toku_pmainternal_find (PMA pma, DBT *); // The DB is so the comparison fuction can be called. int toku_pmainternal_find (PMA pma, DBT *); // The DB is so the comparison fuction can be called.
void toku_print_pma (PMA pma); /* useful for debugging, so keep the name short. I.e., not pmainternal_print_pma() */ void toku_print_pma (PMA pma); /* useful for debugging, so keep the name short. I.e., not pmainternal_print_pma() */
......
...@@ -30,7 +30,8 @@ void local_memory_check_all_free(void) { ...@@ -30,7 +30,8 @@ void local_memory_check_all_free(void) {
static void test_make_space_at (void) { static void test_make_space_at (void) {
PMA pma; PMA pma;
char *key; char *key;
int r, newi; int r;
unsigned int newi;
struct kv_pair *key_A, *key_B; struct kv_pair *key_A, *key_B;
key = "A"; key = "A";
...@@ -85,7 +86,7 @@ static void test_make_space_at (void) { ...@@ -85,7 +86,7 @@ static void test_make_space_at (void) {
toku_print_pma(pma); toku_print_pma(pma);
printf("r=%d\n", newi); printf("r=%d\n", newi);
{ {
int i; unsigned int i;
for (i=0; i<toku_pma_index_limit(pma); i++) { for (i=0; i<toku_pma_index_limit(pma); i++) {
if (pma->pairs[i]) { if (pma->pairs[i]) {
assert(i<newi); assert(i<newi);
...@@ -102,9 +103,9 @@ static void test_make_space_at (void) { ...@@ -102,9 +103,9 @@ static void test_make_space_at (void) {
static void test_pma_find (void) { static void test_pma_find (void) {
PMA pma; PMA pma;
int i; unsigned int i, fidx;
int r; int r;
const int N = 16; const unsigned int N = 16;
DBT k; DBT k;
MALLOC(pma); MALLOC(pma);
MALLOC_N(N,pma->pairs); MALLOC_N(N,pma->pairs);
...@@ -118,25 +119,25 @@ static void test_pma_find (void) { ...@@ -118,25 +119,25 @@ static void test_pma_find (void) {
pma->pairs[5] = kv_pair_malloc("hello", 5, 0, 0); pma->pairs[5] = kv_pair_malloc("hello", 5, 0, 0);
assert(toku_pma_index_limit(pma)==N); assert(toku_pma_index_limit(pma)==N);
r=toku_pmainternal_find(pma, toku_fill_dbt(&k, "hello", 5)); fidx=toku_pmainternal_find(pma, toku_fill_dbt(&k, "hello", 5));
assert(toku_pma_index_limit(pma)==N); assert(toku_pma_index_limit(pma)==N);
assert(r==5); assert(fidx==5);
r=toku_pmainternal_find(pma, toku_fill_dbt(&k, "there", 5)); fidx=toku_pmainternal_find(pma, toku_fill_dbt(&k, "there", 5));
assert(r==6); assert(fidx==6);
r=toku_pmainternal_find(pma, toku_fill_dbt(&k, "aaa", 3)); fidx=toku_pmainternal_find(pma, toku_fill_dbt(&k, "aaa", 3));
assert(r==0); assert(fidx==0);
pma->pairs[N-1] = kv_pair_malloc("there", 5, 0, 0); pma->pairs[N-1] = kv_pair_malloc("there", 5, 0, 0);
r=toku_pmainternal_find(pma, toku_fill_dbt(&k, "hello", 5)); fidx=toku_pmainternal_find(pma, toku_fill_dbt(&k, "hello", 5));
assert(r==5); assert(fidx==5);
r=toku_pmainternal_find(pma, toku_fill_dbt(&k, "there", 5)); fidx=toku_pmainternal_find(pma, toku_fill_dbt(&k, "there", 5));
assert(r==N-1); assert(fidx+1==N);
r=toku_pmainternal_find(pma, toku_fill_dbt(&k, "aaa", 3)); fidx=toku_pmainternal_find(pma, toku_fill_dbt(&k, "aaa", 3));
assert(r==0); assert(fidx==0);
r=toku_pmainternal_find(pma, toku_fill_dbt(&k, "hellob", 6)); fidx=toku_pmainternal_find(pma, toku_fill_dbt(&k, "hellob", 6));
assert(r==6); assert(fidx==6);
r=toku_pmainternal_find(pma, toku_fill_dbt(&k, "zzz", 3)); fidx=toku_pmainternal_find(pma, toku_fill_dbt(&k, "zzz", 3));
assert(r==N); assert(fidx==N);
for (i=0; i<N; i++) for (i=0; i<N; i++)
if (pma->pairs[i]) if (pma->pairs[i])
......
...@@ -41,7 +41,7 @@ static int old_pma_resize_array(PMA pma, int asksize, int startx) { ...@@ -41,7 +41,7 @@ static int old_pma_resize_array(PMA pma, int asksize, int startx) {
/* /*
* extract pairs from the pma in the window delimited by lo and hi. * extract pairs from the pma in the window delimited by lo and hi.
*/ */
static struct kv_pair_tag *__pma_extract_pairs(PMA pma, int count, int lo, int hi); static struct kv_pair_tag *pma_extract_pairs(PMA pma, int count, unsigned int lo, unsigned int hi);
/* /*
* update the cursors in a cursor set given a set of tagged pairs. * update the cursors in a cursor set given a set of tagged pairs.
...@@ -126,7 +126,7 @@ static int pma_compress_kvspace(PMA pma) { ...@@ -126,7 +126,7 @@ static int pma_compress_kvspace(PMA pma) {
return -2; return -2;
struct mempool new_kvspace; struct mempool new_kvspace;
toku_mempool_init(&new_kvspace, mp, pma->kvspace.size); toku_mempool_init(&new_kvspace, mp, pma->kvspace.size);
int i; unsigned int i;
for (i=0; i<pma->N; i++) { for (i=0; i<pma->N; i++) {
struct kv_pair *kv = pma->pairs[i]; struct kv_pair *kv = pma->pairs[i];
if (kv_pair_inuse(kv)) { if (kv_pair_inuse(kv)) {
...@@ -174,42 +174,42 @@ int toku_pma_n_entries (PMA pma) { ...@@ -174,42 +174,42 @@ int toku_pma_n_entries (PMA pma) {
return pma->n_pairs_present; return pma->n_pairs_present;
} }
int toku_pma_index_limit (PMA pma) { unsigned int toku_pma_index_limit (PMA pma) {
return pma->N; return pma->N;
} }
int toku_pmanode_valid (PMA pma, int i) { int toku_pmanode_valid (PMA pma, unsigned int i) {
assert(0<=i); assert(i<toku_pma_index_limit(pma)); assert(i<toku_pma_index_limit(pma));
return kv_pair_valid(pma->pairs[i]); return kv_pair_valid(pma->pairs[i]);
} }
bytevec toku_pmanode_key (PMA pma, int i) { bytevec toku_pmanode_key (PMA pma, unsigned int i) {
struct kv_pair *pair; struct kv_pair *pair;
assert(0<=i); assert(i<toku_pma_index_limit(pma)); assert(i<toku_pma_index_limit(pma));
pair = pma->pairs[i]; pair = pma->pairs[i];
assert(kv_pair_valid(pair)); assert(kv_pair_valid(pair));
return kv_pair_key(pair); return kv_pair_key(pair);
} }
ITEMLEN toku_pmanode_keylen (PMA pma, int i) { ITEMLEN toku_pmanode_keylen (PMA pma, unsigned int i) {
struct kv_pair *pair; struct kv_pair *pair;
assert(0<=i); assert(i<toku_pma_index_limit(pma)); assert(i<toku_pma_index_limit(pma));
pair = pma->pairs[i]; pair = pma->pairs[i];
assert(kv_pair_valid(pair)); assert(kv_pair_valid(pair));
return kv_pair_keylen(pair); return kv_pair_keylen(pair);
} }
bytevec toku_pmanode_val (PMA pma, int i) { bytevec toku_pmanode_val (PMA pma, unsigned int i) {
struct kv_pair *pair; struct kv_pair *pair;
assert(0<=i); assert(i<toku_pma_index_limit(pma)); assert(i<toku_pma_index_limit(pma));
pair = pma->pairs[i]; pair = pma->pairs[i];
assert(kv_pair_valid(pair)); assert(kv_pair_valid(pair));
return kv_pair_val(pair); return kv_pair_val(pair);
} }
ITEMLEN toku_pmanode_vallen (PMA pma, int i) { ITEMLEN toku_pmanode_vallen (PMA pma, unsigned int i) {
struct kv_pair *pair; struct kv_pair *pair;
assert(0<=i); assert(i<toku_pma_index_limit(pma)); assert(i<toku_pma_index_limit(pma));
pair = pma->pairs[i]; pair = pma->pairs[i];
assert(kv_pair_valid(pair)); assert(kv_pair_valid(pair));
return kv_pair_vallen(pair); return kv_pair_vallen(pair);
...@@ -218,7 +218,7 @@ ITEMLEN toku_pmanode_vallen (PMA pma, int i) { ...@@ -218,7 +218,7 @@ ITEMLEN toku_pmanode_vallen (PMA pma, int i) {
/* Could pick the same one every time if we wanted. */ /* Could pick the same one every time if we wanted. */
int toku_pma_random_pick(PMA pma, bytevec *key, ITEMLEN *keylen, bytevec *val, ITEMLEN *vallen) { int toku_pma_random_pick(PMA pma, bytevec *key, ITEMLEN *keylen, bytevec *val, ITEMLEN *vallen) {
#if 1 #if 1
int i; unsigned int i;
/* For now a simple implementation where we simply start at the beginning and look. */ /* For now a simple implementation where we simply start at the beginning and look. */
for (i=0; i<toku_pma_index_limit(pma); i++) { for (i=0; i<toku_pma_index_limit(pma); i++) {
...@@ -321,7 +321,7 @@ static int __pma_right_search(PMA pma, DBT *k, int lo, int hi, int *found) { ...@@ -321,7 +321,7 @@ static int __pma_right_search(PMA pma, DBT *k, int lo, int hi, int *found) {
} }
/* search the index for the left most matching key */ /* search the index for the left most matching key */
static int __pma_left_search(PMA pma, DBT *k, int lo, int hi, int *found) { static unsigned int pma_left_search(PMA pma, DBT *k, int lo, int hi, int *found) {
assert(0 <= lo && lo <= hi); assert(0 <= lo && lo <= hi);
if (lo >= hi) { if (lo >= hi) {
*found = 0; *found = 0;
...@@ -333,18 +333,18 @@ static int __pma_left_search(PMA pma, DBT *k, int lo, int hi, int *found) { ...@@ -333,18 +333,18 @@ static int __pma_left_search(PMA pma, DBT *k, int lo, int hi, int *found) {
while (mi < hi && !kv_pair_inuse(pma->pairs[mi])) while (mi < hi && !kv_pair_inuse(pma->pairs[mi]))
mi++; mi++;
if (mi >= hi) if (mi >= hi)
return __pma_left_search(pma, k, lo, omi, found); return pma_left_search(pma, k, lo, omi, found);
struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]); struct kv_pair *kv = kv_pair_ptr(pma->pairs[mi]);
DBT k2; DBT k2;
int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv))); int cmp = pma->compare_fun(pma->db, k, toku_fill_dbt(&k2, kv_pair_key(kv), kv_pair_keylen(kv)));
if (cmp > 0) if (cmp > 0)
return __pma_left_search(pma, k, mi+1, hi, found); return pma_left_search(pma, k, mi+1, hi, found);
if (cmp < 0) if (cmp < 0)
return __pma_left_search(pma, k, lo, mi, found); return pma_left_search(pma, k, lo, mi, found);
/* we have a match, try to find a match on the left tree */ /* we have a match, try to find a match on the left tree */
int here; int here;
here = __pma_left_search(pma, k, lo, mi, found); here = pma_left_search(pma, k, lo, mi, found);
if (*found == 0) if (*found == 0)
here = mi; here = mi;
*found = 1; *found = 1;
...@@ -431,7 +431,7 @@ int toku_pmainternal_find (PMA pma, DBT *k) { ...@@ -431,7 +431,7 @@ int toku_pmainternal_find (PMA pma, DBT *k) {
} }
assert(0<=lo); assert(0<=lo);
assert(lo==hi); assert(lo==hi);
assert(hi <= toku_pma_index_limit(pma)); assert((unsigned)hi <= toku_pma_index_limit(pma));
#if 0 #if 0
/* If lo points at something, the something should not be smaller than key. */ /* If lo points at something, the something should not be smaller than key. */
if (lo>0 && lo < toku_pma_index_limit(pma) && pma->pairs[lo]) { if (lo>0 && lo < toku_pma_index_limit(pma) && pma->pairs[lo]) {
...@@ -559,6 +559,11 @@ int toku_pmainternal_smooth_region (TOKUTXN txn, FILENUM filenum, DISKOFF diskof ...@@ -559,6 +559,11 @@ int toku_pmainternal_smooth_region (TOKUTXN txn, FILENUM filenum, DISKOFF diskof
} }
} }
int r=toku_log_pmadistribute(txn, toku_txn_get_txnid(txn), filenum, diskoff, ipa); int r=toku_log_pmadistribute(txn, toku_txn_get_txnid(txn), filenum, diskoff, ipa);
if (0 && pma) {
printf("Pma state:\n");
PMA_ITERATE_IDX (pma, pidx, key, keylen, data, datalen,
printf(" %d:(%d:%s) (%d:%s)\n", pidx, keylen, (char*)key, datalen, (char*)data));
}
toku_free(ipa.array); toku_free(ipa.array);
if (r!=0) return r; if (r!=0) return r;
} }
...@@ -642,7 +647,7 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM fil ...@@ -642,7 +647,7 @@ int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, DB *db, FILENUM fil
} }
/* find the smallest power of 2 >= n */ /* find the smallest power of 2 >= n */
static int __pma_array_size(PMA pma __attribute__((unused)), int asksize) { static unsigned int pma_array_size(PMA pma __attribute__((unused)), int asksize) {
int n = PMA_MIN_ARRAY_SIZE; int n = PMA_MIN_ARRAY_SIZE;
while (n < asksize) while (n < asksize)
n *= 2; n *= 2;
...@@ -660,7 +665,7 @@ int toku_resize_pma_exactly (PMA pma, int oldsize, int newsize) { ...@@ -660,7 +665,7 @@ int toku_resize_pma_exactly (PMA pma, int oldsize, int newsize) {
return -1; return -1;
pma->pairs[pma->N] = (void *) 0xdeadbeef; pma->pairs[pma->N] = (void *) 0xdeadbeef;
int i; unsigned int i;
for (i=oldsize; i<pma->N; i++) { for (i=oldsize; i<pma->N; i++) {
pma->pairs[i] = 0; pma->pairs[i] = 0;
} }
...@@ -668,10 +673,8 @@ int toku_resize_pma_exactly (PMA pma, int oldsize, int newsize) { ...@@ -668,10 +673,8 @@ int toku_resize_pma_exactly (PMA pma, int oldsize, int newsize) {
} }
static int pma_resize_array(TOKUTXN txn, FILENUM filenum, DISKOFF offset, PMA pma, int asksize, int startz) { static int pma_resize_array(TOKUTXN txn, FILENUM filenum, DISKOFF offset, PMA pma, int asksize, int startz) {
int n; unsigned int oldN = pma->N;
int oldN = pma->N; unsigned int n = pma_array_size(pma, asksize);
n = __pma_array_size(pma, asksize);
int r = toku_resize_pma_exactly(pma, startz, n); int r = toku_resize_pma_exactly(pma, startz, n);
if (r!=0) return r; if (r!=0) return r;
toku_pmainternal_calculate_parameters(pma); toku_pmainternal_calculate_parameters(pma);
...@@ -754,7 +757,7 @@ int toku_pma_cursor_set_position_first (PMA_CURSOR c) { ...@@ -754,7 +757,7 @@ int toku_pma_cursor_set_position_first (PMA_CURSOR c) {
int old_position = c->position; int old_position = c->position;
c->position=0; c->position=0;
while (!kv_pair_valid(c->pma->pairs[c->position])) { while (!kv_pair_valid(c->pma->pairs[c->position])) {
if (c->position+1<pma->N) if (c->position+1<(signed)pma->N)
c->position++; c->position++;
else { else {
c->position = -1; c->position = -1;
...@@ -771,7 +774,7 @@ int toku_pma_cursor_set_position_next (PMA_CURSOR c) { ...@@ -771,7 +774,7 @@ int toku_pma_cursor_set_position_next (PMA_CURSOR c) {
PMA pma = c->pma; PMA pma = c->pma;
int old_position=c->position; int old_position=c->position;
c->position++; c->position++;
while (c->position<pma->N) { while (c->position<(signed)pma->N) {
if (kv_pair_valid(c->pma->pairs[c->position])) { if (kv_pair_valid(c->pma->pairs[c->position])) {
__pma_delete_resume(pma, old_position); __pma_delete_resume(pma, old_position);
return 0; return 0;
...@@ -807,14 +810,15 @@ int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) { ...@@ -807,14 +810,15 @@ int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) {
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key) { int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key) {
PMA pma = c->pma; PMA pma = c->pma;
int here, found; unsigned int here;
int found;
if (pma->dup_mode & TOKU_DB_DUP) { if (pma->dup_mode & TOKU_DB_DUP) {
here = __pma_left_search(pma, key, 0, pma->N, &found); here = pma_left_search(pma, key, 0, pma->N, &found);
} else } else
here = toku_pmainternal_find(pma, key); here = toku_pmainternal_find(pma, key);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma)); assert(here<=toku_pma_index_limit(pma));
int r = DB_NOTFOUND; int r = DB_NOTFOUND;
if (here < pma->N) { if (here < (unsigned)pma->N) {
DBT k2; DBT k2;
struct kv_pair *pair = pma->pairs[here]; struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair) && if (kv_pair_valid(pair) &&
...@@ -829,8 +833,8 @@ int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key) { ...@@ -829,8 +833,8 @@ int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key) {
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val) { int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val) {
PMA pma = c->pma; PMA pma = c->pma;
int here = toku_pmainternal_find(pma, key); unsigned int here = toku_pmainternal_find(pma, key);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma)); assert(here<=toku_pma_index_limit(pma));
int r = DB_NOTFOUND; int r = DB_NOTFOUND;
if (here < pma->N) { if (here < pma->N) {
DBT k2, v2; DBT k2, v2;
...@@ -848,12 +852,13 @@ int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val) { ...@@ -848,12 +852,13 @@ int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val) {
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key) { int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key) {
PMA pma = c->pma; PMA pma = c->pma;
int here, found; unsigned int here;
int found;
if (pma->dup_mode & TOKU_DB_DUP) if (pma->dup_mode & TOKU_DB_DUP)
here = __pma_left_search(pma, key, 0, pma->N, &found); here = pma_left_search(pma, key, 0, pma->N, &found);
else else
here = toku_pmainternal_find(pma, key); here = toku_pmainternal_find(pma, key);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma)); assert(here<=toku_pma_index_limit(pma));
/* find the first valid pair where key[here] >= key */ /* find the first valid pair where key[here] >= key */
int r = DB_NOTFOUND; int r = DB_NOTFOUND;
...@@ -874,7 +879,7 @@ int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize) { ...@@ -874,7 +879,7 @@ int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize) {
int r = DB_NOTFOUND; int r = DB_NOTFOUND;
if (c->position >= 0) { if (c->position >= 0) {
PMA pma = c->pma; PMA pma = c->pma;
assert(c->position < pma->N); assert((unsigned)c->position < pma->N);
struct kv_pair *kv = pma->pairs[c->position]; struct kv_pair *kv = pma->pairs[c->position];
if (kv_pair_valid(kv)) { if (kv_pair_valid(kv)) {
if (kvsize) if (kvsize)
...@@ -902,13 +907,13 @@ int toku_pma_cursor_free (PMA_CURSOR *cursp) { ...@@ -902,13 +907,13 @@ int toku_pma_cursor_free (PMA_CURSOR *cursp) {
/* Make some space for a key to go at idx (the thing currently at idx should end up at to the right.) */ /* Make some space for a key to go at idx (the thing currently at idx should end up at to the right.) */
/* (Making space may involve moving things around, including the hole at index.) */ /* (Making space may involve moving things around, including the hole at index.) */
int toku_pmainternal_make_space_at (TOKUTXN txn, FILENUM filenum, DISKOFF offset, PMA pma, int idx, int *new_index) { int toku_pmainternal_make_space_at (TOKUTXN txn, FILENUM filenum, DISKOFF offset, PMA pma, int idx, unsigned int *new_index) {
/* Within a range LO to HI we have a limit of how much packing we will tolerate. /* Within a range LO to HI we have a limit of how much packing we will tolerate.
* We allow the entire array to be 50% full. * We allow the entire array to be 50% full.
* We allow a region of size lgN to be full. * We allow a region of size lgN to be full.
* At sizes in between, we interpolate. * At sizes in between, we interpolate.
*/ */
int size=pma->uplgN; unsigned int size=pma->uplgN;
int lo=idx; int lo=idx;
int hi=idx; int hi=idx;
double udt=PMA_UDT_HIGH; double udt=PMA_UDT_HIGH;
...@@ -918,20 +923,20 @@ int toku_pmainternal_make_space_at (TOKUTXN txn, FILENUM filenum, DISKOFF offset ...@@ -918,20 +923,20 @@ int toku_pmainternal_make_space_at (TOKUTXN txn, FILENUM filenum, DISKOFF offset
hi=idx+size/2; hi=idx+size/2;
//printf("lo=%d hi=%d\n", lo, hi); //printf("lo=%d hi=%d\n", lo, hi);
if (lo<0) { hi-=lo; lo=0; } if (lo<0) { hi-=lo; lo=0; }
else if (hi>toku_pma_index_limit(pma)) { lo-=(hi-toku_pma_index_limit(pma)); hi=toku_pma_index_limit(pma); } else if ((unsigned)hi>toku_pma_index_limit(pma)) { lo-=(hi-toku_pma_index_limit(pma)); hi=toku_pma_index_limit(pma); }
else { ; /* nothing */ } else { ; /* nothing */ }
//printf("lo=%d hi=%d\n", lo, hi); //printf("lo=%d hi=%d\n", lo, hi);
assert(0<=lo); assert(lo<hi); assert(hi<=toku_pma_index_limit(pma)); assert(hi-lo==size); // separate into separate assertions so that gcov doesn't see branches not taken. assert(0<=lo); assert(lo<hi); assert((unsigned)hi<=toku_pma_index_limit(pma)); assert((unsigned)(hi-lo)==size); // separate into separate assertions so that gcov doesn't see branches not taken.
assert(udt>0.499); assert(udt<=1); assert(udt>0.499); assert(udt<=1);
if (udt<0.5001) { assert(lo==0); assert(hi==toku_pma_index_limit(pma)); } if (udt<0.5001) { assert(lo==0); assert((unsigned)hi==toku_pma_index_limit(pma)); }
{ {
int count = (1+ /* Don't forget space for the new guy. */ int count = (1+ /* Don't forget space for the new guy. */
toku_pmainternal_count_region(pma->pairs, lo, hi)); toku_pmainternal_count_region(pma->pairs, lo, hi));
double density = (double) count / (double) (hi - lo); double density = (double) count / (double) (hi - lo);
if (density <= udt) if (density <= udt)
break; break;
if (lo==0 && hi==toku_pma_index_limit(pma)) { if (lo==0 && (unsigned)hi==toku_pma_index_limit(pma)) {
/* The array needs to be doubled in size. */ /* The array needs to be doubled in size. */
assert(size==toku_pma_index_limit(pma)); assert(size==toku_pma_index_limit(pma));
...@@ -959,12 +964,13 @@ int toku_pmainternal_make_space_at (TOKUTXN txn, FILENUM filenum, DISKOFF offset ...@@ -959,12 +964,13 @@ int toku_pmainternal_make_space_at (TOKUTXN txn, FILENUM filenum, DISKOFF offset
} }
enum pma_errors toku_pma_lookup (PMA pma, DBT *k, DBT *v) { enum pma_errors toku_pma_lookup (PMA pma, DBT *k, DBT *v) {
int here, found; unsigned int here;
int found;
if (pma->dup_mode & TOKU_DB_DUP) { if (pma->dup_mode & TOKU_DB_DUP) {
here = __pma_left_search(pma, k, 0, pma->N, &found); here = pma_left_search(pma, k, 0, pma->N, &found);
} else } else
here = toku_pmainternal_find(pma, k); here = toku_pmainternal_find(pma, k);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma)); assert(here<=toku_pma_index_limit(pma));
if (here==toku_pma_index_limit(pma)) return DB_NOTFOUND; if (here==toku_pma_index_limit(pma)) return DB_NOTFOUND;
DBT k2; DBT k2;
struct kv_pair *pair; struct kv_pair *pair;
...@@ -979,12 +985,12 @@ enum pma_errors toku_pma_lookup (PMA pma, DBT *k, DBT *v) { ...@@ -979,12 +985,12 @@ enum pma_errors toku_pma_lookup (PMA pma, DBT *k, DBT *v) {
/* returns 0 if OK. /* returns 0 if OK.
* You must have freed all the cursors, otherwise returns nonzero and does nothing. */ * You must have freed all the cursors, otherwise returns nonzero and does nothing. */
int toku_pma_free (PMA *pmap) { int toku_pma_free (PMA *pmap) {
int i;
PMA pma=*pmap; PMA pma=*pmap;
if (!list_empty(&pma->cursors)) if (!list_empty(&pma->cursors))
return -1; return -1;
if (pma->n_pairs_present > 0) { if (pma->n_pairs_present > 0) {
unsigned int i;
for (i=0; i < pma->N; i++) { for (i=0; i < pma->N; i++) {
struct kv_pair *kv = pma->pairs[i]; struct kv_pair *kv = pma->pairs[i];
if (kv_pair_inuse(kv)) { if (kv_pair_inuse(kv)) {
...@@ -1011,7 +1017,8 @@ int toku_pma_free (PMA *pmap) { ...@@ -1011,7 +1017,8 @@ int toku_pma_free (PMA *pmap) {
/* Copies keylen and datalen */ /* Copies keylen and datalen */
/* returns an error if the key is already present. */ /* returns an error if the key is already present. */
int toku_pma_insert (PMA pma, DBT *k, DBT *v, TOKUTXN txn, FILENUM filenum, DISKOFF diskoff, u_int32_t rand4fingerprint, u_int32_t *fingerprint) { int toku_pma_insert (PMA pma, DBT *k, DBT *v, TOKUTXN txn, FILENUM filenum, DISKOFF diskoff, u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
int found, idx; int found;
unsigned int idx;
if (pma->dup_mode & TOKU_DB_DUPSORT) { if (pma->dup_mode & TOKU_DB_DUPSORT) {
idx = __pma_dup_search(pma, k, v, 0, pma->N, &found); idx = __pma_dup_search(pma, k, v, 0, pma->N, &found);
...@@ -1040,12 +1047,12 @@ int toku_pma_insert (PMA pma, DBT *k, DBT *v, TOKUTXN txn, FILENUM filenum, DISK ...@@ -1040,12 +1047,12 @@ int toku_pma_insert (PMA pma, DBT *k, DBT *v, TOKUTXN txn, FILENUM filenum, DISK
} }
} }
if (kv_pair_inuse(pma->pairs[idx])) { if (kv_pair_inuse(pma->pairs[idx])) {
int newidx; unsigned int newidx;
int r = toku_pmainternal_make_space_at (txn, filenum, diskoff, pma, idx, &newidx); /* returns the new idx. */ int r = toku_pmainternal_make_space_at (txn, filenum, diskoff, pma, idx, &newidx); /* returns the new idx. */
if (r!=0) return r; if (r!=0) return r;
idx = newidx; idx = newidx;
} }
assert(0 <= idx && idx < pma->N); assert(idx < pma->N);
assert(!kv_pair_inuse(pma->pairs[idx])); assert(!kv_pair_inuse(pma->pairs[idx]));
pma->pairs[idx] = pma_malloc_kv_pair(pma, k->data, k->size, v->data, v->size); pma->pairs[idx] = pma_malloc_kv_pair(pma, k->data, k->size, v->data, v->size);
assert(pma->pairs[idx]); assert(pma->pairs[idx]);
...@@ -1076,8 +1083,9 @@ static int pma_next_key(PMA pma, DBT *k, int here, int n, int *found) { ...@@ -1076,8 +1083,9 @@ static int pma_next_key(PMA pma, DBT *k, int here, int n, int *found) {
static int pma_delete_dup (PMA pma, DBT *k, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) { static int pma_delete_dup (PMA pma, DBT *k, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
/* find the left most matching key in the pma */ /* find the left most matching key in the pma */
int found, lefthere; int found;
lefthere = __pma_left_search(pma, k, 0, pma->N, &found); unsigned int lefthere;
lefthere = pma_left_search(pma, k, 0, pma->N, &found);
int rightfound = found, righthere = lefthere; int rightfound = found, righthere = lefthere;
while (rightfound) { while (rightfound) {
struct kv_pair *kv = pma->pairs[righthere]; struct kv_pair *kv = pma->pairs[righthere];
...@@ -1144,15 +1152,12 @@ static void __pma_delete_finish(PMA pma, int here) { ...@@ -1144,15 +1152,12 @@ static void __pma_delete_finish(PMA pma, int here) {
} }
static void __pma_delete_at(PMA pma, int here) { static void __pma_delete_at(PMA pma, int here) {
int size;
int count; int count;
struct kv_pair_tag *newpairs; struct kv_pair_tag *newpairs;
int lgN;
double ldt;
lgN = pma->uplgN; unsigned int lgN = pma->uplgN;
size = lgN; unsigned int size = lgN;
ldt = PMA_LDT_HIGH; double ldt = PMA_LDT_HIGH;
/* check the density of regions from lg(N) size to the entire array */ /* check the density of regions from lg(N) size to the entire array */
for (;;) { for (;;) {
...@@ -1165,9 +1170,9 @@ static void __pma_delete_at(PMA pma, int here) { ...@@ -1165,9 +1170,9 @@ static void __pma_delete_at(PMA pma, int here) {
if (lo < 0) { if (lo < 0) {
hi -= lo; hi -= lo;
lo = 0; lo = 0;
if (hi > pma->N) if ((unsigned)hi > pma->N)
hi = pma->N; hi = pma->N;
} else if (hi > pma->N) { } else if ((unsigned)hi > pma->N) {
lo -= hi - pma->N; lo -= hi - pma->N;
hi = pma->N; hi = pma->N;
if (lo < 0) if (lo < 0)
...@@ -1186,7 +1191,7 @@ static void __pma_delete_at(PMA pma, int here) { ...@@ -1186,7 +1191,7 @@ static void __pma_delete_at(PMA pma, int here) {
if (size == lgN) if (size == lgN)
return; return;
if (0) printf("delete_at_rebalance %d over %d %d\n", count, lo, hi); if (0) printf("delete_at_rebalance %d over %d %d\n", count, lo, hi);
newpairs = __pma_extract_pairs(pma, count, lo, hi); newpairs = pma_extract_pairs(pma, count, lo, hi);
distribute_data(pma->pairs + lo, hi - lo, newpairs, count, pma); distribute_data(pma->pairs + lo, hi - lo, newpairs, count, pma);
__pma_update_my_cursors(pma, newpairs, count); __pma_update_my_cursors(pma, newpairs, count);
toku_free(newpairs); toku_free(newpairs);
...@@ -1194,16 +1199,16 @@ static void __pma_delete_at(PMA pma, int here) { ...@@ -1194,16 +1199,16 @@ static void __pma_delete_at(PMA pma, int here) {
} }
ldt -= pma->ldt_step; ldt -= pma->ldt_step;
size *= 2; size *= 2;
if (0 == lo && pma->N == hi) if (0 == lo && pma->N == (unsigned)hi)
break; break;
} }
/* shrink */ /* shrink */
size = __pma_array_size(pma, count + count/4); size = pma_array_size(pma, count + count/4);
if (size == pma->N) if (size == pma->N)
return; return;
if (0) printf("shrink %d from %d to %d\n", count, pma->N, size); if (0) printf("shrink %d from %d to %d\n", count, pma->N, size);
newpairs = __pma_extract_pairs(pma, count, 0, pma->N); newpairs = pma_extract_pairs(pma, count, 0, pma->N);
assert(newpairs); assert(newpairs);
old_pma_resize_array(pma, size, 0); old_pma_resize_array(pma, size, 0);
distribute_data(pma->pairs, pma->N, newpairs, count, pma); distribute_data(pma->pairs, pma->N, newpairs, count, pma);
...@@ -1218,7 +1223,8 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v, ...@@ -1218,7 +1223,8 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
u_int32_t rand4fingerprint, u_int32_t *fingerprint) { u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
//printf("%s:%d v->size=%d\n", __FILE__, __LINE__, v->size); //printf("%s:%d v->size=%d\n", __FILE__, __LINE__, v->size);
int r; int r;
int idx, found; unsigned int idx;
int found;
if (pma->dup_mode & TOKU_DB_DUPSORT) { if (pma->dup_mode & TOKU_DB_DUPSORT) {
idx = __pma_dup_search(pma, k, v, 0, pma->N, &found); idx = __pma_dup_search(pma, k, v, 0, pma->N, &found);
if (found) if (found)
...@@ -1255,7 +1261,7 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v, ...@@ -1255,7 +1261,7 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
} }
} }
if (kv_pair_inuse(pma->pairs[idx])) { if (kv_pair_inuse(pma->pairs[idx])) {
int newidx; unsigned int newidx;
r = toku_pmainternal_make_space_at (txn, filenum, diskoff, pma, idx, &newidx); /* returns the new idx. */ r = toku_pmainternal_make_space_at (txn, filenum, diskoff, pma, idx, &newidx); /* returns the new idx. */
if (r!=0) return r; if (r!=0) return r;
idx=newidx; idx=newidx;
...@@ -1278,7 +1284,7 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v, ...@@ -1278,7 +1284,7 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
} }
void toku_pma_iterate (PMA pma, void(*f)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*v) { void toku_pma_iterate (PMA pma, void(*f)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*v) {
int i; unsigned int i;
for (i=0; i<toku_pma_index_limit(pma); i++) { for (i=0; i<toku_pma_index_limit(pma); i++) {
struct kv_pair *pair = pma->pairs[i]; struct kv_pair *pair = pma->pairs[i];
if (pair) { if (pair) {
...@@ -1350,9 +1356,9 @@ static void __pma_update_my_cursors(PMA pma, struct kv_pair_tag *tpairs, int n) ...@@ -1350,9 +1356,9 @@ static void __pma_update_my_cursors(PMA pma, struct kv_pair_tag *tpairs, int n)
} }
} }
static struct kv_pair_tag *__pma_extract_pairs(PMA pma, int npairs, int lo, int hi) { static struct kv_pair_tag *pma_extract_pairs(PMA pma, int npairs, unsigned int lo, unsigned int hi) {
struct kv_pair_tag *pairs; struct kv_pair_tag *pairs;
int i; unsigned int i;
int lastpair; int lastpair;
pairs = toku_malloc(npairs * sizeof (struct kv_pair_tag)); pairs = toku_malloc(npairs * sizeof (struct kv_pair_tag));
...@@ -1360,7 +1366,7 @@ static struct kv_pair_tag *__pma_extract_pairs(PMA pma, int npairs, int lo, int ...@@ -1360,7 +1366,7 @@ static struct kv_pair_tag *__pma_extract_pairs(PMA pma, int npairs, int lo, int
return 0; return 0;
lastpair = 0; lastpair = 0;
for (i=lo; i<hi; i++) { for (i=lo; i<hi; i++) {
assert(0 <= i && i < pma->N); assert(i < pma->N);
if (pma->pairs[i] != 0) { if (pma->pairs[i] != 0) {
assert(pma->pairs[i] != (void*)0xdeadbeef); assert(pma->pairs[i] != (void*)0xdeadbeef);
pairs[lastpair].pair = pma->pairs[i]; pairs[lastpair].pair = pma->pairs[i];
...@@ -1376,7 +1382,7 @@ static struct kv_pair_tag *__pma_extract_pairs(PMA pma, int npairs, int lo, int ...@@ -1376,7 +1382,7 @@ static struct kv_pair_tag *__pma_extract_pairs(PMA pma, int npairs, int lo, int
#if PMA_USE_MEMPOOL #if PMA_USE_MEMPOOL
static void __pma_relocate_kvpairs(PMA pma) { static void __pma_relocate_kvpairs(PMA pma) {
int i; unsigned int i;
for (i=0; i<pma->N; i++) { for (i=0; i<pma->N; i++) {
struct kv_pair *kv = pma->pairs[i]; struct kv_pair *kv = pma->pairs[i];
if (kv) { if (kv) {
...@@ -1423,7 +1429,7 @@ int toku_pma_split(TOKUTXN txn, FILENUM filenum, ...@@ -1423,7 +1429,7 @@ int toku_pma_split(TOKUTXN txn, FILENUM filenum,
assert(toku_pma_n_entries(rightpma) == 0); assert(toku_pma_n_entries(rightpma) == 0);
/* TODO move pairs to the stack */ /* TODO move pairs to the stack */
pairs = __pma_extract_pairs(origpma, npairs, 0, origpma->N); pairs = pma_extract_pairs(origpma, npairs, 0, origpma->N);
assert(pairs); assert(pairs);
origpma->n_pairs_present = 0; origpma->n_pairs_present = 0;
...@@ -1581,7 +1587,7 @@ int toku_pma_bulk_insert(TOKUTXN txn, FILENUM filenum, DISKOFF diskoff, PMA pma, ...@@ -1581,7 +1587,7 @@ int toku_pma_bulk_insert(TOKUTXN txn, FILENUM filenum, DISKOFF diskoff, PMA pma,
*/ */
void toku_pma_verify(PMA pma) { void toku_pma_verify(PMA pma) {
int i; unsigned int i;
struct kv_pair *kv; struct kv_pair *kv;
/* find the first key in the index */ /* find the first key in the index */
...@@ -1640,8 +1646,8 @@ void toku_pma_verify_fingerprint (PMA pma, u_int32_t rand4fingerprint, u_int32_t ...@@ -1640,8 +1646,8 @@ void toku_pma_verify_fingerprint (PMA pma, u_int32_t rand4fingerprint, u_int32_t
// If the index is wrong or there is a value already, return nonzero // If the index is wrong or there is a value already, return nonzero
// There should be no cursors, but if there were they wouldn't need to be updated. // There should be no cursors, but if there were they wouldn't need to be updated.
int toku_pma_set_at_index (PMA pma, int idx, DBT *key, DBT *value) { int toku_pma_set_at_index (PMA pma, unsigned int idx, DBT *key, DBT *value) {
if (idx<0 || idx>=pma->N) return -1; if (idx>=pma->N) return -1;
if (kv_pair_inuse(pma->pairs[idx])) return -1; if (kv_pair_inuse(pma->pairs[idx])) return -1;
pma->pairs[idx] = pma_malloc_kv_pair(pma, key->data, key->size, value->data, value->size); pma->pairs[idx] = pma_malloc_kv_pair(pma, key->data, key->size, value->data, value->size);
pma->n_pairs_present++; pma->n_pairs_present++;
......
...@@ -122,17 +122,17 @@ int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize); ...@@ -122,17 +122,17 @@ int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize);
int toku_pma_random_pick(PMA, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen); int toku_pma_random_pick(PMA, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen);
int toku_pma_index_limit(PMA); // How many slots are in the PMA right now? unsigned int toku_pma_index_limit(PMA); // How many slots are in the PMA right now?
int toku_pmanode_valid(PMA,int); int toku_pmanode_valid(PMA, unsigned int);
bytevec toku_pmanode_key(PMA,int); bytevec toku_pmanode_key(PMA, unsigned int);
ITEMLEN toku_pmanode_keylen(PMA,int); ITEMLEN toku_pmanode_keylen(PMA, unsigned int);
bytevec toku_pmanode_val(PMA,int); bytevec toku_pmanode_val(PMA, unsigned int);
ITEMLEN toku_pmanode_vallen(PMA,int); ITEMLEN toku_pmanode_vallen(PMA, unsigned int);
void toku_pma_iterate (PMA, void(*)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*); void toku_pma_iterate (PMA, void(*)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*);
#define PMA_ITERATE_IDX(table,idx,keyvar,keylenvar,datavar,datalenvar,body) ({ \ #define PMA_ITERATE_IDX(table,idx,keyvar,keylenvar,datavar,datalenvar,body) ({ \
int idx; \ unsigned int idx; \
for (idx=0; idx<toku_pma_index_limit(table); idx++) { \ for (idx=0; idx<toku_pma_index_limit(table); idx++) { \
if (toku_pmanode_valid(table,idx)) { \ if (toku_pmanode_valid(table,idx)) { \
bytevec keyvar = toku_pmanode_key(table,idx); \ bytevec keyvar = toku_pmanode_key(table,idx); \
...@@ -149,7 +149,7 @@ void toku_pma_verify_fingerprint (PMA pma, u_int32_t rand4fingerprint, u_int32_t ...@@ -149,7 +149,7 @@ void toku_pma_verify_fingerprint (PMA pma, u_int32_t rand4fingerprint, u_int32_t
// Set the PMA's size, without moving anything. // Set the PMA's size, without moving anything.
int toku_resize_pma_exactly (PMA pma, int oldsize, int newsize); int toku_resize_pma_exactly (PMA pma, int oldsize, int newsize);
int toku_pma_set_at_index (PMA, int /*index*/, DBT */*key*/, DBT */*value*/); // If the index is wrong or there is a value already, return nonzero int toku_pma_set_at_index (PMA, unsigned int /*index*/, DBT */*key*/, DBT */*value*/); // If the index is wrong or there is a value already, return nonzero
// Requires: No open cursors on the pma. // Requires: No open cursors on the pma.
int toku_pma_move_indices (PMA pma, INTPAIRARRAY fromto); // Return nonzero if the indices are somehow wrong. int toku_pma_move_indices (PMA pma, INTPAIRARRAY fromto); // Return nonzero if the indices are somehow wrong.
......
...@@ -180,6 +180,13 @@ static void toku_recover_pmadistribute (struct logtype_pmadistribute *c) { ...@@ -180,6 +180,13 @@ static void toku_recover_pmadistribute (struct logtype_pmadistribute *c) {
assert(r==0); assert(r==0);
BRTNODE node = node_v; BRTNODE node = node_v;
assert(node->height==0); assert(node->height==0);
{
unsigned int i;
for (i=0; i<c->fromto.size; i++) {
assert(c->fromto.array[i].a < toku_pma_index_limit(node->u.l.buffer));
assert(c->fromto.array[i].b < toku_pma_index_limit(node->u.l.buffer));
}
}
r = toku_pma_move_indices (node->u.l.buffer, c->fromto); r = toku_pma_move_indices (node->u.l.buffer, c->fromto);
// The bytes in bufer and fingerprint shouldn't change // The bytes in bufer and fingerprint shouldn't change
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment