本文整理汇总了C++中WT_CURSOR::next方法的典型用法代码示例。如果您正苦于以下问题:C++ WT_CURSOR::next方法的具体用法?C++ WT_CURSOR::next怎么用?C++ WT_CURSOR::next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WT_CURSOR
的用法示例。
在下文中一共展示了WT_CURSOR::next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*
* __recovery_file_scan --
* Scan the files referenced from the metadata and gather information
* about them for recovery.
*/
static int
__recovery_file_scan(WT_RECOVERY *r)
{
WT_CURSOR *c;
WT_DECL_RET;
int cmp;
const char *uri, *config;
/* Scan through all files in the metadata. */
c = r->files[0].c;
c->set_key(c, "file:");
if ((ret = c->search_near(c, &cmp)) != 0) {
/* Is the metadata empty? */
WT_RET_NOTFOUND_OK(ret);
return (0);
}
if (cmp < 0)
WT_RET_NOTFOUND_OK(c->next(c));
for (; ret == 0; ret = c->next(c)) {
WT_RET(c->get_key(c, &uri));
if (!WT_PREFIX_MATCH(uri, "file:"))
break;
WT_RET(c->get_value(c, &config));
WT_RET(__recovery_setup_file(r, uri, config));
}
WT_RET_NOTFOUND_OK(ret);
return (0);
}
示例2:
/*
* wts_stats --
* Dump the run's statistics.
*/
void
wts_stats(void)
{
WT_CONNECTION *conn;
WT_CURSOR *cursor;
WT_SESSION *session;
FILE *fp;
const char *pval, *desc;
uint64_t v;
int ret;
track("stat", 0ULL, NULL);
conn = g.wts_conn;
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
die(ret, "connection.open_session");
if ((fp = fopen("__stats", "w")) == NULL)
die(errno, "fopen: __stats");
/* Connection statistics. */
if ((ret = session->open_cursor(session,
"statistics:", NULL, NULL, &cursor)) != 0)
die(ret, "session.open_cursor");
while ((ret = cursor->next(cursor)) == 0 &&
(ret = cursor->get_value(cursor, &desc, &pval, &v)) == 0)
if (fprintf(fp, "%s=%s\n", desc, pval) < 0)
die(errno, "fprintf");
if (ret != WT_NOTFOUND)
die(ret, "cursor.next");
if ((ret = cursor->close(cursor)) != 0)
die(ret, "cursor.close");
/* File statistics. */
if ((ret = session->open_cursor(session,
"statistics:" WT_TABLENAME, NULL, NULL, &cursor)) != 0)
die(ret, "session.open_cursor");
while ((ret = cursor->next(cursor)) == 0 &&
(ret = cursor->get_value(cursor, &desc, &pval, &v)) == 0)
if (fprintf(fp, "%s=%s\n", desc, pval) < 0)
die(errno, "fprintf");
if (ret != WT_NOTFOUND)
die(ret, "cursor.next");
if ((ret = cursor->close(cursor)) != 0)
die(ret, "cursor.close");
if ((ret = fclose(fp)) != 0)
die(ret, "fclose");
if ((ret = session->close(session, NULL)) != 0)
die(ret, "session.close");
}
示例3: if
/*
* __wt_meta_btree_apply --
* Apply a function to all files listed in the metadata, apart from the
* metadata file.
*/
int
__wt_meta_btree_apply(WT_SESSION_IMPL *session,
int (*func)(WT_SESSION_IMPL *, const char *[]), const char *cfg[])
{
WT_CURSOR *cursor;
WT_DATA_HANDLE *saved_dhandle;
WT_DECL_RET;
const char *uri;
int cmp, tret;
saved_dhandle = session->dhandle;
WT_RET(__wt_metadata_cursor(session, NULL, &cursor));
cursor->set_key(cursor, "file:");
if ((tret = cursor->search_near(cursor, &cmp)) == 0 && cmp < 0)
tret = cursor->next(cursor);
for (; tret == 0; tret = cursor->next(cursor)) {
WT_ERR(cursor->get_key(cursor, &uri));
if (!WT_PREFIX_MATCH(uri, "file:"))
break;
else if (strcmp(uri, WT_METAFILE_URI) == 0)
continue;
/*
* We need to pull the handle into the session handle cache
* and make sure it's referenced to stop other internal code
* dropping the handle (e.g in LSM when cleaning up obsolete
* chunks). Holding the metadata lock isn't enough.
*/
ret = __wt_session_get_btree(session, uri, NULL, NULL, 0);
if (ret == 0) {
WT_SAVE_DHANDLE(session,
ret = func(session, cfg));
if (WT_META_TRACKING(session))
WT_TRET(
__wt_meta_track_handle_lock(session, 0));
else
WT_TRET(__wt_session_release_btree(session));
} else if (ret == EBUSY)
ret = __wt_conn_btree_apply_single(
session, uri, NULL, func, cfg);
WT_ERR(ret);
}
if (tret != WT_NOTFOUND)
WT_TRET(tret);
err: WT_TRET(cursor->close(cursor));
session->dhandle = saved_dhandle;
return (ret);
}
示例4: if
/*
* __clsm_next --
* WT_CURSOR->next method for the LSM cursor type.
*/
static int
__clsm_next(WT_CURSOR *cursor)
{
WT_CURSOR_LSM *clsm;
WT_CURSOR *c;
WT_DECL_RET;
WT_SESSION_IMPL *session;
u_int i;
int cmp;
bool check, deleted;
clsm = (WT_CURSOR_LSM *)cursor;
CURSOR_API_CALL(cursor, session, next, NULL);
WT_CURSOR_NOVALUE(cursor);
WT_ERR(__clsm_enter(clsm, false, false));
/* If we aren't positioned for a forward scan, get started. */
if (clsm->current == NULL || !F_ISSET(clsm, WT_CLSM_ITERATE_NEXT)) {
F_CLR(clsm, WT_CLSM_MULTIPLE);
WT_FORALL_CURSORS(clsm, c, i) {
if (!F_ISSET(cursor, WT_CURSTD_KEY_SET)) {
WT_ERR(c->reset(c));
ret = c->next(c);
} else if (c != clsm->current) {
c->set_key(c, &cursor->key);
if ((ret = c->search_near(c, &cmp)) == 0) {
if (cmp < 0)
ret = c->next(c);
else if (cmp == 0) {
if (clsm->current == NULL)
clsm->current = c;
else
F_SET(clsm,
WT_CLSM_MULTIPLE);
}
} else
F_CLR(c, WT_CURSTD_KEY_SET);
}
WT_ERR_NOTFOUND_OK(ret);
}
F_SET(clsm, WT_CLSM_ITERATE_NEXT);
F_CLR(clsm, WT_CLSM_ITERATE_PREV);
/* We just positioned *at* the key, now move. */
if (clsm->current != NULL)
goto retry;
} else {
示例5:
static void
write_and_read_new(WT_SESSION *session)
{
WT_CURSOR *logc;
WT_ITEM logrec_key, logrec_value;
uint64_t txnid;
uint32_t fileid, log_file, log_offset, opcount, optype, rectype;
bool saw_msg;
/*
* Write a log record and force it to disk so we can read it.
*/
printf("Write log_printf record and verify.\n");
testutil_check(session->log_printf(session, "Test Log Record"));
testutil_check(session->log_flush(session, "sync=on"));
testutil_check(
session->open_cursor(session, "log:", NULL, NULL, &logc));
testutil_check(
session->open_cursor(session, "log:", NULL, NULL, &logc));
saw_msg = false;
while (logc->next(logc) == 0) {
/*
* We don't really need to get the key, but in case we want
* the LSN for some message, get it.
*/
testutil_check(logc->get_key(
logc, &log_file, &log_offset, &opcount));
testutil_check(logc->get_value(logc, &txnid,
&rectype, &optype, &fileid, &logrec_key, &logrec_value));
/*
* We should never see a record from us in log file 2. We wrote
* a record there, but then the record in log file 1 was
* truncated to be a partial record, ending the log there.
* So everything after that, including everything in log
* file 2, is invalid until we get to log file 3 which is where
* the post-recovery records will be written.
* The one exception in log file two is the system record for
* the previous log file's LSN. Although it is written by the
* system, we do walk it when using a cursor.
*/
if (log_file == 2 && rectype != WT_LOGREC_SYSTEM)
testutil_die(EINVAL, "Found LSN in Log 2");
#if 0
printf("LSN [%" PRIu32 "][%" PRIu32 "].%" PRIu32
": record type %" PRIu32 " optype %" PRIu32
" txnid %" PRIu64 " fileid %" PRIu32 "\n",
log_file, log_offset, opcount,
rectype, optype, txnid, fileid);
#endif
if (rectype == WT_LOGREC_MESSAGE) {
saw_msg = true;
printf("Application Record: %s\n",
(char *)logrec_value.data);
break;
}
}
testutil_check(logc->close(logc));
if (!saw_msg)
testutil_die(EINVAL, "Did not traverse log printf record");
}
示例6:
/*! [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);
}
示例7: fetchStats
void WiredTigerOperationStats::fetchStats(WT_SESSION* session,
const std::string& uri,
const std::string& config) {
invariant(session);
WT_CURSOR* c = nullptr;
const char* cursorConfig = config.empty() ? nullptr : config.c_str();
int ret = session->open_cursor(session, uri.c_str(), nullptr, cursorConfig, &c);
uassert(ErrorCodes::CursorNotFound, "Unable to open statistics cursor", ret == 0);
invariant(c);
ON_BLOCK_EXIT([&] { c->close(c); });
const char* desc;
uint64_t value;
uint64_t key;
while (c->next(c) == 0 && c->get_key(c, &key) == 0) {
fassert(51035, c->get_value(c, &desc, nullptr, &value) == 0);
#if defined(__s390x__)
_stats[key >> 32] = WiredTigerUtil::castStatisticsValue<long long>(value);
#else
_stats[key] = WiredTigerUtil::castStatisticsValue<long long>(value);
#endif // __s390x__
}
// Reset the statistics so that the next fetch gives the recent values.
invariantWTOK(c->reset(c));
}
示例8:
/*
* simple_walk_log --
* A simple walk of the log.
*/
static int
simple_walk_log(WT_SESSION *session)
{
WT_CURSOR *cursor;
WT_LSN lsn;
WT_ITEM logrec_key, logrec_value;
uint64_t txnid;
uint32_t fileid, opcount, optype, rectype;
int ret;
/*! [log cursor open] */
ret = session->open_cursor(session, "log:", NULL, NULL, &cursor);
/*! [log cursor open] */
while ((ret = cursor->next(cursor)) == 0) {
/*! [log cursor get_key] */
ret = cursor->get_key(cursor, &lsn.file, &lsn.offset, &opcount);
/*! [log cursor get_key] */
/*! [log cursor get_value] */
ret = cursor->get_value(cursor, &txnid,
&rectype, &optype, &fileid, &logrec_key, &logrec_value);
/*! [log cursor get_value] */
print_record(&lsn, opcount,
rectype, optype, txnid, fileid, &logrec_key, &logrec_value);
}
if (ret == WT_NOTFOUND)
ret = 0;
ret = cursor->close(cursor);
return (ret);
}
示例9:
/*
* __curindex_search_near --
* WT_CURSOR->search_near method for index cursors.
*/
static int
__curindex_search_near(WT_CURSOR *cursor, int *exact)
{
WT_CURSOR *child;
WT_CURSOR_INDEX *cindex;
WT_DECL_RET;
WT_ITEM found_key;
WT_SESSION_IMPL *session;
int cmp;
cindex = (WT_CURSOR_INDEX *)cursor;
child = cindex->child;
JOINABLE_CURSOR_API_CALL(cursor, session, search, NULL);
/*
* We are searching using the application-specified key, which
* (usually) doesn't contain the primary key, so it is just a prefix of
* any matching index key. That said, if there is an exact match, we
* want to find the first matching index entry and set exact equal to
* zero.
*
* Do a search_near, and if we find an entry that is too small, step to
* the next one. In the unlikely event of a search past the end of the
* tree, go back to the last key.
*/
__wt_cursor_set_raw_key(child, &cursor->key);
WT_ERR(child->search_near(child, &cmp));
if (cmp < 0) {
if ((ret = child->next(child)) == WT_NOTFOUND)
ret = child->prev(child);
WT_ERR(ret);
}
/*
* We expect partial matches, and want the smallest record with a key
* greater than or equal to the search key.
*
* If the found key starts with the search key, we indicate a match by
* setting exact equal to zero.
*
* The compare function expects application-supplied keys to come first
* so we flip the sign of the result to match what callers expect.
*/
found_key = child->key;
if (found_key.size > cursor->key.size)
found_key.size = cursor->key.size;
WT_ERR(__wt_compare(
session, cindex->index->collator, &cursor->key, &found_key, exact));
*exact = -*exact;
WT_ERR(__curindex_move(cindex));
if (0) {
err: F_CLR(cursor, WT_CURSTD_KEY_INT | WT_CURSTD_VALUE_INT);
}
API_END_RET(session, ret);
}
示例10:
/*
* simple_walk_log --
* A simple walk of the write-ahead log.
* We wrote text messages into the log. Print them.
* This verifies we're decrypting properly.
*/
static void
simple_walk_log(WT_SESSION *session)
{
WT_CURSOR *cursor;
WT_ITEM logrec_key, logrec_value;
uint64_t txnid;
uint32_t fileid, log_file, log_offset, opcount, optype, rectype;
int found, ret;
error_check(session->open_cursor(session, "log:", NULL, NULL, &cursor));
found = 0;
while ((ret = cursor->next(cursor)) == 0) {
error_check(cursor->get_key(
cursor, &log_file, &log_offset, &opcount));
error_check(cursor->get_value(cursor, &txnid,
&rectype, &optype, &fileid, &logrec_key, &logrec_value));
if (rectype == WT_LOGREC_MESSAGE) {
found = 1;
printf("Application Log Record: %s\n",
(char *)logrec_value.data);
}
}
scan_end_check(ret == WT_NOTFOUND);
error_check(cursor->close(cursor));
if (found == 0) {
fprintf(stderr, "Did not find log messages.\n");
exit(EXIT_FAILURE);
}
}
示例11: cursor
std::vector<std::string> WiredTigerKVEngine::getAllIdents(OperationContext* opCtx) const {
std::vector<std::string> all;
WiredTigerCursor cursor("metadata:", WiredTigerSession::kMetadataTableId, false, opCtx);
WT_CURSOR* c = cursor.get();
if (!c)
return all;
while (c->next(c) == 0) {
const char* raw;
c->get_key(c, &raw);
StringData key(raw);
size_t idx = key.find(':');
if (idx == string::npos)
continue;
StringData type = key.substr(0, idx);
if (type != "table")
continue;
StringData ident = key.substr(idx + 1);
if (ident == "sizeStorer")
continue;
all.push_back(ident.toString());
}
return all;
}
示例12: sizeof
/*
* stats
* Dump the database/file statistics.
*/
void
stats(void)
{
FILE *fp;
WT_CURSOR *cursor;
WT_SESSION *session;
uint64_t v;
int ret;
const char *desc, *pval;
char name[64];
testutil_check(conn->open_session(conn, NULL, NULL, &session));
if ((fp = fopen(FNAME_STAT, "w")) == NULL)
testutil_die(errno, "fopen " FNAME_STAT);
/* Connection statistics. */
testutil_check(session->open_cursor(
session, "statistics:", NULL, NULL, &cursor));
while ((ret = cursor->next(cursor)) == 0 &&
(ret = cursor->get_value(cursor, &desc, &pval, &v)) == 0)
(void)fprintf(fp, "%s=%s\n", desc, pval);
if (ret != WT_NOTFOUND)
testutil_die(ret, "cursor.next");
testutil_check(cursor->close(cursor));
/* File statistics. */
if (!multiple_files) {
testutil_check(__wt_snprintf(
name, sizeof(name), "statistics:" FNAME, 0));
testutil_check(session->open_cursor(
session, name, NULL, NULL, &cursor));
while ((ret = cursor->next(cursor)) == 0 &&
(ret = cursor->get_value(cursor, &desc, &pval, &v)) == 0)
(void)fprintf(fp, "%s=%s\n", desc, pval);
if (ret != WT_NOTFOUND)
testutil_die(ret, "cursor.next");
testutil_check(cursor->close(cursor));
testutil_check(session->close(session, NULL));
}
(void)fclose(fp);
}
示例13: open
int
util_backup(WT_SESSION *session, int argc, char *argv[])
{
WT_CURSOR *cursor;
WT_DECL_RET;
int ch;
char *config;
const char *directory, *name;
config = NULL;
while ((ch = util_getopt(argc, argv, "t:")) != EOF)
switch (ch) {
case 't':
if (append_target(util_optarg, &config))
return (1);
break;
case '?':
default:
return (usage());
}
argc -= util_optind;
argv += util_optind;
if (argc != 1) {
(void)usage();
goto err;
}
directory = *argv;
if ((ret = session->open_cursor(
session, "backup:", NULL, config, &cursor)) != 0) {
fprintf(stderr, "%s: cursor open(backup:) failed: %s\n",
progname, wiredtiger_strerror(ret));
goto err;
}
/* Copy the files. */
while (
(ret = cursor->next(cursor)) == 0 &&
(ret = cursor->get_key(cursor, &name)) == 0)
if ((ret = copy(name, directory)) != 0)
goto err;
if (ret == WT_NOTFOUND)
ret = 0;
if (ret != 0) {
fprintf(stderr, "%s: cursor next(backup:) failed: %s\n",
progname, wiredtiger_strerror(ret));
goto err;
}
err: if (config != NULL)
free(config);
if (cbuf != NULL)
free(cbuf);
return (ret);
}
示例14: next
boost::optional<Record> next() final {
if (_eof)
return {};
WT_CURSOR* c = _cursor->get();
bool mustAdvance = true;
if (_lastReturnedId.isNull() && !_forward && _rs._isCapped) {
// In this case we need to seek to the highest visible record.
const RecordId reverseCappedInitialSeekPoint =
_readUntilForOplog.isNull() ? _rs.lowestCappedHiddenRecord() : _readUntilForOplog;
if (!reverseCappedInitialSeekPoint.isNull()) {
c->set_key(c, _makeKey(reverseCappedInitialSeekPoint));
int cmp;
int seekRet = WT_OP_CHECK(c->search_near(c, &cmp));
if (seekRet == WT_NOTFOUND) {
_eof = true;
return {};
}
invariantWTOK(seekRet);
// If we landed at or past the lowest hidden record, we must advance to be in
// the visible range.
mustAdvance = _rs.isCappedHidden(reverseCappedInitialSeekPoint)
? (cmp >= 0)
: (cmp > 0); // No longer hidden.
}
}
if (mustAdvance) {
// Nothing after the next line can throw WCEs.
// Note that an unpositioned (or eof) WT_CURSOR returns the first/last entry in the
// table when you call next/prev.
int advanceRet = WT_OP_CHECK(_forward ? c->next(c) : c->prev(c));
if (advanceRet == WT_NOTFOUND) {
_eof = true;
return {};
}
invariantWTOK(advanceRet);
}
int64_t key;
invariantWTOK(c->get_key(c, &key));
const RecordId id = _fromKey(key);
if (!isVisible(id)) {
_eof = true;
return {};
}
WT_ITEM value;
invariantWTOK(c->get_value(c, &value));
_lastReturnedId = id;
return {{id, {static_cast<const char*>(value.data), static_cast<int>(value.size)}}};
}
示例15:
/*
* __backup_all --
* Backup all objects in the database.
*/
static int
__backup_all(WT_SESSION_IMPL *session, WT_CURSOR_BACKUP *cb)
{
WT_CONFIG_ITEM cval;
WT_CURSOR *cursor;
WT_DECL_RET;
const char *key, *value;
cursor = NULL;
/*
* Open a cursor on the metadata file and copy all of the entries to
* the hot backup file.
*/
WT_ERR(__wt_metadata_cursor(session, NULL, &cursor));
while ((ret = cursor->next(cursor)) == 0) {
WT_ERR(cursor->get_key(cursor, &key));
WT_ERR(cursor->get_value(cursor, &value));
WT_ERR_TEST((fprintf(
cb->bfp, "%s\n%s\n", key, value) < 0), __wt_errno());
/*
* While reading the metadata file, check there are no "sources"
* or "types" which can't support hot backup. This checks for
* a data source that's non-standard, which can't be backed up,
* but is also sanity checking: if there's an entry backed by
* anything other than a file or lsm entry, we're confused.
*/
if ((ret = __wt_config_getones(
session, value, "type", &cval)) == 0 &&
!WT_PREFIX_MATCH_LEN(cval.str, cval.len, "file") &&
!WT_PREFIX_MATCH_LEN(cval.str, cval.len, "lsm"))
WT_ERR_MSG(session, ENOTSUP,
"hot backup is not supported for objects of "
"type %.*s", (int)cval.len, cval.str);
WT_ERR_NOTFOUND_OK(ret);
if ((ret =__wt_config_getones(
session, value, "source", &cval)) == 0 &&
!WT_PREFIX_MATCH_LEN(cval.str, cval.len, "file:") &&
!WT_PREFIX_MATCH_LEN(cval.str, cval.len, "lsm:"))
WT_ERR_MSG(session, ENOTSUP,
"hot backup is not supported for objects of "
"source %.*s", (int)cval.len, cval.str);
WT_ERR_NOTFOUND_OK(ret);
}
WT_ERR_NOTFOUND_OK(ret);
/* Build a list of the file objects that need to be copied. */
WT_WITH_DHANDLE_LOCK(session,
ret = __wt_meta_btree_apply(
session, __backup_list_all_append, NULL));
err: if (cursor != NULL)
WT_TRET(cursor->close(cursor));
return (ret);
}