本文整理汇总了C++中WT_CURSOR::set_value方法的典型用法代码示例。如果您正苦于以下问题:C++ WT_CURSOR::set_value方法的具体用法?C++ WT_CURSOR::set_value怎么用?C++ WT_CURSOR::set_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WT_CURSOR
的用法示例。
在下文中一共展示了WT_CURSOR::set_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: populate
void populate(TEST_OPTS *opts)
{
WT_CURSOR *maincur;
WT_SESSION *session;
uint32_t key;
int balance, i, flag, post;
WT_RAND_STATE rnd;
testutil_check(__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));
}
maincur->close(maincur);
session->close(session, NULL);
}
示例2:
int
main(int argc, char *argv[])
{
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_SESSION *session;
home = example_setup(argc, argv);
error_check(
wiredtiger_open(home, NULL, "create,statistics=(all)", &conn));
error_check(conn->open_session(conn, NULL, NULL, &session));
error_check(session->create(session,
"table:access", "key_format=S,value_format=S,columns=(k,v)"));
error_check(session->open_cursor(
session, "table:access", NULL, NULL, &cursor));
cursor->set_key(cursor, "key");
cursor->set_value(cursor, "value");
error_check(cursor->insert(cursor));
error_check(cursor->close(cursor));
error_check(session->checkpoint(session, NULL));
print_database_stats(session);
print_file_stats(session);
print_join_cursor_stats(session);
print_overflow_pages(session);
print_derived_stats(session);
error_check(conn->close(conn, NULL));
return (EXIT_SUCCESS);
}
示例3: getCursor
TEST_F(WiredTigerRecoveryUnitTestFixture,
LocalReadOnADocumentBeingPreparedDoesntTriggerPrepareConflict) {
// Prepare but don't commit a transaction
ru1->beginUnitOfWork(clientAndCtx1.second.get());
WT_CURSOR* cursor;
getCursor(ru1, &cursor);
cursor->set_key(cursor, "key");
cursor->set_value(cursor, "value");
invariantWTOK(cursor->insert(cursor));
ru1->setPrepareTimestamp({1, 1});
ru1->prepareUnitOfWork();
// A transaction that chooses to ignore prepare conflicts does not see the record instead of
// returning a prepare conflict.
ru2->beginUnitOfWork(clientAndCtx2.second.get());
ru2->setIgnorePrepared(true);
getCursor(ru2, &cursor);
cursor->set_key(cursor, "key");
int ret = cursor->search(cursor);
ASSERT_EQ(WT_NOTFOUND, ret);
ru1->abortUnitOfWork();
ru2->abortUnitOfWork();
}
示例4: sizeof
//.........这里部分代码省略.........
uri = clp->list[0];
(void)snprintf(config, sizeof(config),
"dump=json%s%s",
LF_ISSET(LOAD_JSON_APPEND) ? ",append" : "",
LF_ISSET(LOAD_JSON_NO_OVERWRITE) ? ",overwrite=false" : "");
if ((ret = session->open_cursor(
session, uri, NULL, config, &cursor)) != 0) {
ret = util_err(ret, "%s: session.open", uri);
goto err;
}
keyformat = cursor->key_format;
isrec = (strcmp(keyformat, "r") == 0);
for (nkeys = 0; *keyformat; keyformat++)
if (!isdigit(*keyformat))
nkeys++;
recno = 0;
while (json_peek(session, ins) == '{') {
nfield = 0;
JSON_EXPECT(session, ins, '{');
if (ins->kvraw == NULL) {
if ((ins->kvraw = (char *)malloc(1)) == NULL) {
ret = util_err(errno, NULL);
goto err;
}
}
ins->kvraw[0] = '\0';
ins->kvrawstart = JSON_INPUT_POS(ins);
keystrlen = 0;
while (json_peek(session, ins) == 's') {
JSON_EXPECT(session, ins, 's');
JSON_EXPECT(session, ins, ':');
toktype = json_peek(session, ins);
JSON_EXPECT(session, ins, toktype);
if (isrec && nfield == 0) {
/* Verify the dump has recnos in order. */
recno++;
gotno = __wt_strtouq(ins->tokstart, &endp, 0);
gotnolen = (endp - ins->tokstart);
if (recno != gotno ||
ins->toklen != (size_t)gotnolen) {
ret = util_err(0,
"%s: recno out of order", uri);
goto err;
}
}
if (++nfield == nkeys) {
size_t curpos = JSON_INPUT_POS(ins);
if ((ret = json_kvraw_append(ins,
(char *)ins->line.mem + ins->kvrawstart,
curpos - ins->kvrawstart)) != 0)
goto err;
ins->kvrawstart = curpos;
keystrlen = strlen(ins->kvraw);
}
if (json_peek(session, ins) != ',')
break;
JSON_EXPECT(session, ins, ',');
if (json_peek(session, ins) != 's')
goto err;
}
if (json_kvraw_append(ins, ins->line.mem, JSON_INPUT_POS(ins)))
goto err;
ins->kvraw[keystrlen] = '\0';
if (!LF_ISSET(LOAD_JSON_APPEND))
cursor->set_key(cursor, ins->kvraw);
/* skip over inserted space and comma */
cursor->set_value(cursor, &ins->kvraw[keystrlen+2]);
if ((ret = cursor->insert(cursor)) != 0) {
ret = util_err(ret, "%s: cursor.insert", uri);
goto err;
}
JSON_EXPECT(session, ins, '}');
if (json_peek(session, ins) != ',')
break;
JSON_EXPECT(session, ins, ',');
if (json_peek(session, ins) != '{')
goto err;
}
if (0) {
err: if (ret == 0)
ret = EINVAL;
}
/*
* Technically, we don't have to close the cursor because the session
* handle will do it for us, but I'd like to see the flush to disk and
* the close succeed, it's better to fail early when loading files.
*/
if (cursor != NULL && (tret = cursor->close(cursor)) != 0) {
tret = util_err(tret, "%s: cursor.close", uri);
if (ret == 0)
ret = tret;
}
if (ret == 0)
ret = util_flush(session, uri);
return (ret);
}
示例5:
int
transaction_ops(WT_CONNECTION *conn, WT_SESSION *session)
{
WT_CURSOR *cursor;
int ret;
/*! [transaction commit/rollback] */
ret =
session->open_cursor(session, "table:mytable", NULL, NULL, &cursor);
ret = session->begin_transaction(session, NULL);
/*
* Cursors may be opened before or after the transaction begins, and in
* either case, subsequent operations are included in the transaction.
* The begin_transaction call resets all open cursors.
*/
cursor->set_key(cursor, "key");
cursor->set_value(cursor, "value");
switch (ret = cursor->update(cursor)) {
case 0: /* Update success */
ret = session->commit_transaction(session, NULL);
/*
* The commit_transaction call resets all open cursors.
* If commit_transaction fails, the transaction was rolled-back.
*/
break;
case WT_DEADLOCK: /* Update conflict */
default: /* Other error */
ret = session->rollback_transaction(session, NULL);
/* The rollback_transaction call resets all open cursors. */
break;
}
/* Cursors remain open and may be used for multiple transactions. */
/*! [transaction commit/rollback] */
ret = cursor->close(cursor);
/*! [transaction isolation] */
/* A single transaction configured for snapshot isolation. */
ret =
session->open_cursor(session, "table:mytable", NULL, NULL, &cursor);
ret = session->begin_transaction(session, "isolation=snapshot");
cursor->set_key(cursor, "some-key");
cursor->set_value(cursor, "some-value");
ret = cursor->update(cursor);
ret = session->commit_transaction(session, NULL);
/*! [transaction isolation] */
/*! [session isolation configuration] */
/* Open a session configured for read-uncommitted isolation. */
ret = conn->open_session(
conn, NULL, "isolation=read_uncommitted", &session);
/*! [session isolation configuration] */
/*! [session isolation re-configuration] */
/* Re-configure a session for snapshot isolation. */
ret = session->reconfigure(session, "isolation=snapshot");
/*! [session isolation re-configuration] */
return (ret);
}
示例6:
int
transaction_ops(WT_CONNECTION *conn, WT_SESSION *session)
{
WT_CURSOR *cursor;
int ret;
/*! [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.
*/
ret =
session->open_cursor(session, "table:mytable", NULL, NULL, &cursor);
ret = session->begin_transaction(session, NULL);
cursor->set_key(cursor, "key");
cursor->set_value(cursor, "value");
switch (ret = cursor->update(cursor)) {
case 0: /* Update success */
ret = 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 */
ret = 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] */
ret = cursor->close(cursor);
/*! [transaction isolation] */
/* A single transaction configured for snapshot isolation. */
ret =
session->open_cursor(session, "table:mytable", NULL, NULL, &cursor);
ret = session->begin_transaction(session, "isolation=snapshot");
cursor->set_key(cursor, "some-key");
cursor->set_value(cursor, "some-value");
ret = cursor->update(cursor);
ret = session->commit_transaction(session, NULL);
/*! [transaction isolation] */
/*! [session isolation configuration] */
/* Open a session configured for read-uncommitted isolation. */
ret = conn->open_session(
conn, NULL, "isolation=read_uncommitted", &session);
/*! [session isolation configuration] */
/*! [session isolation re-configuration] */
/* Re-configure a session for snapshot isolation. */
ret = session->reconfigure(session, "isolation=snapshot");
/*! [session isolation re-configuration] */
{
/*! [transaction pinned range] */
/* Check the transaction ID range pinned by the session handle. */
uint64_t range;
ret = session->transaction_pinned_range(session, &range);
/*! [transaction pinned range] */
}
return (ret);
}
示例7: sizeof
/*
* Child process creates the database and table, and then writes data into
* the table until it is killed by the parent.
*/
static void
fill_db(void)
{
FILE *fp;
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_ITEM data;
WT_RAND_STATE rnd;
WT_SESSION *session;
uint64_t i;
int ret;
uint8_t buf[MAX_VAL];
__wt_random_init(&rnd);
memset(buf, 0, sizeof(buf));
/*
* Initialize the first 25% to random values. Leave a bunch of data
* space at the end to emphasize zero data.
*/
for (i = 0; i < MAX_VAL/4; i++)
buf[i] = (uint8_t)__wt_random(&rnd);
/*
* Run in the home directory so that the records file is in there too.
*/
chdir(home);
if ((ret = wiredtiger_open(NULL, NULL, ENV_CONFIG, &conn)) != 0)
testutil_die(ret, "wiredtiger_open");
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
testutil_die(ret, "WT_CONNECTION:open_session");
if ((ret = session->create(session,
uri, "key_format=Q,value_format=u")) != 0)
testutil_die(ret, "WT_SESSION.create: %s", uri);
if ((ret =
session->open_cursor(session, uri, NULL, NULL, &cursor)) != 0)
testutil_die(ret, "WT_SESSION.open_cursor: %s", uri);
/*
* Keep a separate file with the records we wrote for checking.
*/
(void)unlink(RECORDS_FILE);
if ((fp = fopen(RECORDS_FILE, "w")) == NULL)
testutil_die(errno, "fopen");
/*
* Set to no buffering.
*/
setvbuf(fp, NULL, _IONBF, 0);
/*
* Write data into the table until we are killed by the parent.
* The data in the buffer is already set to random content.
*/
data.data = buf;
for (i = 0;; ++i) {
data.size = __wt_random(&rnd) % MAX_VAL;
cursor->set_key(cursor, i);
cursor->set_value(cursor, &data);
if ((ret = cursor->insert(cursor)) != 0)
testutil_die(ret, "WT_CURSOR.insert");
/*
* Save the key separately for checking later.
*/
if (fprintf(fp, "%" PRIu64 "\n", i) == -1)
testutil_die(errno, "fprintf");
if (i % 5000)
__wt_yield();
}
}
示例8: sizeof
//.........这里部分代码省略.........
* Parent creates a database and table. Then cleanly shuts down.
* Then copy database to read-only directory and chmod.
* Also copy database to read-only directory and remove the lock
* file. One read-only database will have a lock file in the
* file system and the other will not.
* Parent opens all databases with read-only configuration flag.
* Parent forks off child who tries to also open all databases
* with the read-only flag. It should error on the writeable
* directory, but allow it on the read-only directories.
* The child then confirms it can read all the data.
*/
/*
* Run in the home directory and create the table.
*/
if ((ret = wiredtiger_open(home, NULL, ENV_CONFIG, &conn)) != 0)
testutil_die(ret, "wiredtiger_open");
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
testutil_die(ret, "WT_CONNECTION:open_session");
if ((ret = session->create(session,
uri, "key_format=Q,value_format=u")) != 0)
testutil_die(ret, "WT_SESSION.create: %s", uri);
if ((ret =
session->open_cursor(session, uri, NULL, NULL, &cursor)) != 0)
testutil_die(ret, "WT_SESSION.open_cursor: %s", uri);
/*
* Write data into the table and then cleanly shut down connection.
*/
memset(buf, 0, sizeof(buf));
data.data = buf;
data.size = MAX_VAL;
for (i = 0; i < MAX_KV; ++i) {
cursor->set_key(cursor, i);
cursor->set_value(cursor, &data);
if ((ret = cursor->insert(cursor)) != 0)
testutil_die(ret, "WT_CURSOR.insert");
}
if ((ret = conn->close(conn, NULL)) != 0)
testutil_die(ret, "WT_CONNECTION:close");
/*
* Copy the database. Remove any lock file from one copy
* and chmod the copies to be read-only permissions.
*/
(void)snprintf(cmd, sizeof(cmd),
"cp -rp %s/* %s; rm -f %s/WiredTiger.lock",
home, home_wr, home_wr);
if ((status = system(cmd)) < 0)
testutil_die(status, "system: %s", cmd);
(void)snprintf(cmd, sizeof(cmd),
"cp -rp %s/* %s; chmod 0555 %s; chmod -R 0444 %s/*",
home, home_rd, home_rd, home_rd);
if ((status = system(cmd)) < 0)
testutil_die(status, "system: %s", cmd);
(void)snprintf(cmd, sizeof(cmd),
"cp -rp %s/* %s; rm -f %s/WiredTiger.lock; "
"chmod 0555 %s; chmod -R 0444 %s/*",
home, home_rd2, home_rd2, home_rd2, home_rd2);
if ((status = system(cmd)) < 0)
testutil_die(status, "system: %s", cmd);
/*
* Run four scenarios. Sometimes expect errors, sometimes success.
* The writable database directories should always fail to allow the
示例9: 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);
}
示例10: if
static void
run(CONFIG *cp, int bigkey, size_t bytes)
{
WT_CONNECTION *conn;
WT_SESSION *session;
WT_CURSOR *cursor;
uint64_t keyno;
int ret;
void *p;
big[bytes - 1] = '\0';
printf(SIZET_FMT "%s%s: %s %s big %s\n",
bytes < MEGABYTE ? bytes :
(bytes < GIGABYTE ? bytes / MEGABYTE : bytes / GIGABYTE),
bytes < MEGABYTE ? "" :
(bytes < GIGABYTE ?
(bytes % MEGABYTE == 0 ? "" : "+") :
(bytes % GIGABYTE == 0 ? "" : "+")),
bytes < MEGABYTE ? "B" : (bytes < GIGABYTE ? "MB" : "GB"),
cp->uri, cp->config, bigkey ? "key" : "value");
testutil_make_work_dir(home);
/*
* Open/create the database, connection, session and cursor; set the
* cache size large, we don't want to try and evict anything.
*/
if ((ret = wiredtiger_open(
home, NULL, "create,cache_size=10GB", &conn)) != 0)
testutil_die(ret, "wiredtiger_open");
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
testutil_die(ret, "WT_CONNECTION.open_session");
if ((ret = session->create(session, cp->uri, cp->config)) != 0)
testutil_die(ret,
"WT_SESSION.create: %s %s", cp->uri, cp->config);
if ((ret =
session->open_cursor(session, cp->uri, NULL, NULL, &cursor)) != 0)
testutil_die(ret, "WT_SESSION.open_cursor: %s", cp->uri);
/* Set the key/value. */
if (bigkey)
cursor->set_key(cursor, big);
else if (cp->recno) {
keyno = 1;
cursor->set_key(cursor, keyno);
} else
cursor->set_key(cursor, "key001");
cursor->set_value(cursor, big);
/* Insert the record (use update, insert discards the key). */
if ((ret = cursor->update(cursor)) != 0)
testutil_die(ret, "WT_CURSOR.insert");
/* Retrieve the record and check it. */
if ((ret = cursor->search(cursor)) != 0)
testutil_die(ret, "WT_CURSOR.search");
if (bigkey && (ret = cursor->get_key(cursor, &p)) != 0)
testutil_die(ret, "WT_CURSOR.get_key");
if ((ret = cursor->get_value(cursor, &p)) != 0)
testutil_die(ret, "WT_CURSOR.get_value");
if (memcmp(p, big, bytes) != 0)
testutil_die(0,
"retrieved big key/value item did not match original");
/* Remove the record. */
if ((ret = cursor->remove(cursor)) != 0)
testutil_die(ret, "WT_CURSOR.remove");
if ((ret = conn->close(conn, NULL)) != 0)
testutil_die(ret, "WT_CONNECTION.close");
big[bytes - 1] = 'a';
}
示例11: calloc
void
worker(CONFIG *cfg, uint32_t worker_type)
{
WT_CONNECTION *conn;
WT_SESSION *session;
WT_CURSOR *cursor;
const char *op_name = "search";
char *data_buf, *key_buf, *value;
int ret, op_ret;
uint64_t next_val;
session = NULL;
data_buf = key_buf = NULL;
op_ret = 0;
conn = cfg->conn;
key_buf = calloc(cfg->key_sz + 1, 1);
if (key_buf == NULL) {
lprintf(cfg, ret = ENOMEM, 0, "Populate key buffer");
goto err;
}
if (worker_type == WORKER_INSERT) {
data_buf = calloc(cfg->data_sz, 1);
if (data_buf == NULL) {
lprintf(cfg, ret = ENOMEM, 0, "Populate data buffer");
goto err;
}
memset(data_buf, 'a', cfg->data_sz - 1);
}
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
lprintf(cfg, ret, 0,
"open_session failed in read thread");
goto err;
}
if ((ret = session->open_cursor(session, cfg->uri,
NULL, NULL, &cursor)) != 0) {
lprintf(cfg, ret, 0,
"open_cursor failed in read thread");
goto err;
}
while (g_running) {
/* Get a value in range, avoid zero. */
#define VALUE_RANGE (cfg->icount + g_nins_ops - (cfg->insert_threads + 1))
next_val = (worker_type == WORKER_INSERT ?
(cfg->icount + ATOMIC_ADD(g_nins_ops, 1)) :
((uint64_t)rand() % VALUE_RANGE) + 1);
/*
* If the workload is started without a populate phase we
* rely on at least one insert to get a valid item id.
*/
if (worker_type != WORKER_INSERT && VALUE_RANGE < next_val)
continue;
sprintf(key_buf, "%0*" PRIu64, cfg->key_sz, next_val);
cursor->set_key(cursor, key_buf);
switch(worker_type) {
case WORKER_READ:
op_name = "read";
op_ret = cursor->search(cursor);
if (op_ret == 0)
++g_nread_ops;
break;
case WORKER_INSERT:
op_name = "insert";
cursor->set_value(cursor, data_buf);
op_ret = cursor->insert(cursor);
if (op_ret != 0)
++g_nfailedins_ops;
break;
case WORKER_UPDATE:
op_name = "update";
op_ret = cursor->search(cursor);
if (op_ret == 0) {
cursor->get_value(cursor, &value);
if (value[0] == 'a')
value[0] = 'b';
else
value[0] = 'a';
op_ret = cursor->update(cursor);
}
if (op_ret == 0)
++g_nupdate_ops;
break;
default:
lprintf(cfg, EINVAL, 0, "Invalid worker type");
goto err;
}
/* Report errors and continue. */
if (op_ret != 0)
lprintf(cfg, op_ret, 0,
"%s failed for: %s", op_name, key_buf);
else
++g_nworker_ops;
}
err: if (ret != 0)
++g_threads_quit;
if (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:
//.........这里部分代码省略.........
error_check(session->create(
session, "table:old",
"key_format=r,value_format=S,cache_resident=true"));
/*! [Rename a table] */
error_check(session->rename(session, "table:old", "table:new", NULL));
/*! [Rename a table] */
/*! [Salvage a table] */
error_check(session->salvage(session, "table:mytable", NULL));
/*! [Salvage a table] */
/*! [Truncate a table] */
error_check(session->truncate(
session, "table:mytable", NULL, NULL, NULL));
/*! [Truncate a table] */
/*! [Transaction sync] */
error_check(session->transaction_sync(session, NULL));
/*! [Transaction sync] */
/*! [Reset the session] */
error_check(session->reset(session));
/*! [Reset the session] */
{
/*
* Insert a pair of keys so we can truncate a range.
*/
WT_CURSOR *cursor;
error_check(session->open_cursor(
session, "table:mytable", NULL, NULL, &cursor));
cursor->set_key(cursor, "June01");
cursor->set_value(cursor, "value");
error_check(cursor->update(cursor));
cursor->set_key(cursor, "June30");
cursor->set_value(cursor, "value");
error_check(cursor->update(cursor));
error_check(cursor->close(cursor));
{
/*! [Truncate a range] */
WT_CURSOR *start, *stop;
error_check(session->open_cursor(
session, "table:mytable", NULL, NULL, &start));
start->set_key(start, "June01");
error_check(start->search(start));
error_check(session->open_cursor(
session, "table:mytable", NULL, NULL, &stop));
stop->set_key(stop, "June30");
error_check(stop->search(stop));
error_check(session->truncate(session, NULL, start, stop, NULL));
/*! [Truncate a range] */
error_check(stop->close(stop));
error_check(start->close(start));
}
}
/*! [Upgrade a table] */
error_check(session->upgrade(session, "table:mytable", NULL));
/*! [Upgrade a table] */
/*! [Verify a table] */
示例14: strlen
static int
cursor_ops(WT_SESSION *session)
{
WT_CURSOR *cursor;
int ret;
/*! [Open a cursor] */
error_check(session->open_cursor(
session, "table:mytable", NULL, NULL, &cursor));
/*! [Open a cursor] */
/*! [Open a cursor on the metadata] */
error_check(session->open_cursor(
session, "metadata:", NULL, NULL, &cursor));
/*! [Open a cursor on the metadata] */
{
const char *key = "some key", *value = "some value";
/*! [Reconfigure a cursor] */
error_check(session->open_cursor(
session, "table:mytable", NULL, "overwrite=false", &cursor));
/* Reconfigure the cursor to overwrite the record. */
error_check(cursor->reconfigure(cursor, "overwrite=true"));
cursor->set_key(cursor, key);
cursor->set_value(cursor, value);
error_check(cursor->insert(cursor));
/*! [Reconfigure a cursor] */
}
{
WT_CURSOR *duplicate;
const char *key = "some key";
/*! [Duplicate a cursor] */
error_check(session->open_cursor(
session, "table:mytable", NULL, NULL, &cursor));
cursor->set_key(cursor, key);
error_check(cursor->search(cursor));
/* Duplicate the cursor. */
error_check(
session->open_cursor(session, NULL, cursor, NULL, &duplicate));
/*! [Duplicate a cursor] */
}
{
/*! [boolean configuration string example] */
error_check(session->open_cursor(
session, "table:mytable", NULL, "overwrite", &cursor));
error_check(session->open_cursor(
session, "table:mytable", NULL, "overwrite=true", &cursor));
error_check(session->open_cursor(
session, "table:mytable", NULL, "overwrite=1", &cursor));
/*! [boolean configuration string example] */
}
error_check(session->checkpoint(session, "name=midnight"));
{
/*! [open a named checkpoint] */
error_check(session->open_cursor(session,
"table:mytable", NULL, "checkpoint=midnight", &cursor));
/*! [open a named checkpoint] */
}
{
/*! [open the default checkpoint] */
error_check(session->open_cursor(session,
"table:mytable", NULL, "checkpoint=WiredTigerCheckpoint", &cursor));
/*! [open the default checkpoint] */
}
{
/*! [Set the cursor's string key] */
/* Set the cursor's string key. */
const char *key = "another key";
cursor->set_key(cursor, key);
/*! [Set the cursor's string key] */
}
{
/*! [Get the cursor's string key] */
const char *key; /* Get the cursor's string key. */
error_check(cursor->get_key(cursor, &key));
/*! [Get the cursor's string key] */
}
/* Switch to a recno table. */
error_check(session->create(
session, "table:recno", "key_format=r,value_format=S"));
error_check(session->open_cursor(
session, "table:recno", NULL, NULL, &cursor));
{
/*! [Set the cursor's record number key] */
uint64_t recno = 37; /* Set the cursor's record number key. */
cursor->set_key(cursor, recno);
/*! [Set the cursor's record number key] */
}
//.........这里部分代码省略.........
示例15:
void
wts_load(void)
{
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_ITEM key, value;
WT_SESSION *session;
uint8_t *keybuf, *valbuf;
int is_bulk, ret;
conn = g.wts_conn;
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
die(ret, "connection.open_session");
if (g.logging != 0)
(void)g.wt_api->msg_printf(g.wt_api, session,
"=============== bulk load start ===============");
/*
* Avoid bulk load with KVS (there's no bulk load support for a
* data-source); avoid bulk load with a custom collator, because
* the order of insertion will not match the collation order.
*/
is_bulk = !g.c_reverse &&
!DATASOURCE("kvsbdb") && !DATASOURCE("helium");
if ((ret = session->open_cursor(session, g.uri, NULL,
is_bulk ? "bulk" : NULL, &cursor)) != 0)
die(ret, "session.open_cursor");
/* Set up the default key buffer. */
key_gen_setup(&keybuf);
val_gen_setup(&valbuf);
for (;;) {
if (++g.key_cnt > g.c_rows) {
g.key_cnt = g.rows = g.c_rows;
break;
}
/* Report on progress every 100 inserts. */
if (g.key_cnt % 100 == 0)
track("bulk load", g.key_cnt, NULL);
key_gen(keybuf, &key.size, (uint64_t)g.key_cnt, 0);
key.data = keybuf;
value_gen(valbuf, &value.size, (uint64_t)g.key_cnt);
value.data = valbuf;
switch (g.type) {
case FIX:
if (!is_bulk)
cursor->set_key(cursor, g.key_cnt);
cursor->set_value(cursor, *(uint8_t *)value.data);
if (g.logging == LOG_OPS)
(void)g.wt_api->msg_printf(g.wt_api, session,
"%-10s %" PRIu32 " {0x%02" PRIx8 "}",
"bulk V",
g.key_cnt, ((uint8_t *)value.data)[0]);
break;
case VAR:
if (!is_bulk)
cursor->set_key(cursor, g.key_cnt);
cursor->set_value(cursor, &value);
if (g.logging == LOG_OPS)
(void)g.wt_api->msg_printf(g.wt_api, session,
"%-10s %" PRIu32 " {%.*s}", "bulk V",
g.key_cnt,
(int)value.size, (char *)value.data);
break;
case ROW:
cursor->set_key(cursor, &key);
if (g.logging == LOG_OPS)
(void)g.wt_api->msg_printf(g.wt_api, session,
"%-10s %" PRIu32 " {%.*s}", "bulk K",
g.key_cnt, (int)key.size, (char *)key.data);
cursor->set_value(cursor, &value);
if (g.logging == LOG_OPS)
(void)g.wt_api->msg_printf(g.wt_api, session,
"%-10s %" PRIu32 " {%.*s}", "bulk V",
g.key_cnt,
(int)value.size, (char *)value.data);
break;
}
if ((ret = cursor->insert(cursor)) != 0)
die(ret, "cursor.insert");
if (!SINGLETHREADED)
continue;
/* Insert the item into BDB. */
bdb_insert(key.data, key.size, value.data, value.size);
}
if ((ret = cursor->close(cursor)) != 0)
die(ret, "cursor.close");
if (g.logging != 0)
(void)g.wt_api->msg_printf(g.wt_api, session,
//.........这里部分代码省略.........