本文整理汇总了C++中WT_SESSION::rollback_transaction方法的典型用法代码示例。如果您正苦于以下问题:C++ WT_SESSION::rollback_transaction方法的具体用法?C++ WT_SESSION::rollback_transaction怎么用?C++ WT_SESSION::rollback_transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WT_SESSION
的用法示例。
在下文中一共展示了WT_SESSION::rollback_transaction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _txnClose
void WiredTigerRecoveryUnit::_txnClose(bool commit) {
invariant(_isActive(), toString(_state));
WT_SESSION* s = _session->getSession();
if (_timer) {
const int transactionTime = _timer->millis();
// `serverGlobalParams.slowMs` can be set to values <= 0. In those cases, give logging a
// break.
if (transactionTime >= std::max(1, serverGlobalParams.slowMS)) {
LOG(kSlowTransactionSeverity) << "Slow WT transaction. Lifetime of SnapshotId "
<< _mySnapshotId << " was " << transactionTime << "ms";
}
}
int wtRet;
if (commit) {
if (!_commitTimestamp.isNull()) {
const std::string conf = "commit_timestamp=" + integerToHex(_commitTimestamp.asULL());
invariantWTOK(s->timestamp_transaction(s, conf.c_str()));
_isTimestamped = true;
}
wtRet = s->commit_transaction(s, nullptr);
LOG(3) << "WT commit_transaction for snapshot id " << _mySnapshotId;
} else {
wtRet = s->rollback_transaction(s, nullptr);
invariant(!wtRet);
LOG(3) << "WT rollback_transaction for snapshot id " << _mySnapshotId;
}
if (_isTimestamped) {
if (!_orderedCommit) {
// We only need to update oplog visibility where commits can be out-of-order with
// respect to their assigned optime and such commits might otherwise be visible.
// This should happen only on primary nodes.
_oplogManager->triggerJournalFlush();
}
_isTimestamped = false;
}
invariantWTOK(wtRet);
invariant(!_lastTimestampSet || _commitTimestamp.isNull(),
str::stream() << "Cannot have both a _lastTimestampSet and a "
"_commitTimestamp. _lastTimestampSet: "
<< _lastTimestampSet->toString()
<< ". _commitTimestamp: "
<< _commitTimestamp.toString());
// We reset the _lastTimestampSet between transactions. Since it is legal for one
// transaction on a RecoveryUnit to call setTimestamp() and another to call
// setCommitTimestamp().
_lastTimestampSet = boost::none;
_prepareTimestamp = Timestamp();
_mySnapshotId = nextSnapshotId.fetchAndAdd(1);
_isOplogReader = false;
_orderedCommit = true; // Default value is true; we assume all writes are ordered.
}
示例2: do_rollback
void do_rollback() override {
resetCursors();
#if TERARK_WT_USE_TXN
WT_SESSION* ses = m_session.ses;
int err = ses->rollback_transaction(ses, NULL);
if (err) {
THROW_STD(invalid_argument
, "ERROR: wiredtiger rollback_transaction: %s"
, ses->strerror(ses, err));
}
#endif
}
示例3: _txnClose
void WiredTigerRecoveryUnit::_txnClose(bool commit) {
invariant(_active);
WT_SESSION* s = _session->getSession();
if (commit) {
invariantWTOK(s->commit_transaction(s, NULL));
LOG(3) << "WT commit_transaction for snapshot id " << _mySnapshotId;
} else {
invariantWTOK(s->rollback_transaction(s, NULL));
LOG(3) << "WT rollback_transaction for snapshot id " << _mySnapshotId;
}
_active = false;
_mySnapshotId = nextSnapshotId.fetchAndAdd(1);
}
示例4: _txnClose
void WiredTigerRecoveryUnit::_txnClose(bool commit) {
invariant(_active);
WT_SESSION* s = _session->getSession();
if (commit) {
invariantWTOK(s->commit_transaction(s, NULL));
LOG(2) << "WT commit_transaction";
} else {
invariantWTOK(s->rollback_transaction(s, NULL));
LOG(2) << "WT rollback_transaction";
}
_active = false;
_myTransactionCount++;
_ticket.reset(NULL);
}
示例5: _txnClose
void WiredTigerRecoveryUnit::_txnClose( bool commit ) {
invariant( _active );
WT_SESSION *s = _session->getSession();
if ( commit ) {
invariantWTOK( s->commit_transaction(s, NULL) );
LOG(2) << "WT commit_transaction";
if ( _syncing )
awaitCommitData.syncHappend();
}
else {
invariantWTOK( s->rollback_transaction(s, NULL) );
LOG(2) << "WT rollback_transaction";
}
_active = false;
}
示例6:
/*
* Append to a table in a "racy" fashion - that is attempt to insert the
* same record another thread is likely to also be inserting.
*/
void *
thread_insert_race(void *arg)
{
TEST_OPTS *opts;
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_SESSION *session;
uint64_t i, value;
int ret;
opts = (TEST_OPTS *)arg;
conn = opts->conn;
testutil_check(conn->open_session(conn, NULL, NULL, &session));
testutil_check(session->open_cursor(
session, opts->uri, NULL, NULL, &cursor));
printf("Running insert thread\n");
for (i = 0; i < opts->nrecords; ++i) {
testutil_check(
session->begin_transaction(session, "isolation=snapshot"));
cursor->set_key(cursor, 1);
testutil_check(cursor->search(cursor));
testutil_check(cursor->get_value(cursor, &value));
cursor->set_key(cursor, 1);
cursor->set_value(cursor, value + 1);
if ((ret = cursor->update(cursor)) != 0) {
if (ret == WT_ROLLBACK) {
testutil_check(session->rollback_transaction(
session, NULL));
i--;
continue;
}
printf("Error in update: %d\n", ret);
}
testutil_check(session->commit_transaction(session, NULL));
if (i % 10000 == 0) {
printf("insert: %" PRIu64 "\r", i);
fflush(stdout);
}
}
if (i > 10000)
printf("\n");
opts->running = false;
return (NULL);
}
示例7: _txnClose
void WiredTigerRecoveryUnit::_txnClose(bool commit) {
invariant(_active);
WT_SESSION* s = _session->getSession();
if (_timer) {
const int transactionTime = _timer->millis();
if (transactionTime >= serverGlobalParams.slowMS) {
LOG(kSlowTransactionSeverity) << "Slow WT transaction. Lifetime of SnapshotId "
<< _mySnapshotId << " was " << transactionTime << "ms";
}
}
if (commit) {
invariantWTOK(s->commit_transaction(s, NULL));
LOG(3) << "WT commit_transaction for snapshot id " << _mySnapshotId;
} else {
invariantWTOK(s->rollback_transaction(s, NULL));
LOG(3) << "WT rollback_transaction for snapshot id " << _mySnapshotId;
}
_active = false;
_mySnapshotId = nextSnapshotId.fetchAndAdd(1);
_oplogReadTill = RecordId();
}
示例8: mmrand
//.........这里部分代码省略.........
if (g.append_cnt >= g.append_max)
goto skip_insert;
/* Insert, then reset the insert cursor. */
if (col_insert(tinfo,
cursor_insert, &key, &value, &keyno))
goto deadlock;
if ((ret =
cursor_insert->reset(cursor_insert)) != 0)
die(ret, "cursor.reset");
insert = 1;
break;
}
} else if (
op < g.c_delete_pct + g.c_insert_pct + g.c_write_pct) {
++tinfo->update;
switch (g.type) {
case ROW:
if (row_update(
tinfo, cursor, &key, &value, keyno))
goto deadlock;
break;
case FIX:
case VAR:
skip_insert: if (col_update(tinfo,
cursor, &key, &value, keyno))
goto deadlock;
break;
}
} else {
++tinfo->search;
if (read_row(cursor, &key, keyno))
if (intxn)
goto deadlock;
continue;
}
/*
* The cursor is positioned if we did any operation other than
* insert, do a small number of next/prev cursor operations in
* a random direction.
*/
if (!insert) {
dir = (int)mmrand(&tinfo->rnd, 0, 1);
for (np = 0; np < mmrand(&tinfo->rnd, 1, 8); ++np) {
if (notfound)
break;
if (nextprev(cursor, dir, ¬found))
goto deadlock;
}
}
/* Read to confirm the operation. */
++tinfo->search;
if (read_row(cursor, &key, keyno))
goto deadlock;
/* Reset the cursor: there is no reason to keep pages pinned. */
if ((ret = cursor->reset(cursor)) != 0)
die(ret, "cursor.reset");
/*
* If we're in the transaction, commit 40% of the time and
* rollback 10% of the time.
*/
if (intxn)
switch (mmrand(&tinfo->rnd, 1, 10)) {
case 1: case 2: case 3: case 4: /* 40% */
if ((ret = session->commit_transaction(
session, NULL)) != 0)
die(ret, "session.commit_transaction");
++tinfo->commit;
intxn = 0;
break;
case 5: /* 10% */
if (0) {
deadlock: ++tinfo->deadlock;
}
if ((ret = session->rollback_transaction(
session, NULL)) != 0)
die(ret,
"session.rollback_transaction");
++tinfo->rollback;
intxn = 0;
break;
default:
break;
}
}
if (session != NULL && (ret = session->close(session, NULL)) != 0)
die(ret, "session.close");
free(keybuf);
free(valbuf);
tinfo->state = TINFO_COMPLETE;
return (NULL);
}
示例9: if
//.........这里部分代码省略.........
*/
if (g.append_cnt >= g.append_max)
goto skip_insert;
/*
* Reset the standard cursor so it doesn't keep
* pages pinned.
*/
if ((ret = cursor->reset(cursor)) != 0)
die(ret, "cursor.reset");
/* Insert, then reset the insert cursor. */
if (col_insert(
cursor_insert, &key, &value, &keyno))
goto deadlock;
if ((ret =
cursor_insert->reset(cursor_insert)) != 0)
die(ret, "cursor.reset");
insert = 1;
break;
}
} else if (
op < g.c_delete_pct + g.c_insert_pct + g.c_write_pct) {
++tinfo->update;
switch (g.type) {
case ROW:
if (row_update(cursor, &key, &value, keyno))
goto deadlock;
break;
case FIX:
case VAR:
skip_insert: if (col_update(cursor, &key, &value, keyno))
goto deadlock;
break;
}
} else {
++tinfo->search;
if (read_row(cursor, &key, keyno))
goto deadlock;
continue;
}
/*
* The cursor is positioned if we did any operation other than
* insert, do a small number of next/prev cursor operations in
* a random direction.
*/
if (!insert) {
dir = (int)MMRAND(0, 1);
for (np = 0; np < MMRAND(1, 8); ++np) {
if (notfound)
break;
if (nextprev(cursor, dir, ¬found))
goto deadlock;
}
}
/* Read the value we modified to confirm the operation. */
++tinfo->search;
if (read_row(cursor, &key, keyno))
goto deadlock;
/*
* If we're in the transaction, commit 40% of the time and
* rollback 10% of the time.
*/
if (intxn)
switch (MMRAND(1, 10)) {
case 1: case 2: case 3: case 4: /* 40% */
if ((ret = session->commit_transaction(
session, NULL)) != 0)
die(ret, "session.commit_transaction");
++tinfo->commit;
intxn = 0;
break;
case 5: /* 10% */
if (0) {
deadlock: ++tinfo->deadlock;
}
if ((ret = session->rollback_transaction(
session, NULL)) != 0)
die(ret, "session.commit_transaction");
++tinfo->rollback;
intxn = 0;
break;
default:
break;
}
}
if (session != NULL && (ret = session->close(session, NULL)) != 0)
die(ret, "session.close");
free(keybuf);
free(valbuf);
tinfo->state = TINFO_COMPLETE;
return (NULL);
}
示例10: sizeof
/*
* real_worker --
* A single worker thread that transactionally updates all tables with
* consistent values.
*/
static int
real_worker(void)
{
WT_CURSOR **cursors;
WT_RAND_STATE rnd;
WT_SESSION *session;
u_int i, keyno;
int j, ret, t_ret;
ret = t_ret = 0;
__wt_random_init(&rnd);
if ((cursors = calloc(
(size_t)(g.ntables), sizeof(WT_CURSOR *))) == NULL)
return (log_print_err("malloc", ENOMEM, 1));
if ((ret = g.conn->open_session(
g.conn, NULL, "isolation=snapshot", &session)) != 0) {
(void)log_print_err("conn.open_session", ret, 1);
goto err;
}
for (j = 0; j < g.ntables; j++)
if ((ret = session->open_cursor(session,
g.cookies[j].uri, NULL, NULL, &cursors[j])) != 0) {
(void)log_print_err("session.open_cursor", ret, 1);
goto err;
}
for (i = 0; i < g.nops && g.running; ++i, __wt_yield()) {
if ((ret = session->begin_transaction(session, NULL)) != 0) {
(void)log_print_err(
"real_worker:begin_transaction", ret, 1);
goto err;
}
keyno = __wt_random(&rnd) % g.nkeys + 1;
for (j = 0; j < g.ntables; j++) {
if ((ret = worker_op(cursors[j], keyno, i)) != 0)
break;
}
if (ret == 0) {
if ((ret = session->commit_transaction(
session, NULL)) != 0) {
(void)log_print_err(
"real_worker:commit_transaction", ret, 1);
goto err;
}
} else if (ret == WT_ROLLBACK) {
if ((ret = session->rollback_transaction(
session, NULL)) != 0) {
(void)log_print_err(
"real_worker:rollback_transaction", ret, 1);
goto err;
}
} else {
(void)log_print_err("worker op failed", ret, 1);
goto err;
}
}
err: if ((t_ret = session->close(session, NULL)) != 0 && ret == 0) {
ret = t_ret;
(void)log_print_err("session.close", ret, 1);
}
free(cursors);
return (ret);
}
示例11: sizeof
static void
transaction_ops(WT_SESSION *session_arg)
{
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_SESSION *session;
session = session_arg;
conn = session->connection;
/*! [transaction commit/rollback] */
/*
* Cursors may be opened before or after the transaction begins, and in
* either case, subsequent operations are included in the transaction.
* Opening cursors before the transaction begins allows applications to
* cache cursors and use them for multiple operations.
*/
error_check(session->open_cursor(
session, "table:mytable", NULL, NULL, &cursor));
error_check(session->begin_transaction(session, NULL));
cursor->set_key(cursor, "key");
cursor->set_value(cursor, "value");
switch (cursor->update(cursor)) {
case 0: /* Update success */
error_check(session->commit_transaction(session, NULL));
/*
* If commit_transaction succeeds, cursors remain positioned; if
* commit_transaction fails, the transaction was rolled-back and
* and all cursors are reset.
*/
break;
case WT_ROLLBACK: /* Update conflict */
default: /* Other error */
error_check(session->rollback_transaction(session, NULL));
/* The rollback_transaction call resets all cursors. */
break;
}
/*
* Cursors remain open and may be used for multiple transactions.
*/
/*! [transaction commit/rollback] */
error_check(cursor->close(cursor));
/*! [transaction isolation] */
/* A single transaction configured for snapshot isolation. */
error_check(session->open_cursor(
session, "table:mytable", NULL, NULL, &cursor));
error_check(session->begin_transaction(session, "isolation=snapshot"));
cursor->set_key(cursor, "some-key");
cursor->set_value(cursor, "some-value");
error_check(cursor->update(cursor));
error_check(session->commit_transaction(session, NULL));
/*! [transaction isolation] */
{
/*! [transaction prepare] */
/*
* Prepare a transaction which guarantees a subsequent commit will
* succeed. Only commit and rollback are allowed on a transaction after
* it has been prepared.
*/
error_check(session->open_cursor(
session, "table:mytable", NULL, NULL, &cursor));
error_check(session->begin_transaction(session, NULL));
cursor->set_key(cursor, "key");
cursor->set_value(cursor, "value");
error_check(session->prepare_transaction(
session, "prepare_timestamp=2a"));
error_check(session->commit_transaction(
session, "commit_timestamp=2b"));
/*! [transaction prepare] */
}
/*! [session isolation configuration] */
/* Open a session configured for read-uncommitted isolation. */
error_check(conn->open_session(
conn, NULL, "isolation=read-uncommitted", &session));
/*! [session isolation configuration] */
/*! [session isolation re-configuration] */
/* Re-configure a session for snapshot isolation. */
error_check(session->reconfigure(session, "isolation=snapshot"));
/*! [session isolation re-configuration] */
error_check(session->close(session, NULL));
session = session_arg;
{
/*! [transaction pinned range] */
/* Check the transaction ID range pinned by the session handle. */
uint64_t range;
error_check(session->transaction_pinned_range(session, &range));
/*! [transaction pinned range] */
}
error_check(session->begin_transaction(session, NULL));
//.........这里部分代码省略.........
示例12:
static void *
thread_get(void *arg)
{
SHARED_OPTS *sharedopts;
TEST_OPTS *opts;
THREAD_ARGS *threadargs;
WT_CURSOR *maincur, *postcur;
WT_SESSION *session;
double elapsed;
time_t prevtime, curtime; /* 1 second resolution is okay */
int bal, flag, key, key2, post, bal2, flag2, post2;
char *extra;
threadargs = (THREAD_ARGS *)arg;
opts = threadargs->testopts;
sharedopts = threadargs->sharedopts;
(void)time(&prevtime);
testutil_check(opts->conn->open_session(
opts->conn, NULL, NULL, &session));
testutil_check(session->open_cursor(session, opts->uri, NULL, NULL,
&maincur));
testutil_check(session->open_cursor(
session, sharedopts->posturi, NULL, NULL, &postcur));
for (threadargs->njoins = 0; threadargs->done == 0;
threadargs->njoins++) {
testutil_check(session->begin_transaction(session, NULL));
postcur->set_key(postcur, 54321);
testutil_check(postcur->search(postcur));
while (postcur->next(postcur) == 0) {
testutil_check(postcur->get_key(postcur, &post));
testutil_check(postcur->get_value(postcur, &post2,
&bal, &extra, &flag, &key));
testutil_assert(post == post2);
if (post != 54321)
break;
maincur->set_key(maincur, key);
testutil_check(maincur->search(maincur));
testutil_check(maincur->get_value(maincur, &post2,
&bal2, &extra, &flag2, &key2));
testutil_check(maincur->reset(maincur));
testutil_assert(key == key2);
testutil_assert(post == post2);
testutil_assert(bal == bal2);
testutil_assert(flag == flag2);
testutil_assert((flag2 > 0 && bal2 < 0) ||
(flag2 == 0 && bal2 >= 0));
}
/*
* Reset the cursors, potentially allowing the insert
* threads to proceed.
*/
testutil_check(postcur->reset(postcur));
if (threadargs->njoins % 100 == 0)
fprintf(stderr, "G");
testutil_check(session->rollback_transaction(session, NULL));
(void)time(&curtime);
if ((elapsed = difftime(curtime, prevtime)) > 5.0) {
fprintf(stderr, "\n"
"GAP: %.0f secs after %d gets\n",
elapsed, threadargs->njoins);
threadargs->nfail++;
}
prevtime = curtime;
}
testutil_check(postcur->close(postcur));
testutil_check(maincur->close(maincur));
testutil_check(session->close(session, NULL));
return (NULL);
}