Commit 7bd111d8 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 4495b77a
......@@ -152,7 +152,7 @@ struct tokutxn {
BOOL recovered_from_checkpoint;
ROLLBACK_LOG_NODE pinned_inprogress_rollback_log;
struct toku_list checkpoint_before_commit;
TXN_IGNORE ignore_errors; // 2954
TXN_IGNORE_S ignore_errors; // 2954
};
struct txninfo {
......
......@@ -133,22 +133,23 @@ static inline void rbuf_ma_FILENUM (struct rbuf *r, MEMARENA ma __attribute__((_
// 2954
// 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);
u_int32_t newndone = r->ndone + ( filenums->num * sizeof(FILENUM) );
assert(newndone <= r->size);
filenums->filenums = (FILENUM *) toku_memdup(&r->buf[r->ndone], (size_t)filenums->num * sizeof(FILENUM));
assert(filenums->filenums);
r->ndone = newndone;
filenums->filenums = toku_malloc( filenums->num * sizeof(FILENUM) );
assert(filenums->filenums != NULL);
for (u_int32_t i=0; i < filenums->num; i++) {
rbuf_FILENUM(r, &(filenums->filenums[i]));
}
}
// 2954
static inline void rbuf_ma_FILENUMS (struct rbuf *r, MEMARENA ma __attribute__((__unused__)), FILENUMS *filenums) {
filenums->num = rbuf_int(r);
u_int32_t newndone = r->ndone + ( filenums->num * sizeof(FILENUM) );
assert(newndone <= r->size);
filenums->filenums = (FILENUM *) memarena_memdup(ma, &r->buf[r->ndone], (size_t)filenums->num * sizeof(FILENUM));
assert(filenums->filenums);
r->ndone = newndone;
rbuf_ma_u_int32_t(r, ma, &(filenums->num));
filenums->filenums = malloc_in_memarena(ma, filenums->num * sizeof(FILENUM) );
assert(filenums->filenums != NULL);
for (u_int32_t i=0; i < filenums->num; i++) {
rbuf_ma_FILENUM(r, ma, &(filenums->filenums[i]));
}
}
// 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) {
int r;
for (uint32_t i=0; i<hot_index_filenums->num;i++) {
r = toku_txn_ignore_add(txn, hot_index_filenums->filenums[i]);
if ( r != 0 ) return r;
invariant(r==0);
}
return 0;
}
......@@ -416,7 +416,6 @@ toku_rollback_hot_index (FILENUMS UU(hot_index_filenums),
LSN UU(oplsn))
{
int r = toku_omt_iterate(txn->logger->live_txns, live_txn_ignore, &hot_index_filenums);
assert(r == 0);
return r;
}
......
......@@ -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, f9); CKERR(r);
assert(txn->ignore_errors->fns_allocated == 8);
assert(txn->ignore_errors->filenums.num == 4);
assert(txn->ignore_errors.fns_allocated == 8);
assert(txn->ignore_errors.filenums.num == 4);
r = toku_txn_ignore_add(txn, f2); CKERR(r);
r = toku_txn_ignore_add(txn, f3); CKERR(r);
......@@ -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, f8); CKERR(r);
assert(txn->ignore_errors->fns_allocated == 16);
assert(txn->ignore_errors->filenums.num == 9);
TXN_IGNORE txni = &(txn->ignore_errors); // test using code similar to that in txn.c
assert(txni->fns_allocated == 16);
assert(txni->filenums.num == 9);
// check that dups are ignored
for (int i=0;i<10;i++) {
r = toku_txn_ignore_add(txn, f2); CKERR(r);
}
assert(txn->ignore_errors->fns_allocated == 16);
assert(txn->ignore_errors->filenums.num == 9);
assert(txn->ignore_errors.fns_allocated == 16);
assert(txn->ignore_errors.filenums.num == 9);
toku_txn_ignore_free(txn);
......
......@@ -593,24 +593,21 @@ verify_snapshot_system(TOKULOGGER logger) {
int toku_txn_ignore_init(TOKUTXN txn)
{
if ( !txn ) return EINVAL;
TXN_IGNORE txni = toku_malloc(sizeof(TXN_IGNORE_S));
if ( txni == NULL ) return ENOMEM;
TXN_IGNORE txni = &(txn->ignore_errors);
txni->fns_allocated = 0;
txni->filenums.num = 0;
txni->filenums.filenums = NULL;
txn->ignore_errors = txni;
return 0;
}
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);
txni = NULL;
txni->filenums.num = 0;
txni->filenums.filenums = NULL;
}
// returns
......@@ -625,7 +622,7 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum)
if ( toku_txn_ignore_contains(txn, filenum) == 0 ) return 0;
// alloc more space if needed
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->fns_allocated == 0 ) {
CALLOC_N(N, txni->filenums.filenums);
......@@ -634,7 +631,6 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum)
}
else {
XREALLOC_N(txni->fns_allocated * N, txni->filenums.filenums);
if ( txni->filenums.filenums == NULL ) return ENOMEM;
txni->fns_allocated = txni->fns_allocated * N;
}
}
......@@ -649,10 +645,11 @@ int toku_txn_ignore_add(TOKUTXN txn, FILENUM filenum)
// ENOENT if not found
// EINVAL if txn = NULL
// -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)
{
if ( !txn ) return EINVAL;
TXN_IGNORE txni = txn->ignore_errors;
TXN_IGNORE txni = &(txn->ignore_errors);
int found_fn = 0;
if ( txni->filenums.num == 0 ) return ENOENT;
for(uint32_t i=0; i<txni->filenums.num; i++) {
......@@ -678,7 +675,7 @@ int toku_txn_ignore_remove(TOKUTXN txn, FILENUM filenum)
int toku_txn_ignore_contains(TOKUTXN txn, FILENUM filenum)
{
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++) {
if ( txni->filenums.filenums[i].fileid == filenum.fileid ) {
return 0;
......
......@@ -202,6 +202,7 @@ static inline void wbuf_FILENUM (struct wbuf *w, FILENUM fileid) {
wbuf_uint(w, fileid.fileid);
}
// 2954
static inline void wbuf_nocrc_FILENUMS (struct wbuf *w, FILENUMS v) {
wbuf_nocrc_uint(w, v.num);
uint32_t i;
......@@ -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) {
wbuf_uint(w, v.num);
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