本文整理汇总了C++中WT_CURSOR::get_key方法的典型用法代码示例。如果您正苦于以下问题:C++ WT_CURSOR::get_key方法的具体用法?C++ WT_CURSOR::get_key怎么用?C++ WT_CURSOR::get_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WT_CURSOR
的用法示例。
在下文中一共展示了WT_CURSOR::get_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*
* __curdump_get_key --
* WT_CURSOR->get_key for dump cursors.
*/
static int
__curdump_get_key(WT_CURSOR *cursor, ...)
{
WT_CURSOR *child;
WT_CURSOR_DUMP *cdump;
WT_DECL_RET;
WT_ITEM item, *itemp;
WT_SESSION_IMPL *session;
uint64_t recno;
va_list ap;
cdump = (WT_CURSOR_DUMP *)cursor;
child = cdump->child;
CURSOR_API_CALL(cursor, session, get_key, NULL);
if (WT_CURSOR_RECNO(cursor) && !F_ISSET(cursor, WT_CURSTD_RAW)) {
WT_ERR(child->get_key(child, &recno));
WT_ERR(__wt_buf_fmt(session, &cursor->key, "%" PRIu64, recno));
} else {
WT_ERR(child->get_key(child, &item));
WT_ERR(__raw_to_dump(session, &item,
&cursor->key, F_ISSET(cursor, WT_CURSTD_DUMP_HEX) ? 1 : 0));
}
va_start(ap, cursor);
if (F_ISSET(cursor, WT_CURSTD_RAW)) {
itemp = va_arg(ap, WT_ITEM *);
itemp->data = cursor->key.data;
itemp->size = cursor->key.size;
} else
示例2:
/*
* __wt_bloom_open --
* Open a Bloom filter object for use by a single session. The filter must
* have been created and finalized.
*/
int
__wt_bloom_open(WT_SESSION_IMPL *session,
const char *uri, uint32_t factor, uint32_t k,
WT_CURSOR *owner, WT_BLOOM **bloomp)
{
WT_BLOOM *bloom;
WT_CURSOR *c;
WT_DECL_RET;
uint64_t size;
WT_RET(__bloom_init(session, uri, NULL, &bloom));
WT_ERR(__bloom_open_cursor(bloom, owner));
c = bloom->c;
/* Find the largest key, to get the size of the filter. */
WT_ERR(c->prev(c));
WT_ERR(c->get_key(c, &size));
WT_ERR(c->reset(c));
WT_ERR(__bloom_setup(bloom, 0, size, factor, k));
*bloomp = bloom;
return (0);
err: (void)__wt_bloom_close(bloom);
return (ret);
}
示例3:
/*
* __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);
}
示例4: cursor
boost::optional<RecordId> WiredTigerRecordStore::oplogStartHack(
OperationContext* txn, const RecordId& startingPosition) const {
if (!_useOplogHack)
return boost::none;
{
WiredTigerRecoveryUnit* wru = WiredTigerRecoveryUnit::get(txn);
_oplogSetStartHack(wru);
}
WiredTigerCursor cursor(_uri, _tableId, true, txn);
WT_CURSOR* c = cursor.get();
int cmp;
c->set_key(c, _makeKey(startingPosition));
int ret = WT_OP_CHECK(c->search_near(c, &cmp));
if (ret == 0 && cmp > 0)
ret = c->prev(c); // landed one higher than startingPosition
if (ret == WT_NOTFOUND)
return RecordId(); // nothing <= startingPosition
invariantWTOK(ret);
int64_t key;
ret = c->get_key(c, &key);
invariantWTOK(ret);
return _fromKey(key);
}
示例5:
/*
* 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);
}
}
示例6:
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");
}
示例7: 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;
}
示例8:
/*! [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: sizeof
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;
}
}
示例10: 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));
}
示例11:
/*
* 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);
}
示例12: 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);
}
示例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);
}