Commit 4c62025d authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Improvements to rollback. Addresses #27.

git-svn-id: file:///svn/tokudb@2434 c7de825b-a66e-492c-adef-691d508d4ae1
parent 62a40e87
...@@ -1715,12 +1715,6 @@ int toku_brt_insert (BRT brt, DBT *key, DBT *val, TOKUTXN txn) { ...@@ -1715,12 +1715,6 @@ int toku_brt_insert (BRT brt, DBT *key, DBT *val, TOKUTXN txn) {
int r; int r;
BRT_CMD_S brtcmd = { BRT_INSERT, toku_txn_get_txnid(txn), .u.id={key,val}}; BRT_CMD_S brtcmd = { BRT_INSERT, toku_txn_get_txnid(txn), .u.id={key,val}};
{
const BYTESTRING insertedkey = { key->size, toku_memdup(key->data, key->size) };
const BYTESTRING inserteddata = { val->size, toku_memdup(val->data, val->size) };
r = toku_logger_save_rollback_insert(txn, toku_cachefile_filenum(brt->cf), insertedkey, inserteddata);
if (r!=0) return r;
}
r = brt_root_put_cmd(brt, &brtcmd, toku_txn_logger(txn)); r = brt_root_put_cmd(brt, &brtcmd, toku_txn_logger(txn));
return r; return r;
} }
...@@ -1745,11 +1739,6 @@ int toku_brt_delete(BRT brt, DBT *key, TOKUTXN txn) { ...@@ -1745,11 +1739,6 @@ int toku_brt_delete(BRT brt, DBT *key, TOKUTXN txn) {
DBT val; DBT val;
printf("removing\n"); printf("removing\n");
BRT_CMD_S brtcmd = { BRT_DELETE, toku_txn_get_txnid(txn), .u.id={key, toku_init_dbt(&val)}}; BRT_CMD_S brtcmd = { BRT_DELETE, toku_txn_get_txnid(txn), .u.id={key, toku_init_dbt(&val)}};
{
const BYTESTRING deletedkey = { key->size, toku_memdup(key->data, key->size) };
r = toku_logger_save_rollback_delete(txn, toku_cachefile_filenum(brt->cf), deletedkey);
if (r!=0) return r;
}
r = brt_root_put_cmd(brt, &brtcmd, toku_txn_logger(txn)); r = brt_root_put_cmd(brt, &brtcmd, toku_txn_logger(txn));
return r; return r;
} }
......
...@@ -41,14 +41,11 @@ int logformat_version_number = 0; ...@@ -41,14 +41,11 @@ int logformat_version_number = 0;
const struct logtype rollbacks[] = { const struct logtype rollbacks[] = {
{"fcreate", 'F', FA{{"BYTESTRING", "fname", 0}, {"fcreate", 'F', FA{{"BYTESTRING", "fname", 0},
NULLFIELD}}, NULLFIELD}},
{"delete", 'd', FA{{"FILENUM", "filenum", 0}, // Note a delete for rollback. {"deleteatleaf", 'd', FA{{"FILENUM", "filenum", 0}, // Note a delete for rollback. The delete takes place in a leaf.
{"BYTESTRING", "key", 0},
NULLFIELD}},
{"deleteboth", 'D', FA{{"FILENUM", "filenum", 0}, // Note a delete for rollback.
{"BYTESTRING", "key", 0}, {"BYTESTRING", "key", 0},
{"BYTESTRING", "data", 0}, {"BYTESTRING", "data", 0},
NULLFIELD}}, NULLFIELD}},
{"insert", 'i', FA{{"FILENUM", "filenum", 0}, // Note a delete for rollback. {"insertatleaf", 'i', FA{{"FILENUM", "filenum", 0}, // Note an insert for rollback. The insert takes place in a leaf.
{"BYTESTRING", "key", 0}, {"BYTESTRING", "key", 0},
{"BYTESTRING", "data", 0}, {"BYTESTRING", "data", 0},
NULLFIELD}}, NULLFIELD}},
......
...@@ -716,18 +716,27 @@ int toku_pma_insert (PMA pma, DBT *k, DBT *v, TOKULOGGER logger, TXNID xid, FILE ...@@ -716,18 +716,27 @@ int toku_pma_insert (PMA pma, DBT *k, DBT *v, TOKULOGGER logger, TXNID xid, FILE
pma->n_pairs_present++; pma->n_pairs_present++;
*fingerprint += rand4fingerprint*toku_calccrc32_kvpair(k->data, k->size, v->data, v->size); *fingerprint += rand4fingerprint*toku_calccrc32_kvpair(k->data, k->size, v->data, v->size);
const struct kv_pair *pair = pma->pairs[idx]; struct kv_pair *pair = pma->pairs[idx];
{
TOKUTXN txn;
int r;
if ((r=toku_txnid2txn(logger, xid, &txn))) return r;
const BYTESTRING key = { pair->keylen, toku_memdup(kv_pair_key_const(pair), pair->keylen) }; const BYTESTRING key = { pair->keylen, toku_memdup(kv_pair_key_const(pair), pair->keylen) };
const BYTESTRING data = { pair->vallen, toku_memdup(kv_pair_val_const(pair), pair->vallen) }; const BYTESTRING data = { pair->vallen, toku_memdup(kv_pair_val_const(pair), pair->vallen) };
TOKUTXN txn; if ((r = toku_logger_save_rollback_insertatleaf(txn, pma->filenum, key, data))) {
toku_free(key.data); toku_free(data.data);
return r;
}
}
{
const BYTESTRING key = { pair->keylen, kv_pair_key(pair) };
const BYTESTRING data = { pair->vallen, kv_pair_val(pair) };
int r = toku_log_insertinleaf (logger, xid, pma->filenum, diskoff, idx, key, data); int r = toku_log_insertinleaf (logger, xid, pma->filenum, diskoff, idx, key, data);
if (r!=0) return r;
if (logger && node_lsn) *node_lsn = toku_logger_last_lsn(logger); if (logger && node_lsn) *node_lsn = toku_logger_last_lsn(logger);
if (r!=0) goto freeit; }
if (0!=toku_txnid2txn(logger, xid, &txn)) goto freeit;
/* Don't save rollback info, instead we'll reinsert the command at the root, if the insert fails. */ return 0;
if (0) { freeit: toku_free(key.data); toku_free(data.data); }
return r;
} }
static int pma_delete_dup (PMA pma, DBT *k, DBT *v, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) { static int pma_delete_dup (PMA pma, DBT *k, DBT *v, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
...@@ -866,15 +875,12 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v, ...@@ -866,15 +875,12 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
if (r!=0) return r; if (r!=0) return r;
} }
if (logger) { if (logger) {
const BYTESTRING deletedkey = { kv->keylen, toku_memdup(kv_pair_key(kv), kv->keylen) };
const BYTESTRING deleteddata = { kv->vallen, toku_memdup(kv_pair_val(kv), kv->vallen) };
TOKUTXN txn; TOKUTXN txn;
if (0!=toku_txnid2txn(logger, xid, &txn)) return -1; if (0!=toku_txnid2txn(logger, xid, &txn)) return -1;
r=toku_logger_save_rollback_deleteboth(txn, pma->filenum, deletedkey, deleteddata); const BYTESTRING deletedkey = { kv->keylen, toku_memdup(kv_pair_key(kv), kv->keylen) };
if (r!=0) { const BYTESTRING deleteddata = { kv->vallen, toku_memdup(kv_pair_val(kv), kv->vallen) };
toku_free(deletedkey.data); r=toku_logger_save_rollback_deleteatleaf(txn, pma->filenum, deletedkey, deleteddata);
toku_free(deleteddata.data); if (r!=0) { toku_free(deletedkey.data); toku_free(deleteddata.data); return r;
return r;
} }
} }
} }
...@@ -904,9 +910,18 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v, ...@@ -904,9 +910,18 @@ int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
//printf("%s:%d txn=%p\n", __FILE__, __LINE__, txn); //printf("%s:%d txn=%p\n", __FILE__, __LINE__, txn);
logit_and_update_fingerprint: logit_and_update_fingerprint:
{ {
struct kv_pair *pair = pma->pairs[idx]; TOKUTXN txn;
BYTESTRING key = { pair->keylen, kv_pair_key(pair) }; if ((r=toku_txnid2txn(logger, xid, &txn))) return r;
BYTESTRING data = { pair->vallen, kv_pair_val(pair) }; const BYTESTRING key = { k->size, toku_memdup(k->data, k->size) };
const BYTESTRING data = { v->size, toku_memdup(v->data, v->size) };
if ((r = toku_logger_save_rollback_insertatleaf(txn, pma->filenum, key, data))) {
toku_free(key.data); toku_free(data.data);
return r;
}
}
{
const BYTESTRING key = { k->size, k->data };
const BYTESTRING data = { v->size, k->data };
r = toku_log_insertinleaf (logger, xid, pma->filenum, diskoff, idx, key, data); r = toku_log_insertinleaf (logger, xid, pma->filenum, diskoff, idx, key, data);
if (logger && node_lsn) *node_lsn = toku_logger_last_lsn(logger); if (logger && node_lsn) *node_lsn = toku_logger_last_lsn(logger);
if (r!=0) return r; if (r!=0) return r;
......
...@@ -411,8 +411,7 @@ void toku_recover_deleteinleaf (LSN lsn, TXNID UU(txnid), FILENUM filenum, DISKO ...@@ -411,8 +411,7 @@ void toku_recover_deleteinleaf (LSN lsn, TXNID UU(txnid), FILENUM filenum, DISKO
toku_free_BYTESTRING(databs); toku_free_BYTESTRING(databs);
} }
int toku_rollback_deleteboth (FILENUM filenum, int toku_rollback_deleteatleaf (FILENUM filenum, BYTESTRING key, BYTESTRING data,TOKUTXN txn) {
BYTESTRING key,BYTESTRING data,TOKUTXN txn) {
CACHEFILE cf; CACHEFILE cf;
BRT brt; BRT brt;
int r = toku_cachefile_of_filenum(txn->logger->ct, filenum, &cf, &brt); int r = toku_cachefile_of_filenum(txn->logger->ct, filenum, &cf, &brt);
...@@ -425,22 +424,7 @@ int toku_rollback_deleteboth (FILENUM filenum, ...@@ -425,22 +424,7 @@ int toku_rollback_deleteboth (FILENUM filenum,
return r; return r;
} }
int toku_rollback_delete (FILENUM filenum, int toku_rollback_insertatleaf (FILENUM filenum, BYTESTRING key,BYTESTRING data, TOKUTXN txn) {
BYTESTRING key,BYTESTRING data,TOKUTXN txn) {
CACHEFILE cf;
BRT brt;
int r = toku_cachefile_of_filenum(txn->logger->ct, filenum, &cf, &brt);
assert(r==0);
DBT key_dbt,data_dbt;
r = toku_brt_insert(brt,
toku_fill_dbt(&key_dbt, key.data, key.len),
toku_fill_dbt(&data_dbt, data.data, data.len),
txn);
return r;
}
int toku_rollback_insert (FILENUM filenum,
BYTESTRING key,BYTESTRING data,TOKUTXN txn) {
CACHEFILE cf; CACHEFILE cf;
BRT brt; BRT brt;
int r = toku_cachefile_of_filenum(txn->logger->ct, filenum, &cf, &brt); int r = toku_cachefile_of_filenum(txn->logger->ct, filenum, &cf, &brt);
......
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