Commit 8de2b2f1 authored by Dave Wells's avatar Dave Wells Committed by Yoni Fogel

fixes from hotindexer recovery code review

git-svn-id: file:///svn/toku/tokudb@26176 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8f052632
...@@ -152,7 +152,7 @@ struct tokutxn { ...@@ -152,7 +152,7 @@ struct tokutxn {
BOOL recovered_from_checkpoint; BOOL recovered_from_checkpoint;
ROLLBACK_LOG_NODE pinned_inprogress_rollback_log; ROLLBACK_LOG_NODE pinned_inprogress_rollback_log;
struct toku_list checkpoint_before_commit; struct toku_list checkpoint_before_commit;
TXN_IGNORE ignore_errors; // 2954 TXN_IGNORE_S ignore_errors; // 2954
}; };
struct txninfo { struct txninfo {
......
...@@ -133,22 +133,23 @@ static inline void rbuf_ma_FILENUM (struct rbuf *r, MEMARENA ma __attribute__((_ ...@@ -133,22 +133,23 @@ static inline void rbuf_ma_FILENUM (struct rbuf *r, MEMARENA ma __attribute__((_
// 2954 // 2954
// Don't try to use the same space, malloc it // Don't try to use the same space, malloc it
static inline void rbuf_FILENUMS (struct rbuf *r, FILENUMS *filenums) { static inline void rbuf_FILENUMS(struct rbuf *r, FILENUMS *filenums) {
filenums->num = rbuf_int(r); filenums->num = rbuf_int(r);
u_int32_t newndone = r->ndone + ( filenums->num * sizeof(FILENUM) ); filenums->filenums = toku_malloc( filenums->num * sizeof(FILENUM) );
assert(newndone <= r->size); assert(filenums->filenums != NULL);
filenums->filenums = (FILENUM *) toku_memdup(&r->buf[r->ndone], (size_t)filenums->num * sizeof(FILENUM)); for (u_int32_t i=0; i < filenums->num; i++) {
assert(filenums->filenums); rbuf_FILENUM(r, &(filenums->filenums[i]));
r->ndone = newndone; }
} }
// 2954 // 2954
static inline void rbuf_ma_FILENUMS (struct rbuf *r, MEMARENA ma __attribute__((__unused__)), FILENUMS *filenums) { static inline void rbuf_ma_FILENUMS (struct rbuf *r, MEMARENA ma __attribute__((__unused__)), FILENUMS *filenums) {
filenums->num = rbuf_int(r); rbuf_ma_u_int32_t(r, ma, &(filenums->num));
u_int32_t newndone = r->ndone + ( filenums->num * sizeof(FILENUM) ); filenums->filenums = malloc_in_memarena(ma, filenums->num * sizeof(FILENUM) );
assert(newndone <= r->size); assert(filenums->filenums != NULL);
filenums->filenums = (FILENUM *) memarena_memdup(ma, &r->buf[r->ndone], (size_t)filenums->num * sizeof(FILENUM)); for (u_int32_t i=0; i < filenums->num; i++) {
assert(filenums->filenums); rbuf_ma_FILENUM(r, ma, &(filenums->filenums[i]));
r->ndone = newndone; }
} }
// Don't try to use the same space, malloc it // Don't try to use the same space, malloc it
......
...@@ -403,7 +403,7 @@ live_txn_ignore(OMTVALUE vtxn, u_int32_t UU(idx) , void *vfn) { ...@@ -403,7 +403,7 @@ live_txn_ignore(OMTVALUE vtxn, u_int32_t UU(idx) , void *vfn) {
int r; int r;
for (uint32_t i=0; i<hot_index_filenums->num;i++) { for (uint32_t i=0; i<hot_index_filenums->num;i++) {
r = toku_txn_ignore_add(txn, hot_index_filenums->filenums[i]); r = toku_txn_ignore_add(txn, hot_index_filenums->filenums[i]);
if ( r != 0 ) return r; invariant(r==0);
} }
return 0; return 0;
} }
...@@ -416,7 +416,6 @@ toku_rollback_hot_index (FILENUMS UU(hot_index_filenums), ...@@ -416,7 +416,6 @@ toku_rollback_hot_index (FILENUMS UU(hot_index_filenums),
LSN UU(oplsn)) LSN UU(oplsn))
{ {
int r = toku_omt_iterate(txn->logger->live_txns, live_txn_ignore, &hot_index_filenums); int r = toku_omt_iterate(txn->logger->live_txns, live_txn_ignore, &hot_index_filenums);
assert(r == 0);
return r; return r;
} }
......
...@@ -53,8 +53,9 @@ test_main(int argc, const char *argv[]) { ...@@ -53,8 +53,9 @@ test_main(int argc, const char *argv[]) {
r = toku_txn_ignore_contains(txn, f8); assert( r == ENOENT ); r = toku_txn_ignore_contains(txn, f8); assert( r == ENOENT );
r = toku_txn_ignore_contains(txn, f9); CKERR(r); r = toku_txn_ignore_contains(txn, f9); CKERR(r);
assert(txn->ignore_errors->fns_allocated == 8); assert(txn->ignore_errors.fns_allocated == 8);
assert(txn->ignore_errors->filenums.num == 4); assert(txn->ignore_errors.filenums.num == 4);
r = toku_txn_ignore_add(txn, f2); CKERR(r); r = toku_txn_ignore_add(txn, f2); CKERR(r);
r = toku_txn_ignore_add(txn, f3); CKERR(r); r = toku_txn_ignore_add(txn, f3); CKERR(r);
...@@ -62,15 +63,16 @@ test_main(int argc, const char *argv[]) { ...@@ -62,15 +63,16 @@ test_main(int argc, const char *argv[]) {
r = toku_txn_ignore_add(txn, f6); CKERR(r); r = toku_txn_ignore_add(txn, f6); CKERR(r);
r = toku_txn_ignore_add(txn, f8); CKERR(r); r = toku_txn_ignore_add(txn, f8); CKERR(r);
assert(txn->ignore_errors->fns_allocated == 16); TXN_IGNORE txni = &(txn->ignore_errors); // test using code similar to that in txn.c
assert(txn->ignore_errors->filenums.num == 9); assert(txni->fns_allocated == 16);
assert(txni->filenums.num == 9);
// check that dups are ignored // check that dups are ignored
for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
r = toku_txn_ignore_add(txn, f2); CKERR(r); r = toku_txn_ignore_add(txn, f2); CKERR(r);
} }
assert(txn->ignore_errors->fns_allocated == 16); assert(txn->ignore_errors.fns_allocated == 16);
assert(txn->ignore_errors->filenums.num == 9); assert(txn->ignore_errors.filenums.num == 9);
toku_txn_ignore_free(txn); toku_txn_ignore_free(txn);
......
...@@ -593,24 +593,21 @@ verify_snapshot_system(TOKULOGGER logger) { ...@@ -593,24 +593,21 @@ verify_snapshot_system(TOKULOGGER logger) {
int toku_txn_ignore_init(TOKUTXN txn) int toku_txn_ignore_init(TOKUTXN txn)
{ {
if ( !txn ) return EINVAL; if ( !txn ) return EINVAL;
TXN_IGNORE txni = toku_malloc(sizeof(TXN_IGNORE_S)); TXN_IGNORE txni = &(txn->ignore_errors);
if ( txni == NULL ) return ENOMEM;
txni->fns_allocated = 0; txni->fns_allocated = 0;
txni->filenums.num = 0; txni->filenums.num = 0;
txni->filenums.filenums = NULL; txni->filenums.filenums = NULL;
txn->ignore_errors = txni;
return 0; return 0;
} }
void toku_txn_ignore_free(TOKUTXN txn) void toku_txn_ignore_free(TOKUTXN txn)
{ {
TXN_IGNORE txni = txn->ignore_errors; TXN_IGNORE txni = &(txn->ignore_errors);
toku_free(txni->filenums.filenums); toku_free(txni->filenums.filenums);
toku_free(txni); txni->filenums.num = 0;
txni = NULL; txni->filenums.filenums = NULL;
} }
// returns // returns
...@@ -625,7 +622,7 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum) ...@@ -625,7 +622,7 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum)
if ( toku_txn_ignore_contains(txn, filenum) == 0 ) return 0; if ( toku_txn_ignore_contains(txn, filenum) == 0 ) return 0;
// alloc more space if needed // alloc more space if needed
const int N = 2; const int N = 2;
TXN_IGNORE txni = txn->ignore_errors; TXN_IGNORE txni = &(txn->ignore_errors);
if ( txni->filenums.num == txni->fns_allocated ) { if ( txni->filenums.num == txni->fns_allocated ) {
if ( txni->fns_allocated == 0 ) { if ( txni->fns_allocated == 0 ) {
CALLOC_N(N, txni->filenums.filenums); CALLOC_N(N, txni->filenums.filenums);
...@@ -634,7 +631,6 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum) ...@@ -634,7 +631,6 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum)
} }
else { else {
XREALLOC_N(txni->fns_allocated * N, txni->filenums.filenums); XREALLOC_N(txni->fns_allocated * N, txni->filenums.filenums);
if ( txni->filenums.filenums == NULL ) return ENOMEM;
txni->fns_allocated = txni->fns_allocated * N; txni->fns_allocated = txni->fns_allocated * N;
} }
} }
...@@ -649,10 +645,11 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum) ...@@ -649,10 +645,11 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum)
// ENOENT if not found // ENOENT if not found
// EINVAL if txn = NULL // EINVAL if txn = NULL
// -1 on other errors // -1 on other errors
// THIS FUNCTION IS NOT USED IN FUNCTIONAL CODE, BUT IS USEFUL FOR TESTING
int toku_txn_ignore_remove(TOKUTXN txn, FILENUM filenum) int toku_txn_ignore_remove(TOKUTXN txn, FILENUM filenum)
{ {
if ( !txn ) return EINVAL; if ( !txn ) return EINVAL;
TXN_IGNORE txni = txn->ignore_errors; TXN_IGNORE txni = &(txn->ignore_errors);
int found_fn = 0; int found_fn = 0;
if ( txni->filenums.num == 0 ) return ENOENT; if ( txni->filenums.num == 0 ) return ENOENT;
for(uint32_t i=0; i<txni->filenums.num; i++) { for(uint32_t i=0; i<txni->filenums.num; i++) {
...@@ -678,7 +675,7 @@ int toku_txn_ignore_remove(TOKUTXN txn, FILENUM filenum) ...@@ -678,7 +675,7 @@ int toku_txn_ignore_remove(TOKUTXN txn, FILENUM filenum)
int toku_txn_ignore_contains(TOKUTXN txn, FILENUM filenum) int toku_txn_ignore_contains(TOKUTXN txn, FILENUM filenum)
{ {
if ( !txn ) return EINVAL; if ( !txn ) return EINVAL;
TXN_IGNORE txni = txn->ignore_errors; TXN_IGNORE txni = &(txn->ignore_errors);
for(uint32_t i=0; i<txni->filenums.num; i++) { for(uint32_t i=0; i<txni->filenums.num; i++) {
if ( txni->filenums.filenums[i].fileid == filenum.fileid ) { if ( txni->filenums.filenums[i].fileid == filenum.fileid ) {
return 0; return 0;
......
...@@ -202,6 +202,7 @@ static inline void wbuf_FILENUM (struct wbuf *w, FILENUM fileid) { ...@@ -202,6 +202,7 @@ static inline void wbuf_FILENUM (struct wbuf *w, FILENUM fileid) {
wbuf_uint(w, fileid.fileid); wbuf_uint(w, fileid.fileid);
} }
// 2954
static inline void wbuf_nocrc_FILENUMS (struct wbuf *w, FILENUMS v) { static inline void wbuf_nocrc_FILENUMS (struct wbuf *w, FILENUMS v) {
wbuf_nocrc_uint(w, v.num); wbuf_nocrc_uint(w, v.num);
uint32_t i; uint32_t i;
...@@ -210,6 +211,7 @@ static inline void wbuf_nocrc_FILENUMS (struct wbuf *w, FILENUMS v) { ...@@ -210,6 +211,7 @@ static inline void wbuf_nocrc_FILENUMS (struct wbuf *w, FILENUMS v) {
} }
} }
// 2954
static inline void wbuf_FILENUMS (struct wbuf *w, FILENUMS v) { static inline void wbuf_FILENUMS (struct wbuf *w, FILENUMS v) {
wbuf_uint(w, v.num); wbuf_uint(w, v.num);
uint32_t i; uint32_t i;
......
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