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])
......
This diff is collapsed.
...@@ -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