本文整理汇总了C++中WT_SESSION::begin_transaction方法的典型用法代码示例。如果您正苦于以下问题:C++ WT_SESSION::begin_transaction方法的具体用法?C++ WT_SESSION::begin_transaction怎么用?C++ WT_SESSION::begin_transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WT_SESSION
的用法示例。
在下文中一共展示了WT_SESSION::begin_transaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dcalloc
/*
* Each thread inserts a set of keys into the record store database. The keys
* are generated in such a way that there are large gaps in the key range.
*/
static void *
thread_func(void *arg)
{
TEST_OPTS *opts;
WT_CURSOR *cursor, *idx_cursor;
WT_SESSION *session;
uint64_t i, ins_rotor, ins_thr_idx, thr_idx, ts;
uint64_t *obj_data;
opts = (TEST_OPTS *)arg;
thr_idx = __wt_atomic_fetch_addv64(&opts->next_threadid, 1);
ts = g_ts;
obj_data = dcalloc(
(NR_OBJECTS/NR_THREADS + 1) * NR_FIELDS, sizeof(*obj_data));
testutil_check(opts->conn->open_session(
opts->conn, NULL, NULL, &session));
testutil_check(session->open_cursor(
session, opts->uri, NULL, NULL, &cursor));
testutil_check(session->open_cursor(
session, "table:index", NULL, NULL, &idx_cursor));
for (ins_rotor = 1; ins_rotor < 10; ++ins_rotor) {
for (ins_thr_idx = thr_idx, i = 0; ins_thr_idx < NR_OBJECTS;
ins_thr_idx += NR_THREADS, i += NR_FIELDS) {
testutil_check(
session->begin_transaction(session, "sync=false"));
cursor->set_key(cursor, ins_thr_idx << 40 | ins_rotor);
cursor->set_value(cursor, ts,
obj_data[i+0], obj_data[i+1], obj_data[i+2],
obj_data[i+3], obj_data[i+4], obj_data[i+5],
obj_data[i+6], obj_data[i+7]);
testutil_check(cursor->insert(cursor));
idx_cursor->set_key(
idx_cursor, ins_thr_idx << 40 | ts);
idx_cursor->set_value(idx_cursor, ins_rotor);
testutil_check(idx_cursor->insert(idx_cursor));
testutil_check(
session->commit_transaction(session, NULL));
/* change object fields */
++obj_data[i + ((ins_thr_idx + ins_rotor) % NR_FIELDS)];
++obj_data[i +
((ins_thr_idx + ins_rotor + 1) % NR_FIELDS)];
++g_ts;
/* 5K updates/sec */
(void)usleep(1000000ULL * NR_THREADS / 5000);
}
}
testutil_check(session->close(session, NULL));
free(obj_data);
return (NULL);
}
示例2: _txnOpen
void WiredTigerRecoveryUnit::_txnOpen() {
invariant( !_active );
WT_SESSION *s = _session->getSession();
_syncing = _syncing || awaitCommitData.numWaitingForSync.load() > 0;
invariantWTOK( s->begin_transaction(s, _syncing ? "sync=true" : NULL) );
LOG(2) << "WT begin_transaction";
_timer.reset();
_active = true;
}
示例3: _txnOpen
void WiredTigerRecoveryUnit::_txnOpen(OperationContext* opCtx) {
invariant( !_active );
_getTicket(opCtx);
WT_SESSION *s = _session->getSession();
_syncing = _syncing || waitUntilDurableData.numWaitingForSync.load() > 0;
invariantWTOK( s->begin_transaction(s, _syncing ? "sync=true" : NULL) );
LOG(2) << "WT begin_transaction";
_timer.reset();
_active = true;
}
示例4: syncSizeInfo
void WiredTigerKVEngine::syncSizeInfo() const {
if ( !_sizeStorer )
return;
try {
WiredTigerSession session( _conn, -1 );
WT_SESSION* s = session.getSession();
invariantWTOK( s->begin_transaction( s, "sync=true" ) );
_sizeStorer->storeInto( &session, _sizeStorerUri );
invariantWTOK( s->commit_transaction( s, NULL ) );
}
catch ( const WriteConflictException& de ) {
// ignore, it means someone else is doing it
}
}
示例5:
/*
* 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);
}
示例6: _txnOpen
void WiredTigerRecoveryUnit::_txnOpen(OperationContext* opCtx) {
invariant(!_active);
_ensureSession();
WT_SESSION* s = _session->getSession();
if (_readFromMajorityCommittedSnapshot) {
_majorityCommittedSnapshot =
_sessionCache->snapshotManager().beginTransactionOnCommittedSnapshot(s);
} else {
invariantWTOK(s->begin_transaction(s, NULL));
}
LOG(3) << "WT begin_transaction for snapshot id " << _mySnapshotId;
_timer.reset();
_active = true;
}
示例7: _txnOpen
void WiredTigerRecoveryUnit::_txnOpen(OperationContext* opCtx) {
invariant(!_active);
_getTicket(opCtx);
WT_SESSION* s = _session->getSession();
_syncing = _syncing || waitUntilDurableData.numWaitingForSync.load() > 0;
if (_readFromMajorityCommittedSnapshot) {
_sessionCache->snapshotManager().beginTransactionOnCommittedSnapshot(s, _syncing);
} else {
invariantWTOK(s->begin_transaction(s, _syncing ? "sync=true" : NULL));
}
LOG(2) << "WT begin_transaction";
_timer.reset();
_active = true;
}
示例8: do_startTransaction
void do_startTransaction() override {
#if TERARK_WT_USE_TXN
WT_SESSION* ses = m_session.ses;
const char* txnConfig = getenv("TerarkDB_WiredtigerTransactionConfig");
if (NULL == txnConfig) {
// wiredtiger 2.8.0 is not binary compatible with 2.7.0
txnConfig = "isolation=read-committed,sync=false";
}
// fprintf(stderr, "INFO: %s: txnConfig=%s\n", BOOST_CURRENT_FUNCTION, txnConfig);
int err = ses->begin_transaction(ses, txnConfig);
if (err) {
THROW_STD(invalid_argument
, "ERROR: wiredtiger begin_transaction: %s"
, ses->strerror(ses, err));
}
#endif
m_sizeDiff = 0;
}
示例9: _txnOpen
void WiredTigerRecoveryUnit::_txnOpen(OperationContext* opCtx) {
invariant(!_active);
_ensureSession();
// Only start a timer for transaction's lifetime if we're going to log it.
if (shouldLog(kSlowTransactionSeverity)) {
_timer.reset(new Timer());
}
WT_SESSION* s = _session->getSession();
if (_readFromMajorityCommittedSnapshot) {
_majorityCommittedSnapshot =
_sessionCache->snapshotManager().beginTransactionOnCommittedSnapshot(s);
} else {
invariantWTOK(s->begin_transaction(s, NULL));
}
LOG(3) << "WT begin_transaction for snapshot id " << _mySnapshotId;
_active = true;
}
示例10: main
int main(void)
{
int ret;
WT_CONNECTION *conn;
WT_SESSION *session;
WT_CURSOR *cursor;
const char *key, *value;
/*! [configure cache size] */
if ((ret = wiredtiger_open(home, NULL,
"create,cache_size=500M", &conn)) != 0)
fprintf(stderr, "Error connecting to %s: %s\n",
home, wiredtiger_strerror(ret));
/*! [configure cache size] */
/*! [create a table] */
ret = conn->open_session(conn, NULL, NULL, &session);
ret = session->create(session,
"table:access", "key_format=S,value_format=S");
/*! [create a table] */
/*! [transaction] */
ret = session->begin_transaction(session, "priority=100,name=mytxn");
ret = session->open_cursor(session, "config:", NULL, NULL, &cursor);
while ((ret = cursor->next(cursor)) == 0) {
cursor->get_key(cursor, &key);
cursor->get_value(cursor, &value);
printf("configuration value: %s = %s\n", key, value);
}
ret = session->commit_transaction(session, NULL);
/*! [transaction] */
ret = conn->close(conn, NULL);
return (ret);
}
示例11:
void
populate(TEST_OPTS *opts)
{
WT_CURSOR *maincur;
WT_RAND_STATE rnd;
WT_SESSION *session;
uint32_t key;
int balance, i, flag, post;
__wt_random_init_seed(NULL, &rnd);
testutil_check(opts->conn->open_session(
opts->conn, NULL, NULL, &session));
testutil_check(session->open_cursor(session, opts->uri, NULL, NULL,
&maincur));
for (i = 0; i < N_INSERT; i++) {
testutil_check(session->begin_transaction(session, NULL));
key = (__wt_random(&rnd) % (N_RECORDS));
maincur->set_key(maincur, key);
if (__wt_random(&rnd) % 11 == 0)
post = 54321;
else
post = i % 100000;
if (__wt_random(&rnd) % 4 == 0) {
balance = -100;
flag = 1;
} else {
balance = 100 * (i + 1);
flag = 0;
}
maincur->set_value(maincur, post, balance, flag, key);
testutil_check(maincur->insert(maincur));
testutil_check(session->commit_transaction(session, NULL));
}
testutil_check(maincur->close(maincur));
testutil_check(session->close(session, NULL));
}
示例12: 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));
//.........这里部分代码省略.........
示例13:
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);
}
示例14: syncCache
void WiredTigerSizeStorer::syncCache(bool syncToDisk) {
stdx::lock_guard<stdx::mutex> cursorLock(_cursorMutex);
_checkMagic();
Map myMap;
{
stdx::lock_guard<stdx::mutex> lk(_entriesMutex);
for (Map::iterator it = _entries.begin(); it != _entries.end(); ++it) {
std::string uriKey = it->first;
Entry& entry = it->second;
if (entry.rs) {
if (entry.dataSize != entry.rs->dataSize(NULL)) {
entry.dataSize = entry.rs->dataSize(NULL);
entry.dirty = true;
}
if (entry.numRecords != entry.rs->numRecords(NULL)) {
entry.numRecords = entry.rs->numRecords(NULL);
entry.dirty = true;
}
}
if (!entry.dirty)
continue;
myMap[uriKey] = entry;
}
}
if (myMap.empty())
return; // Nothing to do.
WT_SESSION* session = _session.getSession();
invariantWTOK(session->begin_transaction(session, syncToDisk ? "sync=true" : ""));
ScopeGuard rollbacker = MakeGuard(session->rollback_transaction, session, "");
for (Map::iterator it = myMap.begin(); it != myMap.end(); ++it) {
string uriKey = it->first;
Entry& entry = it->second;
BSONObj data;
{
BSONObjBuilder b;
b.append("numRecords", entry.numRecords);
b.append("dataSize", entry.dataSize);
data = b.obj();
}
LOG(2) << "WiredTigerSizeStorer::storeInto " << uriKey << " -> " << redact(data);
WiredTigerItem key(uriKey.c_str(), uriKey.size());
WiredTigerItem value(data.objdata(), data.objsize());
_cursor->set_key(_cursor, key.Get());
_cursor->set_value(_cursor, value.Get());
invariantWTOK(_cursor->insert(_cursor));
}
invariantWTOK(_cursor->reset(_cursor));
rollbacker.Dismiss();
invariantWTOK(session->commit_transaction(session, NULL));
{
stdx::lock_guard<stdx::mutex> lk(_entriesMutex);
for (Map::iterator it = _entries.begin(); it != _entries.end(); ++it) {
it->second.dirty = false;
}
}
}
示例15: sizeof
int
main(void)
{
WT_CONNECTION *wt_conn;
WT_CURSOR *cursor;
WT_SESSION *session;
int i, record_count, ret;
char cmd_buf[256], k[16], v[16];
snprintf(cmd_buf, sizeof(cmd_buf), "rm -rf %s %s && mkdir %s %s",
home1, home2, home1, home2);
if ((ret = system(cmd_buf)) != 0) {
fprintf(stderr, "%s: failed ret %d\n", cmd_buf, ret);
return (ret);
}
if ((ret = wiredtiger_open(home1, NULL, CONN_CONFIG, &wt_conn)) != 0) {
fprintf(stderr, "Error connecting to %s: %s\n",
home1, wiredtiger_strerror(ret));
return (ret);
}
ret = wt_conn->open_session(wt_conn, NULL, NULL, &session);
ret = session->create(session, uri, "key_format=S,value_format=S");
ret = session->open_cursor(session, uri, NULL, NULL, &cursor);
/*
* Perform some operations with individual auto-commit transactions.
*/
for (record_count = 0, i = 0; i < MAX_KEYS; i++, record_count++) {
snprintf(k, sizeof(k), "key%d", i);
snprintf(v, sizeof(v), "value%d", i);
cursor->set_key(cursor, k);
cursor->set_value(cursor, v);
ret = cursor->insert(cursor);
}
ret = session->begin_transaction(session, NULL);
/*
* Perform some operations within a single transaction.
*/
for (i = MAX_KEYS; i < MAX_KEYS+5; i++, record_count++) {
snprintf(k, sizeof(k), "key%d", i);
snprintf(v, sizeof(v), "value%d", i);
cursor->set_key(cursor, k);
cursor->set_value(cursor, v);
ret = cursor->insert(cursor);
}
ret = session->commit_transaction(session, NULL);
ret = cursor->close(cursor);
/*! [log cursor printf] */
ret = session->log_printf(session, "Wrote %d records", record_count);
/*! [log cursor printf] */
/*
* Close and reopen the connection so that the log ends up with
* a variety of records such as file sync and checkpoint. We
* have archiving turned off.
*/
ret = wt_conn->close(wt_conn, NULL);
if ((ret = wiredtiger_open(home1, NULL, CONN_CONFIG, &wt_conn)) != 0) {
fprintf(stderr, "Error connecting to %s: %s\n",
home1, wiredtiger_strerror(ret));
return (ret);
}
ret = wt_conn->open_session(wt_conn, NULL, NULL, &session);
ret = simple_walk_log(session);
ret = walk_log(session);
ret = wt_conn->close(wt_conn, NULL);
return (ret);
}