Commit bea9b8af authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#3043 merge changes from code review to main refs[t:3043]

git-svn-id: file:///svn/toku/tokudb@25904 c7de825b-a66e-492c-adef-691d508d4ae1
parent 076ee90f
...@@ -1672,37 +1672,37 @@ ule_add_placeholders(ULE ule, XIDS xids) { ...@@ -1672,37 +1672,37 @@ ule_add_placeholders(ULE ule, XIDS xids) {
} }
} }
int uint64_t
ule_num_uxrs(ULE ule) { ule_num_uxrs(ULE ule) {
return ule->num_cuxrs + ule->num_puxrs; return ule->num_cuxrs + ule->num_puxrs;
} }
UXR UXR
ule_get_uxr(ULE ule, int ith) { ule_get_uxr(ULE ule, uint64_t ith) {
invariant(0 <= ith && ith < ule_num_uxrs(ule)); invariant(ith < ule_num_uxrs(ule));
return &ule->uxrs[ith]; return &ule->uxrs[ith];
} }
int uint32_t
ule_get_num_committed(ULE ule) { ule_get_num_committed(ULE ule) {
return ule->num_cuxrs; return ule->num_cuxrs;
} }
int uint32_t
ule_get_num_provisional(ULE ule) { ule_get_num_provisional(ULE ule) {
return ule->num_puxrs; return ule->num_puxrs;
} }
int int
ule_is_committed(ULE ule, int ith) { ule_is_committed(ULE ule, uint64_t ith) {
invariant(0 <= ith && ith < ule_num_uxrs(ule)); invariant(ith < ule_num_uxrs(ule));
return ith < (int) ule->num_cuxrs; return ith < ule->num_cuxrs;
} }
int int
ule_is_provisional(ULE ule, int ith) { ule_is_provisional(ULE ule, uint64_t ith) {
invariant(0 <= ith && ith < ule_num_uxrs(ule)); invariant(ith < ule_num_uxrs(ule));
return ith >= (int) ule->num_cuxrs; return ith >= ule->num_cuxrs;
} }
void * void *
......
...@@ -24,12 +24,12 @@ ULEHANDLE toku_ule_create(void * le_p); ...@@ -24,12 +24,12 @@ ULEHANDLE toku_ule_create(void * le_p);
void toku_ule_free(ULEHANDLE ule_p); void toku_ule_free(ULEHANDLE ule_p);
int ule_num_uxrs(ULEHANDLE ule); uint64_t ule_num_uxrs(ULEHANDLE ule);
int ule_get_num_committed(ULEHANDLE ule); uint32_t ule_get_num_committed(ULEHANDLE ule);
int ule_get_num_provisional(ULEHANDLE ule); uint32_t ule_get_num_provisional(ULEHANDLE ule);
UXRHANDLE ule_get_uxr(ULEHANDLE ule, int ith); UXRHANDLE ule_get_uxr(ULEHANDLE ule, uint64_t ith);
int ule_is_committed(ULEHANDLE ule, int ith); int ule_is_committed(ULEHANDLE ule, uint64_t ith);
int ule_is_provisional(ULEHANDLE ule, int ith); int ule_is_provisional(ULEHANDLE ule, uint64_t ith);
void *ule_get_key(ULEHANDLE ule); void *ule_get_key(ULEHANDLE ule);
uint32_t ule_get_keylen(ULEHANDLE ule); uint32_t ule_get_keylen(ULEHANDLE ule);
......
...@@ -53,12 +53,13 @@ indexer_commit_keys_add(struct indexer_commit_keys *keys, size_t length, void *p ...@@ -53,12 +53,13 @@ indexer_commit_keys_add(struct indexer_commit_keys *keys, size_t length, void *p
int new_max_keys = keys->max_keys == 0 ? 8 : keys->max_keys * 2; int new_max_keys = keys->max_keys == 0 ? 8 : keys->max_keys * 2;
keys->keys = (DBT *) toku_realloc(keys->keys, new_max_keys * sizeof (DBT)); keys->keys = (DBT *) toku_realloc(keys->keys, new_max_keys * sizeof (DBT));
resource_assert(keys->keys); resource_assert(keys->keys);
for (int i = keys->current_keys; i < new_max_keys; i++) for (int i = keys->current_keys; i < new_max_keys; i++) {
toku_init_dbt(&keys->keys[i]); toku_init_dbt(&keys->keys[i]);
keys->keys[i].flags = DB_DBT_REALLOC;
}
keys->max_keys = new_max_keys; keys->max_keys = new_max_keys;
} }
DBT *key = &keys->keys[keys->current_keys]; DBT *key = &keys->keys[keys->current_keys];
key->flags = DB_DBT_REALLOC;
toku_dbt_set(length, ptr, key, NULL); toku_dbt_set(length, ptr, key, NULL);
keys->current_keys++; keys->current_keys++;
} }
...@@ -70,11 +71,10 @@ indexer_commit_keys_set_empty(struct indexer_commit_keys *keys) { ...@@ -70,11 +71,10 @@ indexer_commit_keys_set_empty(struct indexer_commit_keys *keys) {
} }
// internal functions // internal functions
static int indexer_setup_xids_committed(DB_INDEXER *indexer, TXNID xid, XIDS *xids_result); static int indexer_set_xid(DB_INDEXER *indexer, TXNID xid, XIDS *xids_result);
static int indexer_setup_xids_provisional(DB_INDEXER *indexer, ULEHANDLE ule, int trindex, TXNID xid, BOOL xid_is_live, XIDS *xids_result); static int indexer_append_xid(DB_INDEXER *indexer, TXNID xid, BOOL xid_is_live, XIDS *xids_result);
static int indexer_find_prev_committed(DB_INDEXER *indexer, ULEHANDLE ule, int i); static BOOL indexer_find_prev_xr(DB_INDEXER *indexer, ULEHANDLE ule, uint64_t xrindex, uint64_t *prev_xrindex);
static int indexer_find_prev_provisional(DB_INDEXER *indexer, ULEHANDLE ule, int i);
static int indexer_generate_hot_key_val(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule, UXRHANDLE uxr, DBT *hotkey, DBT *hotval); static int indexer_generate_hot_key_val(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule, UXRHANDLE uxr, DBT *hotkey, DBT *hotval);
static int indexer_brt_delete_provisional(DB_INDEXER *indexer, DB *hotdb, DBT *hotkey, XIDS xids); static int indexer_brt_delete_provisional(DB_INDEXER *indexer, DB *hotdb, DBT *hotkey, XIDS xids);
...@@ -96,9 +96,9 @@ indexer_undo_do_init(DB_INDEXER *indexer) { ...@@ -96,9 +96,9 @@ indexer_undo_do_init(DB_INDEXER *indexer) {
// destroy the undo globals // destroy the undo globals
void void
indexer_undo_do_destroy(DB_INDEXER *indexer) { indexer_undo_do_destroy(DB_INDEXER *indexer) {
indexer_commit_keys_destroy(&indexer->i->commit_keys);
toku_destroy_dbt(&indexer->i->hotkey); toku_destroy_dbt(&indexer->i->hotkey);
toku_destroy_dbt(&indexer->i->hotval); toku_destroy_dbt(&indexer->i->hotval);
indexer_commit_keys_destroy(&indexer->i->commit_keys);
} }
static int static int
...@@ -109,36 +109,33 @@ indexer_undo_do_committed(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) { ...@@ -109,36 +109,33 @@ indexer_undo_do_committed(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) {
XIDS xids = xids_get_root_xids(); XIDS xids = xids_get_root_xids();
// scan the committed stack from bottom to top // scan the committed stack from bottom to top
int num_committed = ule_get_num_committed(ule); uint32_t num_committed = ule_get_num_committed(ule);
for (int trindex = 0; trindex < num_committed; trindex++) { for (uint64_t xrindex = 0; xrindex < num_committed; xrindex++) {
indexer_commit_keys_set_empty(&indexer->i->commit_keys); indexer_commit_keys_set_empty(&indexer->i->commit_keys);
// get the transaction record // get the transaction record
UXRHANDLE uxr = ule_get_uxr(ule, trindex); UXRHANDLE uxr = ule_get_uxr(ule, xrindex);
invariant(uxr);
// setup up the xids // setup up the xids
TXNID this_xid = uxr_get_txnid(uxr); TXNID this_xid = uxr_get_txnid(uxr);
result = indexer_setup_xids_committed(indexer, this_xid, &xids); result = indexer_set_xid(indexer, this_xid, &xids);
if (result != 0) if (result != 0)
break; break;
// skip placeholders // placeholders in the committed stack are not allowed
if (uxr_is_placeholder(uxr)) { if (uxr_is_placeholder(uxr))
invariant(0); // not allowed invariant(0);
continue;
}
// undo // undo
int prev_trindex = indexer_find_prev_committed(indexer, ule, trindex); if (xrindex > 0) {
if (prev_trindex >= 0) { uint64_t prev_xrindex = xrindex - 1;
UXRHANDLE prevuxr = ule_get_uxr(ule, prev_trindex); UXRHANDLE prevuxr = ule_get_uxr(ule, prev_xrindex);
if (uxr_is_delete(prevuxr)) { if (uxr_is_delete(prevuxr)) {
; // do nothing ; // do nothing
} else if (uxr_is_insert(prevuxr)) { } else if (uxr_is_insert(prevuxr)) {
// generate the hot key and val // generate the hot delete key
result = indexer_generate_hot_key_val(indexer, hotdb, ule, prevuxr, &indexer->i->hotkey, &indexer->i->hotval); result = indexer_generate_hot_key_val(indexer, hotdb, ule, prevuxr, &indexer->i->hotkey, NULL);
if (result == 0) { if (result == 0) {
// send the delete message // send the delete message
result = indexer_brt_delete_committed(indexer, hotdb, &indexer->i->hotkey, xids); result = indexer_brt_delete_committed(indexer, hotdb, &indexer->i->hotkey, xids);
...@@ -155,15 +152,14 @@ indexer_undo_do_committed(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) { ...@@ -155,15 +152,14 @@ indexer_undo_do_committed(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) {
if (uxr_is_delete(uxr)) { if (uxr_is_delete(uxr)) {
; // do nothing ; // do nothing
} else if (uxr_is_insert(uxr)) { } else if (uxr_is_insert(uxr)) {
// generate the hot key and val // generate the hot insert key and val
result = indexer_generate_hot_key_val(indexer, hotdb, ule, uxr, &indexer->i->hotkey, &indexer->i->hotval); result = indexer_generate_hot_key_val(indexer, hotdb, ule, uxr, &indexer->i->hotkey, &indexer->i->hotval);
if (result == 0) { if (result == 0) {
// send the insert message // send the insert message
result = indexer_brt_insert_committed(indexer, hotdb, &indexer->i->hotkey, &indexer->i->hotval, xids); result = indexer_brt_insert_committed(indexer, hotdb, &indexer->i->hotkey, &indexer->i->hotval, xids);
if (result == 0) { if (result == 0)
indexer_commit_keys_add(&indexer->i->commit_keys, indexer->i->hotkey.size, indexer->i->hotkey.data); indexer_commit_keys_add(&indexer->i->commit_keys, indexer->i->hotkey.size, indexer->i->hotkey.data);
} }
}
} else } else
invariant(0); invariant(0);
...@@ -193,23 +189,22 @@ indexer_undo_do_provisional(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) { ...@@ -193,23 +189,22 @@ indexer_undo_do_provisional(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) {
BOOL outermost_is_live = FALSE; BOOL outermost_is_live = FALSE;
// scan the provisional stack from bottom to top // scan the provisional stack from bottom to top
int num_committed = ule_get_num_committed(ule); uint32_t num_committed = ule_get_num_committed(ule);
int num_provisional = ule_get_num_provisional(ule); uint32_t num_provisional = ule_get_num_provisional(ule);
for (int trindex = num_committed; trindex < num_committed + num_provisional; trindex++) { for (uint64_t xrindex = num_committed; xrindex < num_committed + num_provisional; xrindex++) {
// get the ith transaction record // get the ith transaction record
UXRHANDLE uxr = ule_get_uxr(ule, trindex); UXRHANDLE uxr = ule_get_uxr(ule, xrindex);
invariant(uxr);
TXNID this_xid = uxr_get_txnid(uxr); TXNID this_xid = uxr_get_txnid(uxr);
BOOL this_xid_is_live = indexer_is_xid_live(indexer, this_xid); BOOL this_xid_is_live = indexer_is_xid_live(indexer, this_xid);
if (trindex == num_committed) { if (xrindex == num_committed) {
outermost_xid = this_xid; outermost_xid = this_xid;
outermost_is_live = this_xid_is_live; outermost_is_live = this_xid_is_live;
} }
// setup up the xids // setup up the xids
result = indexer_setup_xids_provisional(indexer, ule, trindex, this_xid, this_xid_is_live, &xids); result = indexer_append_xid(indexer, this_xid, this_xid_is_live, &xids);
if (result != 0) if (result != 0)
break; break;
...@@ -218,14 +213,15 @@ indexer_undo_do_provisional(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) { ...@@ -218,14 +213,15 @@ indexer_undo_do_provisional(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) {
continue; continue;
// undo // undo
int prev_trindex = indexer_find_prev_provisional(indexer, ule, trindex); uint64_t prev_xrindex;
if (prev_trindex >= 0) { BOOL prev_xrindex_found = indexer_find_prev_xr(indexer, ule, xrindex, &prev_xrindex);
UXRHANDLE prevuxr = ule_get_uxr(ule, prev_trindex); if (prev_xrindex_found) {
UXRHANDLE prevuxr = ule_get_uxr(ule, prev_xrindex);
if (uxr_is_delete(prevuxr)) { if (uxr_is_delete(prevuxr)) {
; // do nothing ; // do nothing
} else if (uxr_is_insert(prevuxr)) { } else if (uxr_is_insert(prevuxr)) {
// generate the hot key and val // generate the hot delete key
result = indexer_generate_hot_key_val(indexer, hotdb, ule, prevuxr, &indexer->i->hotkey, &indexer->i->hotval); result = indexer_generate_hot_key_val(indexer, hotdb, ule, prevuxr, &indexer->i->hotkey, NULL);
if (result == 0) { if (result == 0) {
// send the delete message // send the delete message
if (!outermost_is_live) { if (!outermost_is_live) {
...@@ -248,7 +244,7 @@ indexer_undo_do_provisional(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) { ...@@ -248,7 +244,7 @@ indexer_undo_do_provisional(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) {
if (uxr_is_delete(uxr)) { if (uxr_is_delete(uxr)) {
; // do nothing ; // do nothing
} else if (uxr_is_insert(uxr)) { } else if (uxr_is_insert(uxr)) {
// generate the hot key and val // generate the hot insert key and val
result = indexer_generate_hot_key_val(indexer, hotdb, ule, uxr, &indexer->i->hotkey, &indexer->i->hotval); result = indexer_generate_hot_key_val(indexer, hotdb, ule, uxr, &indexer->i->hotkey, &indexer->i->hotval);
if (result == 0) { if (result == 0) {
// send the insert message // send the insert message
...@@ -281,12 +277,9 @@ indexer_undo_do_provisional(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) { ...@@ -281,12 +277,9 @@ indexer_undo_do_provisional(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) {
return result; return result;
} }
int int
indexer_undo_do(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) { indexer_undo_do(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) {
int result; int result = indexer_undo_do_committed(indexer, hotdb, ule);
result = indexer_undo_do_committed(indexer, hotdb, ule);
if (result == 0) if (result == 0)
result = indexer_undo_do_provisional(indexer, hotdb, ule); result = indexer_undo_do_provisional(indexer, hotdb, ule);
...@@ -298,11 +291,11 @@ indexer_undo_do(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) { ...@@ -298,11 +291,11 @@ indexer_undo_do(DB_INDEXER *indexer, DB *hotdb, ULEHANDLE ule) {
// the committed XIDS always = [this_xid] // the committed XIDS always = [this_xid]
static int static int
indexer_setup_xids_committed(DB_INDEXER *UU(indexer), TXNID this_xid, XIDS *xids_result) { indexer_set_xid(DB_INDEXER *UU(indexer), TXNID this_xid, XIDS *xids_result) {
int result = 0; int result = 0;
XIDS old_xids = *xids_result; XIDS old_xids = *xids_result;
XIDS new_xids = xids_get_root_xids(); XIDS new_xids = xids_get_root_xids();
if (this_xid > 0) { if (this_xid != TXNID_NONE) {
XIDS child_xids; XIDS child_xids;
result = xids_create_child(new_xids, &child_xids, this_xid); result = xids_create_child(new_xids, &child_xids, this_xid);
xids_destroy(&new_xids); xids_destroy(&new_xids);
...@@ -319,8 +312,7 @@ indexer_setup_xids_committed(DB_INDEXER *UU(indexer), TXNID this_xid, XIDS *xids ...@@ -319,8 +312,7 @@ indexer_setup_xids_committed(DB_INDEXER *UU(indexer), TXNID this_xid, XIDS *xids
// the provisional XIDS = XIDS . [this_xid] when this_xid is live or when XIDS is empty // the provisional XIDS = XIDS . [this_xid] when this_xid is live or when XIDS is empty
static int static int
indexer_setup_xids_provisional(DB_INDEXER *UU(indexer), ULEHANDLE ule, int trindex, TXNID xid, BOOL xid_is_live, XIDS *xids_result) { indexer_append_xid(DB_INDEXER *UU(indexer), TXNID xid, BOOL xid_is_live, XIDS *xids_result) {
invariant(trindex >= ule_get_num_committed(ule));
int result = 0; int result = 0;
XIDS old_xids = *xids_result; XIDS old_xids = *xids_result;
XIDS new_xids; XIDS new_xids;
...@@ -406,35 +398,30 @@ indexer_lock_key(DB_INDEXER *indexer, DB *hotdb, DBT *key, TXNID outermost_live_ ...@@ -406,35 +398,30 @@ indexer_lock_key(DB_INDEXER *indexer, DB *hotdb, DBT *key, TXNID outermost_live_
return result; return result;
} }
static int static BOOL
indexer_find_prev_committed(DB_INDEXER *UU(indexer), ULEHANDLE ule, int i) { indexer_find_prev_xr(DB_INDEXER *UU(indexer), ULEHANDLE ule, uint64_t xrindex, uint64_t *prev_xrindex) {
invariant(i < ule_num_uxrs(ule)); invariant(xrindex < ule_num_uxrs(ule));
int previ = i - 1; BOOL prev_found = FALSE;
return previ; while (xrindex > 0) {
} xrindex -= 1;
UXRHANDLE uxr = ule_get_uxr(ule, xrindex);
static int if (!uxr_is_placeholder(uxr)) {
indexer_find_prev_provisional(DB_INDEXER *UU(indexer), ULEHANDLE ule, int i) { *prev_xrindex = xrindex;
invariant(i < ule_num_uxrs(ule)); prev_found = TRUE;
int previ = i - 1;
while (previ >= 0) {
UXRHANDLE uxr = ule_get_uxr(ule, previ);
if (!uxr_is_placeholder(uxr))
break; break;
previ -= 1;
} }
return previ; }
return prev_found;
} }
static TOKUTXN static TOKUTXN
indexer_get_innermost_live_txn(DB_INDEXER *indexer, XIDS xids) { indexer_get_innermost_live_txn(DB_INDEXER *indexer, XIDS xids) {
DB_ENV *env = indexer->i->env; DB_ENV *env = indexer->i->env;
TOKUTXN txn = NULL; uint8_t num_xids = xids_get_num_xids(xids);
for (uint8_t num_xids = xids_get_num_xids(xids); txn == NULL && num_xids > 0; num_xids--) {
TXNID xid = xids_get_xid(xids, num_xids-1); TXNID xid = xids_get_xid(xids, num_xids-1);
TOKUTXN txn = NULL;
int result = toku_txnid2txn(env->i->logger, xid, &txn); int result = toku_txnid2txn(env->i->logger, xid, &txn);
invariant(result == 0); invariant(result == 0);
}
return txn; return txn;
} }
......
...@@ -168,6 +168,7 @@ put_callback(DB *dest_db, DB *src_db, DBT *dest_key, DBT *dest_data, const DBT * ...@@ -168,6 +168,7 @@ put_callback(DB *dest_db, DB *src_db, DBT *dest_key, DBT *dest_data, const DBT *
lazy_assert(0); lazy_assert(0);
} }
if (dest_data)
switch (dest_data->flags) { switch (dest_data->flags) {
case 0: case 0:
lazy_assert(0); lazy_assert(0);
......
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