Commit d7cb68be authored by Rich Prohaska's avatar Rich Prohaska

DB-808 add flags to xa prepare to support no sync log

parent 906c8b27
...@@ -572,7 +572,7 @@ static void print_db_txn_struct (void) { ...@@ -572,7 +572,7 @@ static void print_db_txn_struct (void) {
STRUCT_SETUP(DB_TXN, abort, "int (*%s) (DB_TXN *)"); STRUCT_SETUP(DB_TXN, abort, "int (*%s) (DB_TXN *)");
STRUCT_SETUP(DB_TXN, api_internal,"void *%s"); STRUCT_SETUP(DB_TXN, api_internal,"void *%s");
STRUCT_SETUP(DB_TXN, commit, "int (*%s) (DB_TXN*, uint32_t)"); STRUCT_SETUP(DB_TXN, commit, "int (*%s) (DB_TXN*, uint32_t)");
STRUCT_SETUP(DB_TXN, prepare, "int (*%s) (DB_TXN*, uint8_t gid[DB_GID_SIZE])"); STRUCT_SETUP(DB_TXN, prepare, "int (*%s) (DB_TXN*, uint8_t gid[DB_GID_SIZE], uint32_t flags)");
STRUCT_SETUP(DB_TXN, discard, "int (*%s) (DB_TXN*, uint32_t)"); STRUCT_SETUP(DB_TXN, discard, "int (*%s) (DB_TXN*, uint32_t)");
STRUCT_SETUP(DB_TXN, id, "uint32_t (*%s) (DB_TXN *)"); STRUCT_SETUP(DB_TXN, id, "uint32_t (*%s) (DB_TXN *)");
STRUCT_SETUP(DB_TXN, mgrp, "DB_ENV *%s /* In TokuFT, mgrp is a DB_ENV, not a DB_TXNMGR */"); STRUCT_SETUP(DB_TXN, mgrp, "DB_ENV *%s /* In TokuFT, mgrp is a DB_ENV, not a DB_TXNMGR */");
...@@ -581,7 +581,7 @@ static void print_db_txn_struct (void) { ...@@ -581,7 +581,7 @@ static void print_db_txn_struct (void) {
"int (*txn_stat)(DB_TXN *, struct txn_stat **)", "int (*txn_stat)(DB_TXN *, struct txn_stat **)",
"int (*commit_with_progress)(DB_TXN*, uint32_t, TXN_PROGRESS_POLL_FUNCTION, void*)", "int (*commit_with_progress)(DB_TXN*, uint32_t, TXN_PROGRESS_POLL_FUNCTION, void*)",
"int (*abort_with_progress)(DB_TXN*, TXN_PROGRESS_POLL_FUNCTION, void*)", "int (*abort_with_progress)(DB_TXN*, TXN_PROGRESS_POLL_FUNCTION, void*)",
"int (*xa_prepare) (DB_TXN*, TOKU_XA_XID *)", "int (*xa_prepare) (DB_TXN*, TOKU_XA_XID *, uint32_t flags)",
"uint64_t (*id64) (DB_TXN*)", "uint64_t (*id64) (DB_TXN*)",
"void (*set_client_id)(DB_TXN *, uint64_t client_id)", "void (*set_client_id)(DB_TXN *, uint64_t client_id)",
"uint64_t (*get_client_id)(DB_TXN *)", "uint64_t (*get_client_id)(DB_TXN *)",
......
...@@ -712,7 +712,7 @@ static int toku_recover_xstillopenprepared (struct logtype_xstillopenprepared *l ...@@ -712,7 +712,7 @@ static int toku_recover_xstillopenprepared (struct logtype_xstillopenprepared *l
} }
switch (renv->ss.ss) { switch (renv->ss.ss) {
case FORWARD_BETWEEN_CHECKPOINT_BEGIN_END: { case FORWARD_BETWEEN_CHECKPOINT_BEGIN_END: {
toku_txn_prepare_txn(txn, l->xa_xid); toku_txn_prepare_txn(txn, l->xa_xid, 0);
break; break;
} }
case FORWARD_NEWER_CHECKPOINT_END: { case FORWARD_NEWER_CHECKPOINT_END: {
...@@ -776,7 +776,7 @@ static int toku_recover_xprepare (struct logtype_xprepare *l, RECOVER_ENV renv) ...@@ -776,7 +776,7 @@ static int toku_recover_xprepare (struct logtype_xprepare *l, RECOVER_ENV renv)
assert(txn!=NULL); assert(txn!=NULL);
// Save the transaction // Save the transaction
toku_txn_prepare_txn(txn, l->xa_xid); toku_txn_prepare_txn(txn, l->xa_xid, 0);
return 0; return 0;
} }
......
...@@ -556,7 +556,7 @@ static void copy_xid (TOKU_XA_XID *dest, TOKU_XA_XID *source) { ...@@ -556,7 +556,7 @@ static void copy_xid (TOKU_XA_XID *dest, TOKU_XA_XID *source) {
memcpy(dest->data, source->data, source->gtrid_length+source->bqual_length); memcpy(dest->data, source->data, source->gtrid_length+source->bqual_length);
} }
void toku_txn_prepare_txn (TOKUTXN txn, TOKU_XA_XID *xa_xid) { void toku_txn_prepare_txn (TOKUTXN txn, TOKU_XA_XID *xa_xid, int nosync) {
if (txn->parent || toku_txn_is_read_only(txn)) { if (txn->parent || toku_txn_is_read_only(txn)) {
// We do not prepare children. // We do not prepare children.
// //
...@@ -571,7 +571,7 @@ void toku_txn_prepare_txn (TOKUTXN txn, TOKU_XA_XID *xa_xid) { ...@@ -571,7 +571,7 @@ void toku_txn_prepare_txn (TOKUTXN txn, TOKU_XA_XID *xa_xid) {
txn->state = TOKUTXN_PREPARING; txn->state = TOKUTXN_PREPARING;
toku_txn_unlock_state(txn); toku_txn_unlock_state(txn);
// Do we need to do an fsync? // Do we need to do an fsync?
txn->do_fsync = (txn->force_fsync_on_commit || txn->roll_info.num_rollentries>0); txn->do_fsync = txn->force_fsync_on_commit || (!nosync && txn->roll_info.num_rollentries>0);
copy_xid(&txn->xa_xid, xa_xid); copy_xid(&txn->xa_xid, xa_xid);
// This list will go away with #4683, so we wn't need the ydb lock for this anymore. // This list will go away with #4683, so we wn't need the ydb lock for this anymore.
toku_log_xprepare(txn->logger, &txn->do_fsync_lsn, 0, txn, txn->txnid, xa_xid); toku_log_xprepare(txn->logger, &txn->do_fsync_lsn, 0, txn, txn->txnid, xa_xid);
......
...@@ -302,7 +302,7 @@ int toku_txn_abort_with_lsn(struct tokutxn *txn, LSN oplsn, ...@@ -302,7 +302,7 @@ int toku_txn_abort_with_lsn(struct tokutxn *txn, LSN oplsn,
int toku_txn_discard_txn(struct tokutxn *txn); int toku_txn_discard_txn(struct tokutxn *txn);
void toku_txn_prepare_txn (struct tokutxn *txn, TOKU_XA_XID *xid); void toku_txn_prepare_txn (struct tokutxn *txn, TOKU_XA_XID *xid, int nosync);
// Effect: Do the internal work of preparing a transaction (does not log the prepare record). // Effect: Do the internal work of preparing a transaction (does not log the prepare record).
void toku_txn_get_prepared_xa_xid(struct tokutxn *txn, TOKU_XA_XID *xa_xid); void toku_txn_get_prepared_xa_xid(struct tokutxn *txn, TOKU_XA_XID *xa_xid);
......
...@@ -147,7 +147,7 @@ run_test(void) { ...@@ -147,7 +147,7 @@ run_test(void) {
uint8_t gid[DB_GID_SIZE]; uint8_t gid[DB_GID_SIZE];
memset(gid, 0, DB_GID_SIZE); memset(gid, 0, DB_GID_SIZE);
gid[0]=42; gid[0]=42;
r = txn->prepare(txn, gid); CKERR(r); r = txn->prepare(txn, gid, 0); CKERR(r);
} }
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r); r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
......
...@@ -122,7 +122,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir, bool commi ...@@ -122,7 +122,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir, bool commi
uint8_t gid[DB_GID_SIZE]; uint8_t gid[DB_GID_SIZE];
memset(gid, 0, DB_GID_SIZE); memset(gid, 0, DB_GID_SIZE);
gid[0]=42; gid[0]=42;
CKERR(txn->prepare(txn, gid)); CKERR(txn->prepare(txn, gid, 0));
if (commit) if (commit)
CKERR(txn->commit(txn, 0)); CKERR(txn->commit(txn, 0));
} }
......
...@@ -124,7 +124,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir, bool commi ...@@ -124,7 +124,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir, bool commi
uint8_t gid[DB_GID_SIZE]; uint8_t gid[DB_GID_SIZE];
memset(gid, 0, DB_GID_SIZE); memset(gid, 0, DB_GID_SIZE);
gid[0]=42; gid[0]=42;
CKERR(txn->prepare(txn, gid)); CKERR(txn->prepare(txn, gid, 0));
if (commit) if (commit)
CKERR(txn->commit(txn, 0)); CKERR(txn->commit(txn, 0));
} }
......
...@@ -147,7 +147,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir) { ...@@ -147,7 +147,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir) {
uint8_t gid[DB_GID_SIZE]; uint8_t gid[DB_GID_SIZE];
memset(gid, 0, DB_GID_SIZE); memset(gid, 0, DB_GID_SIZE);
gid[0]='a'+tnum; gid[0]='a'+tnum;
CKERR(txn->prepare(txn, gid)); CKERR(txn->prepare(txn, gid, 0));
// Drop txn on the ground, since we will commit or abort it after recovery // Drop txn on the ground, since we will commit or abort it after recovery
if (tnum==0) { if (tnum==0) {
//printf("commit %d\n", tnum); //printf("commit %d\n", tnum);
......
...@@ -125,7 +125,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir, bool commi ...@@ -125,7 +125,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir, bool commi
.gtrid_length = 8, .gtrid_length = 8,
.bqual_length = 9}; .bqual_length = 9};
for (int i=0; i<8+9; i++) x.data[i] = 42+i; for (int i=0; i<8+9; i++) x.data[i] = 42+i;
CKERR(txn->xa_prepare(txn, &x)); CKERR(txn->xa_prepare(txn, &x, 0));
if (commit) if (commit)
CKERR(txn->commit(txn, 0)); CKERR(txn->commit(txn, 0));
} }
......
...@@ -118,7 +118,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir, bool commi ...@@ -118,7 +118,7 @@ static void setup_env_and_prepare (DB_ENV **envp, const char *envdir, bool commi
uint8_t gid[DB_GID_SIZE]; uint8_t gid[DB_GID_SIZE];
memset(gid, 0, DB_GID_SIZE); memset(gid, 0, DB_GID_SIZE);
gid[0]=42; gid[0]=42;
CKERR(txn->prepare(txn, gid)); CKERR(txn->prepare(txn, gid, 0));
{ int chk_r = db->close(db, 0); CKERR(chk_r); } { int chk_r = db->close(db, 0); CKERR(chk_r); }
if (commit) if (commit)
CKERR(txn->commit(txn, 0)); CKERR(txn->commit(txn, 0));
......
...@@ -133,7 +133,7 @@ test_main(int argc, char *const argv[]) { ...@@ -133,7 +133,7 @@ test_main(int argc, char *const argv[]) {
uint8_t gid[DB_GID_SIZE]; uint8_t gid[DB_GID_SIZE];
memset(gid, 0, DB_GID_SIZE); memset(gid, 0, DB_GID_SIZE);
gid[0]='a'; gid[0]='a';
r = child_txn->prepare(child_txn, gid); r = child_txn->prepare(child_txn, gid, 0);
CKERR(r); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); r = env->txn_checkpoint(env, 0, 0, 0);
......
...@@ -211,7 +211,7 @@ static int hi_inserts(DB_TXN* UU(txn), ARG arg, void* UU(operation_extra), void ...@@ -211,7 +211,7 @@ static int hi_inserts(DB_TXN* UU(txn), ARG arg, void* UU(operation_extra), void
gid_count++; gid_count++;
uint32_t *hi_gid_count_p = cast_to_typeof(hi_gid_count_p) hi_gid; // make gcc --happy about -Wstrict-aliasing uint32_t *hi_gid_count_p = cast_to_typeof(hi_gid_count_p) hi_gid; // make gcc --happy about -Wstrict-aliasing
*hi_gid_count_p = gid_count; *hi_gid_count_p = gid_count;
int rr = hi_txn->prepare(hi_txn, hi_gid); int rr = hi_txn->prepare(hi_txn, hi_gid, 0);
CKERR(rr); CKERR(rr);
if (r || (random() % 2)) { if (r || (random() % 2)) {
rr = hi_txn->abort(hi_txn); rr = hi_txn->abort(hi_txn);
......
...@@ -130,7 +130,7 @@ test_txn_close_before_prepare_commit (void) { ...@@ -130,7 +130,7 @@ test_txn_close_before_prepare_commit (void) {
uint8_t gid[DB_GID_SIZE]; uint8_t gid[DB_GID_SIZE];
memset(gid, 1, DB_GID_SIZE); memset(gid, 1, DB_GID_SIZE);
r = txn->prepare(txn, gid); assert(r == 0); r = txn->prepare(txn, gid, 0); assert(r == 0);
r = txn->commit(txn, 0); assert(r == 0); r = txn->commit(txn, 0); assert(r == 0);
r = env->close(env, 0); assert(r == 0); r = env->close(env, 0); assert(r == 0);
......
...@@ -593,7 +593,7 @@ static void *worker(void *arg_v) { ...@@ -593,7 +593,7 @@ static void *worker(void *arg_v) {
uint64_t gid_val = txn->id64(txn); uint64_t gid_val = txn->id64(txn);
uint64_t *gid_count_p = cast_to_typeof(gid_count_p) gid; // make gcc --happy about -Wstrict-aliasing uint64_t *gid_count_p = cast_to_typeof(gid_count_p) gid; // make gcc --happy about -Wstrict-aliasing
*gid_count_p = gid_val; *gid_count_p = gid_val;
int rr = txn->prepare(txn, gid); int rr = txn->prepare(txn, gid, 0);
assert_zero(rr); assert_zero(rr);
} }
if (r == 0) { if (r == 0) {
......
...@@ -136,7 +136,7 @@ static void create_prepared_txn(void) { ...@@ -136,7 +136,7 @@ static void create_prepared_txn(void) {
for (int i = 0; i < 8+9; i++) { for (int i = 0; i < 8+9; i++) {
xid.data[i] = i; xid.data[i] = i;
} }
r = txn->xa_prepare(txn, &xid); r = txn->xa_prepare(txn, &xid, 0);
CKERR(r); CKERR(r);
// discard the txn so that we can close the env and run xa recovery later // discard the txn so that we can close the env and run xa recovery later
......
...@@ -136,7 +136,7 @@ static void create_prepared_txn(void) { ...@@ -136,7 +136,7 @@ static void create_prepared_txn(void) {
for (int i = 0; i < 8+9; i++) { for (int i = 0; i < 8+9; i++) {
xid.data[i] = i; xid.data[i] = i;
} }
r = txn->xa_prepare(txn, &xid); r = txn->xa_prepare(txn, &xid, 0);
CKERR(r); CKERR(r);
// discard the txn so that we can close the env and run xa recovery later // discard the txn so that we can close the env and run xa recovery later
......
...@@ -138,7 +138,7 @@ static void create_prepared_txn(void) { ...@@ -138,7 +138,7 @@ static void create_prepared_txn(void) {
for (int i = 0; i < 8+9; i++) { for (int i = 0; i < 8+9; i++) {
xid.data[i] = i; xid.data[i] = i;
} }
r = txn->xa_prepare(txn, &xid); r = txn->xa_prepare(txn, &xid, 0);
CKERR(r); CKERR(r);
// discard the txn so that we can close the env and run xa recovery later // discard the txn so that we can close the env and run xa recovery later
......
...@@ -139,7 +139,7 @@ static void create_prepared_txn(void) { ...@@ -139,7 +139,7 @@ static void create_prepared_txn(void) {
for (int i = 0; i < 8+9; i++) { for (int i = 0; i < 8+9; i++) {
xid.data[i] = i; xid.data[i] = i;
} }
r = txn->xa_prepare(txn, &xid); r = txn->xa_prepare(txn, &xid, 0);
CKERR(r); CKERR(r);
// discard the txn so that we can close the env and run xa recovery later // discard the txn so that we can close the env and run xa recovery later
......
...@@ -239,7 +239,7 @@ static int toku_txn_abort(DB_TXN * txn, ...@@ -239,7 +239,7 @@ static int toku_txn_abort(DB_TXN * txn,
return r; return r;
} }
static int toku_txn_xa_prepare (DB_TXN *txn, TOKU_XA_XID *xid) { static int toku_txn_xa_prepare (DB_TXN *txn, TOKU_XA_XID *xid, uint32_t flags) {
int r = 0; int r = 0;
if (!txn) { if (!txn) {
r = EINVAL; r = EINVAL;
...@@ -272,9 +272,11 @@ static int toku_txn_xa_prepare (DB_TXN *txn, TOKU_XA_XID *xid) { ...@@ -272,9 +272,11 @@ static int toku_txn_xa_prepare (DB_TXN *txn, TOKU_XA_XID *xid) {
HANDLE_PANICKED_ENV(txn->mgrp); HANDLE_PANICKED_ENV(txn->mgrp);
} }
assert(!db_txn_struct_i(txn)->child); assert(!db_txn_struct_i(txn)->child);
int nosync;
nosync = (flags & DB_TXN_NOSYNC)!=0 || (db_txn_struct_i(txn)->flags&DB_TXN_NOSYNC);
TOKUTXN ttxn; TOKUTXN ttxn;
ttxn = db_txn_struct_i(txn)->tokutxn; ttxn = db_txn_struct_i(txn)->tokutxn;
toku_txn_prepare_txn(ttxn, xid); toku_txn_prepare_txn(ttxn, xid, nosync);
TOKULOGGER logger; TOKULOGGER logger;
logger = txn->mgrp->i->logger; logger = txn->mgrp->i->logger;
LSN do_fsync_lsn; LSN do_fsync_lsn;
...@@ -291,14 +293,14 @@ static int toku_txn_xa_prepare (DB_TXN *txn, TOKU_XA_XID *xid) { ...@@ -291,14 +293,14 @@ static int toku_txn_xa_prepare (DB_TXN *txn, TOKU_XA_XID *xid) {
// requires: must hold the multi operation lock. it is // requires: must hold the multi operation lock. it is
// released in toku_txn_xa_prepare before the fsync. // released in toku_txn_xa_prepare before the fsync.
static int toku_txn_prepare (DB_TXN *txn, uint8_t gid[DB_GID_SIZE]) { static int toku_txn_prepare (DB_TXN *txn, uint8_t gid[DB_GID_SIZE], uint32_t flags) {
TOKU_XA_XID xid; TOKU_XA_XID xid;
TOKU_ANNOTATE_NEW_MEMORY(&xid, sizeof(xid)); TOKU_ANNOTATE_NEW_MEMORY(&xid, sizeof(xid));
xid.formatID=0x756b6f54; // "Toku" xid.formatID=0x756b6f54; // "Toku"
xid.gtrid_length=DB_GID_SIZE/2; // The maximum allowed gtrid length is 64. See the XA spec in source:/import/opengroup.org/C193.pdf page 20. xid.gtrid_length=DB_GID_SIZE/2; // The maximum allowed gtrid length is 64. See the XA spec in source:/import/opengroup.org/C193.pdf page 20.
xid.bqual_length=DB_GID_SIZE/2; // The maximum allowed bqual length is 64. xid.bqual_length=DB_GID_SIZE/2; // The maximum allowed bqual length is 64.
memcpy(xid.data, gid, DB_GID_SIZE); memcpy(xid.data, gid, DB_GID_SIZE);
return toku_txn_xa_prepare(txn, &xid); return toku_txn_xa_prepare(txn, &xid, flags);
} }
static int toku_txn_txn_stat (DB_TXN *txn, struct txn_stat **txn_stat) { static int toku_txn_txn_stat (DB_TXN *txn, struct txn_stat **txn_stat) {
......
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