本文整理汇总了C++中WT_SESSION类的典型用法代码示例。如果您正苦于以下问题:C++ WT_SESSION类的具体用法?C++ WT_SESSION怎么用?C++ WT_SESSION使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WT_SESSION类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_checkpoints
/*
* Function for repeatedly running checkpoint operations.
*/
static WT_THREAD_RET
do_checkpoints(void *_opts)
{
TEST_OPTS *opts;
WT_SESSION *session;
time_t now, start;
int ret;
opts = (TEST_OPTS *)_opts;
(void)time(&start);
(void)time(&now);
while (difftime(now, start) < RUNTIME) {
testutil_check(
opts->conn->open_session(opts->conn, NULL, NULL, &session));
if ((ret = session->checkpoint(session, "force")) != 0)
if (ret != EBUSY && ret != ENOENT)
testutil_die(ret, "session.checkpoint");
testutil_check(session->close(session, NULL));
/*
* A short sleep to let operations process and avoid back to
* back checkpoints locking up resources.
*/
sleep(1);
(void)time(&now);
}
return (WT_THREAD_RET_VALUE);
}
示例2: session
Status WiredTigerKVEngine::repairIdent( OperationContext* opCtx,
const StringData& ident ) {
WiredTigerSession session( _conn, -1 );
WT_SESSION* s = session.getSession();
string uri = _uri(ident);
return wtRCToStatus( s->compact(s, uri.c_str(), NULL ) );
}
示例3: op_cursor
/*
* Open and close cursor on a table.
*/
void
op_cursor(void *arg)
{
TEST_OPTS *opts;
TEST_PER_THREAD_OPTS *args;
WT_CURSOR *cursor;
WT_SESSION *session;
int i, ret;
args = (TEST_PER_THREAD_OPTS *)arg;
opts = args->testopts;
testutil_check(
opts->conn->open_session(opts->conn, NULL, NULL, &session));
if ((ret = session->open_cursor(
session, opts->uri, NULL, NULL, &cursor)) != 0) {
if (ret != ENOENT && ret != EBUSY)
testutil_die(ret, "session.open_cursor");
} else {
/* Put some data in if asked to. */
if (args->testopts->do_data_ops) {
for (i = 0; i < 1000; i++) {
cursor->set_key(cursor, i);
cursor->set_value(cursor, "abcdef");
cursor->insert(cursor);
}
}
testutil_check(cursor->close(cursor));
}
testutil_check(session->close(session, NULL));
args->thread_counter++;
}
示例4: op_bulk
/*
* Create a table and open a bulk cursor on it.
*/
void
op_bulk(void *arg)
{
TEST_OPTS *opts;
TEST_PER_THREAD_OPTS *args;
WT_CURSOR *c;
WT_SESSION *session;
int ret;
args = (TEST_PER_THREAD_OPTS *)arg;
opts = args->testopts;
testutil_check(
opts->conn->open_session(opts->conn, NULL, NULL, &session));
if ((ret = session->create(session,
opts->uri, DEFAULT_TABLE_SCHEMA)) != 0)
if (ret != EEXIST && ret != EBUSY)
testutil_die(ret, "session.create");
if (ret == 0) {
__wt_yield();
if ((ret = session->open_cursor(session,
opts->uri, NULL, "bulk,checkpoint_wait=false", &c)) == 0) {
testutil_check(c->close(c));
} else if (ret != ENOENT && ret != EBUSY && ret != EINVAL)
testutil_die(ret, "session.open_cursor bulk");
}
testutil_check(session->close(session, NULL));
args->thread_counter++;
}
示例5: newCappedRecordStore
virtual RecordStore* newCappedRecordStore( const std::string& ns,
int64_t cappedMaxSize,
int64_t cappedMaxDocs ) {
WiredTigerRecoveryUnit* ru = new WiredTigerRecoveryUnit( _sessionCache );
OperationContextNoop txn( ru );
string uri = "table:a.b";
CollectionOptions options;
options.capped = true;
StatusWith<std::string> result =
WiredTigerRecordStore::generateCreateString(ns, options, "");
ASSERT_TRUE(result.isOK());
std::string config = result.getValue();
{
WriteUnitOfWork uow(&txn);
WT_SESSION* s = ru->getSession()->getSession();
invariantWTOK( s->create( s, uri.c_str(), config.c_str() ) );
uow.commit();
}
return new WiredTigerRecordStore( &txn, ns, uri, true, cappedMaxSize, cappedMaxDocs );
}
示例6: main
/*! [thread main] */
int
main(void)
{
WT_SESSION *session;
WT_CURSOR *cursor;
pthread_t threads[NUM_THREADS];
int i, ret;
if ((ret = wiredtiger_open(home, NULL,
"create", &conn)) != 0)
fprintf(stderr, "Error connecting to %s: %s\n",
home, wiredtiger_strerror(ret));
/* Note: further error checking omitted for clarity. */
ret = conn->open_session(conn, NULL, NULL, &session);
ret = session->create(session, "table:access",
"key_format=S,value_format=S");
ret = session->open_cursor(session, "table:access", NULL,
"overwrite", &cursor);
cursor->set_key(cursor, "key1");
cursor->set_value(cursor, "value1");
ret = cursor->insert(cursor);
ret = session->close(session, NULL);
for (i = 0; i < NUM_THREADS; i++)
ret = pthread_create(&threads[i], NULL, scan_thread, NULL);
for (i = 0; i < NUM_THREADS; i++)
ret = pthread_join(threads[i], NULL);
ret = conn->close(conn, NULL);
return (ret);
}
示例7: obj_bulk
void
obj_bulk(void)
{
WT_CURSOR *c;
WT_SESSION *session;
int ret;
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
testutil_die(ret, "conn.session");
if ((ret = session->create(session, uri, config)) != 0)
if (ret != EEXIST && ret != EBUSY)
testutil_die(ret, "session.create");
if (ret == 0) {
__wt_yield();
if ((ret = session->open_cursor(
session, uri, NULL, "bulk", &c)) == 0) {
if ((ret = c->close(c)) != 0)
testutil_die(ret, "cursor.close");
} else if (ret != ENOENT && ret != EBUSY && ret != EINVAL)
testutil_die(ret, "session.open_cursor bulk");
}
if ((ret = session->close(session, NULL)) != 0)
testutil_die(ret, "session.close");
}
示例8: scan_thread
/*! [thread scan] */
void *
scan_thread(void *conn_arg)
{
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_SESSION *session;
const char *key, *value;
int ret;
conn = conn_arg;
ret = conn->open_session(conn, NULL, NULL, &session);
ret = session->open_cursor(
session, "table:access", NULL, NULL, &cursor);
/* Show all records. */
while ((ret = cursor->next(cursor)) == 0) {
ret = cursor->get_key(cursor, &key);
ret = cursor->get_value(cursor, &value);
printf("Got record: %s : %s\n", key, value);
}
if (ret != WT_NOTFOUND)
fprintf(stderr,
"WT_CURSOR.next: %s\n", session->strerror(session, ret));
return (NULL);
}
示例9: obj_create_unique
void
obj_create_unique(int force)
{
WT_SESSION *session;
int ret;
char new_uri[64];
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
testutil_die(ret, "conn.session");
/* Generate a unique object name. */
if ((ret = pthread_rwlock_wrlock(&single)) != 0)
testutil_die(ret, "pthread_rwlock_wrlock single");
testutil_check(__wt_snprintf(
new_uri, sizeof(new_uri), "%s.%u", uri, ++uid));
if ((ret = pthread_rwlock_unlock(&single)) != 0)
testutil_die(ret, "pthread_rwlock_unlock single");
if ((ret = session->create(session, new_uri, config)) != 0)
testutil_die(ret, "session.create");
__wt_yield();
while ((ret = session->drop(
session, new_uri, force ? "force" : NULL)) != 0)
if (ret != EBUSY)
testutil_die(ret, "session.drop: %s", new_uri);
if ((ret = session->close(session, NULL)) != 0)
testutil_die(ret, "session.close");
}
示例10: main
int
main(int argc, char *argv[])
{
WT_SESSION *session;
clock_t ce, cs;
pthread_t idlist[100];
uint64_t i, id;
char buf[100];
opts = &_opts;
memset(opts, 0, sizeof(*opts));
opts->table_type = TABLE_ROW;
opts->n_append_threads = N_APPEND_THREADS;
opts->nrecords = N_RECORDS;
testutil_check(testutil_parse_opts(argc, argv, opts));
testutil_make_work_dir(opts->home);
snprintf(buf, sizeof(buf),
"create,"
"cache_size=%s,"
"eviction=(threads_max=5),"
"statistics=(fast)",
opts->table_type == TABLE_FIX ? "500MB" : "2GB");
testutil_check(wiredtiger_open(opts->home, NULL, buf, &opts->conn));
testutil_check(
opts->conn->open_session(opts->conn, NULL, NULL, &session));
snprintf(buf, sizeof(buf),
"key_format=r,value_format=%s,"
"allocation_size=4K,leaf_page_max=64K",
opts->table_type == TABLE_FIX ? "8t" : "S");
testutil_check(session->create(session, opts->uri, buf));
testutil_check(session->close(session, NULL));
page_init(5000);
/* Force to disk and re-open. */
testutil_check(opts->conn->close(opts->conn, NULL));
testutil_check(wiredtiger_open(opts->home, NULL, NULL, &opts->conn));
(void)signal(SIGINT, onsig);
cs = clock();
id = 0;
for (i = 0; i < opts->n_append_threads; ++i, ++id) {
printf("append: %" PRIu64 "\n", id);
testutil_check(pthread_create(
&idlist[id], NULL, thread_append, (void *)opts));
}
for (i = 0; i < id; ++i)
testutil_check(pthread_join(idlist[i], NULL));
ce = clock();
printf("%" PRIu64 "M records: %.2lf processor seconds\n",
opts->max_inserted_id / MILLION,
(ce - cs) / (double)CLOCKS_PER_SEC);
testutil_cleanup(opts);
return (EXIT_SUCCESS);
}
示例11: sweep_stats
static void
sweep_stats(void)
{
static const int list[] = {
WT_STAT_CONN_CURSOR_SWEEP_BUCKETS,
WT_STAT_CONN_CURSOR_SWEEP_CLOSED,
WT_STAT_CONN_CURSOR_SWEEP_EXAMINED,
WT_STAT_CONN_CURSOR_SWEEP,
WT_STAT_CONN_DH_SWEEP_REF,
WT_STAT_CONN_DH_SWEEP_CLOSE,
WT_STAT_CONN_DH_SWEEP_REMOVE,
WT_STAT_CONN_DH_SWEEP_TOD,
WT_STAT_CONN_DH_SWEEPS,
WT_STAT_CONN_DH_SESSION_SWEEPS,
-1
};
WT_SESSION *session;
WT_CURSOR *cursor;
uint64_t value;
int i;
const char *desc, *pvalue;
testutil_check(conn->open_session(conn, NULL, NULL, &session));
testutil_check(session->open_cursor(
session, "statistics:", NULL, NULL, &cursor));
for (i = 0;; ++i) {
if (list[i] == -1)
break;
cursor->set_key(cursor, list[i]);
testutil_check(cursor->search(cursor));
testutil_check(
cursor->get_value(cursor, &desc, &pvalue, &value));
printf("\t" "%s=%s\n", desc, pvalue);
}
}
示例12: check_copy
/*
* check_copy --
* Confirm the hot backup worked.
*/
static void
check_copy(void)
{
WT_CONNECTION *conn;
WT_SESSION *session;
int ret;
wts_open(RUNDIR_BACKUP, 0, &conn);
/*
* Open a session and verify the store; some data-sources don't support
* verify.
*
* XXX
* LSM can deadlock if WT_SESSION methods are called at the wrong time,
* don't do that for now.
*/
if (!DATASOURCE("lsm") && !DATASOURCE("memrata")) {
if ((ret = conn->open_session(
conn, NULL, NULL, &session)) != 0)
die(ret, "connection.open_session");
if ((ret = session->verify(session, g.uri, NULL)) != 0)
die(ret, "session.verify: %s", g.uri);
}
if ((ret = conn->close(conn, NULL)) != 0)
die(ret, "connection.close: %s", RUNDIR_BACKUP);
}
示例13: indexInsert
bool indexInsert(size_t indexId, fstring key, llong recId) override {
assert(started == m_status);
assert(indexId < m_indices.size());
WT_ITEM item;
WT_SESSION* ses = m_session.ses;
const Schema& schema = m_sconf.getIndexSchema(indexId);
WT_CURSOR* cur = m_indices[indexId].insert;
WtWritableIndex::setKeyVal(schema, cur, key, recId, &item, &m_wrtBuf);
int err = cur->insert(cur);
m_sizeDiff += sizeof(llong) + key.size();
if (schema.m_isUnique) {
if (WT_DUPLICATE_KEY == err) {
return false;
}
if (err) {
THROW_STD(invalid_argument
, "ERROR: wiredtiger insert unique index: %s", ses->strerror(ses, err));
}
}
else {
if (WT_DUPLICATE_KEY == err) {
assert(0); // assert in debug
return true; // ignore in release
}
if (err) {
THROW_STD(invalid_argument
, "ERROR: wiredtiger insert multi index: %s", ses->strerror(ses, err));
}
}
return true;
}
示例14: find_table_count
/*
* Ensure that icount matches the number of records in the
* existing table.
*/
int find_table_count(CONFIG *cfg)
{
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_SESSION *session;
char *key;
int ret;
conn = cfg->conn;
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
lprintf(cfg, ret, 0,
"open_session failed finding existing table count");
goto err;
}
if ((ret = session->open_cursor(session, cfg->uri,
NULL, NULL, &cursor)) != 0) {
lprintf(cfg, ret, 0,
"open_cursor failed finding existing table count");
goto err;
}
if ((ret = cursor->prev(cursor)) != 0) {
lprintf(cfg, ret, 0,
"cursor prev failed finding existing table count");
goto err;
}
cursor->get_key(cursor, &key);
cfg->icount = (uint32_t)atoi(key);
err: session->close(session, NULL);
return (ret);
}
示例15: page_init
static void
page_init(uint64_t n)
{
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_SESSION *session;
uint64_t recno, vrecno;
char buf[64];
conn = opts->conn;
testutil_check(conn->open_session(conn, NULL, NULL, &session));
testutil_check(
session->open_cursor(session, opts->uri, NULL, "append", &cursor));
vrecno = 0;
buf[0] = '\2';
for (recno = 1;; ++recno) {
if (opts->table_type == TABLE_FIX)
cursor->set_value(cursor, buf[0]);
else {
if (recno % 3 == 0)
++vrecno;
testutil_check(__wt_snprintf(buf,
sizeof(buf), "%" PRIu64 " VALUE ------", vrecno));
cursor->set_value(cursor, buf);
}
testutil_check(cursor->insert(cursor));
testutil_check(cursor->get_key(cursor, &opts->max_inserted_id));
if (opts->max_inserted_id >= n)
break;
}
}