本文整理汇总了C++中WT_CURSOR::search方法的典型用法代码示例。如果您正苦于以下问题:C++ WT_CURSOR::search方法的具体用法?C++ WT_CURSOR::search怎么用?C++ WT_CURSOR::search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WT_CURSOR
的用法示例。
在下文中一共展示了WT_CURSOR::search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invariant
// static
StatusWith<uint64_t> WiredTigerUtil::getStatisticsValue(WT_SESSION* session,
const std::string& uri,
const std::string& config,
int statisticsKey) {
invariant(session);
WT_CURSOR* cursor = NULL;
const char* cursorConfig = config.empty() ? NULL : config.c_str();
int ret = session->open_cursor(session, uri.c_str(), NULL, cursorConfig, &cursor);
if (ret != 0) {
return StatusWith<uint64_t>(ErrorCodes::CursorNotFound, str::stream()
<< "unable to open cursor at URI " << uri
<< ". reason: " << wiredtiger_strerror(ret));
}
invariant(cursor);
ON_BLOCK_EXIT(cursor->close, cursor);
cursor->set_key(cursor, statisticsKey);
ret = cursor->search(cursor);
if (ret != 0) {
return StatusWith<uint64_t>(ErrorCodes::NoSuchKey, str::stream()
<< "unable to find key " << statisticsKey << " at URI " << uri
<< ". reason: " << wiredtiger_strerror(ret));
}
uint64_t value;
ret = cursor->get_value(cursor, NULL, NULL, &value);
if (ret != 0) {
return StatusWith<uint64_t>(ErrorCodes::BadValue, str::stream()
<< "unable to get value for key " << statisticsKey << " at URI " << uri
<< ". reason: " << wiredtiger_strerror(ret));
}
return StatusWith<uint64_t>(value);
}
示例2:
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);
}
}
示例3: curwrap
StatusWith<RecordId> WiredTigerRecordStore::updateRecord(OperationContext* txn,
const RecordId& loc,
const char* data,
int len,
bool enforceQuota,
UpdateNotifier* notifier) {
WiredTigerCursor curwrap(_uri, _tableId, true, txn);
curwrap.assertInActiveTxn();
WT_CURSOR* c = curwrap.get();
invariant(c);
c->set_key(c, _makeKey(loc));
int ret = WT_OP_CHECK(c->search(c));
invariantWTOK(ret);
WT_ITEM old_value;
ret = c->get_value(c, &old_value);
invariantWTOK(ret);
int old_length = old_value.size;
c->set_key(c, _makeKey(loc));
WiredTigerItem value(data, len);
c->set_value(c, value.Get());
ret = WT_OP_CHECK(c->insert(c));
invariantWTOK(ret);
_increaseDataSize(txn, len - old_length);
cappedDeleteAsNeeded(txn, loc);
return StatusWith<RecordId>(loc);
}
示例4: invariant
StatusWith<std::string> WiredTigerUtil::getMetadata(OperationContext* opCtx, StringData uri) {
invariant(opCtx);
auto session = WiredTigerRecoveryUnit::get(opCtx)->getSessionNoTxn();
WT_CURSOR* cursor =
session->getCursor("metadata:create", WiredTigerSession::kMetadataTableId, false);
invariant(cursor);
auto releaser =
makeGuard([&] { session->releaseCursor(WiredTigerSession::kMetadataTableId, cursor); });
std::string strUri = uri.toString();
cursor->set_key(cursor, strUri.c_str());
int ret = cursor->search(cursor);
if (ret == WT_NOTFOUND) {
return StatusWith<std::string>(ErrorCodes::NoSuchKey,
str::stream() << "Unable to find metadata for " << uri);
} else if (ret != 0) {
return StatusWith<std::string>(wtRCToStatus(ret));
}
const char* metadata = NULL;
ret = cursor->get_value(cursor, &metadata);
if (ret != 0) {
return StatusWith<std::string>(wtRCToStatus(ret));
}
invariant(metadata);
return StatusWith<std::string>(metadata);
}
示例5:
/*
* __wt_metadata_remove --
* Remove a row from the metadata.
*/
int
__wt_metadata_remove(WT_SESSION_IMPL *session, const char *key)
{
WT_CURSOR *cursor;
WT_DECL_RET;
WT_RET(__wt_verbose(session, WT_VERB_METADATA,
"Remove: key: %s, tracking: %s, %s" "turtle",
key, WT_META_TRACKING(session) ? "true" : "false",
__metadata_turtle(key) ? "" : "not "));
if (__metadata_turtle(key))
WT_RET_MSG(session, EINVAL,
"%s: remove not supported on the turtle file", key);
WT_RET(__wt_metadata_cursor(session, NULL, &cursor));
cursor->set_key(cursor, key);
WT_ERR(cursor->search(cursor));
if (WT_META_TRACKING(session))
WT_ERR(__wt_meta_track_update(session, key));
WT_ERR(cursor->remove(cursor));
err: WT_TRET(cursor->close(cursor));
return (ret);
}
示例6: Get
int WiredTigerEngine::Get(const Slice& key, std::string* value, const Options& options)
{
WT_SESSION* session = GetContextHolder().session;
if (NULL == session)
{
return -1;
}
WT_CURSOR *cursor = create_wiredtiger_cursor(session);
if (NULL == cursor)
{
return -1;
}
WT_ITEM key_item, value_item;
key_item.data = key.data();
key_item.size = key.size();
cursor->set_key(cursor, &key_item);
int ret = 0;
if ((ret = cursor->search(cursor)) == 0)
{
ret = cursor->get_value(cursor, &value_item);
if (0 == ret)
{
if (NULL != value)
{
value->assign((const char*) value_item.data, value_item.size);
}
}
else
{
CHECK_WT_RETURN(ret);
}
}
cursor->close(cursor);
return ret;
}
示例7: sizeof
static void
op(WT_SESSION *session, WT_RAND_STATE *rnd, WT_CURSOR **cpp)
{
WT_CURSOR *cursor;
WT_DECL_RET;
u_int i, key;
char buf[128];
bool readonly;
/* Close any open cursor in the slot we're about to reuse. */
if (*cpp != NULL) {
testutil_check((*cpp)->close(*cpp));
*cpp = NULL;
}
cursor = NULL;
readonly = __wt_random(rnd) % 2 == 0;
/* Loop to open an object handle. */
for (i = __wt_random(rnd) % uris; !done; __wt_yield()) {
/* Use a checkpoint handle for 50% of reads. */
ret = session->open_cursor(session, uri_list[i], NULL,
readonly && (i % 2 == 0) ?
"checkpoint=WiredTigerCheckpoint" : NULL, &cursor);
if (ret != EBUSY) {
testutil_check(ret);
break;
}
(void)__wt_atomic_add64(&worker_busy, 1);
}
if (cursor == NULL)
return;
/* Operate on some number of key/value pairs. */
for (key = 1;
!done && key < MAXKEY; key += __wt_random(rnd) % 37, __wt_yield()) {
testutil_check(
__wt_snprintf(buf, sizeof(buf), "key:%020u", key));
cursor->set_key(cursor, buf);
if (readonly)
testutil_check(cursor->search(cursor));
else {
cursor->set_value(cursor, buf);
testutil_check(cursor->insert(cursor));
}
}
/* Close the cursor half the time, otherwise cache it. */
if (__wt_random(rnd) % 2 == 0)
testutil_check(cursor->close(cursor));
else
*cpp = cursor;
(void)__wt_atomic_add64(&worker, 1);
}
示例8: dataFor
RecordData WiredTigerRecordStore::dataFor(OperationContext* txn, const RecordId& loc) const {
// ownership passes to the shared_array created below
WiredTigerCursor curwrap(_uri, _tableId, true, txn);
WT_CURSOR* c = curwrap.get();
invariant(c);
c->set_key(c, _makeKey(loc));
int ret = WT_OP_CHECK(c->search(c));
massert(28556, "Didn't find RecordId in WiredTigerRecordStore", ret != WT_NOTFOUND);
invariantWTOK(ret);
return _getData(curwrap);
}
示例9: wt_id2entry
int wt_id2entry( BackendDB *be,
WT_SESSION *session,
ID id,
Entry **ep ){
int rc;
WT_CURSOR *cursor = NULL;
WT_ITEM item;
EntryHeader eh;
int eoff;
Entry *e = NULL;
rc = session->open_cursor(session, WT_TABLE_ID2ENTRY"(entry)", NULL,
NULL, &cursor);
if ( rc ) {
Debug( LDAP_DEBUG_ANY,
LDAP_XSTRING(wt_id2entry)
": open_cursor failed: %s (%d)\n",
wiredtiger_strerror(rc), rc, 0 );
goto done;
}
cursor->set_key(cursor, id);
rc = cursor->search(cursor);
if ( rc ) {
goto done;
}
cursor->get_value(cursor, &item);
rc = wt_entry_header( &item, &eh );
eoff = eh.data - (char *)item.data;
eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + item.size;
eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
memset(eh.bv.bv_val, 0xff, eh.bv.bv_len);
eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval );
memcpy(eh.data, item.data, item.size);
eh.data += eoff;
rc = entry_decode( &eh, &e );
if ( rc ) {
Debug( LDAP_DEBUG_ANY,
LDAP_XSTRING(wt_id2entry)
": entry decode error: %s (%d)\n",
rc, 0, 0 );
goto done;
}
e->e_id = id;
*ep = e;
done:
if(cursor){
cursor->close(cursor);
}
return rc;
}
示例10: _hasUri
bool WiredTigerKVEngine::_hasUri(WT_SESSION* session, const std::string& uri) const {
// can't use WiredTigerCursor since this is called from constructor.
WT_CURSOR* c = NULL;
int ret = session->open_cursor(session, "metadata:", NULL, NULL, &c);
if (ret == ENOENT)
return false;
invariantWTOK(ret);
ON_BLOCK_EXIT(c->close, c);
c->set_key(c, uri.c_str());
return c->search(c) == 0;
}
示例11:
/*
* __wt_metadata_search --
* Return a copied row from the metadata.
* The caller is responsible for freeing the allocated memory.
*/
int
__wt_metadata_search(WT_SESSION_IMPL *session, const char *key, char **valuep)
{
WT_CURSOR *cursor;
WT_DECL_RET;
const char *value;
*valuep = NULL;
__wt_verbose(session, WT_VERB_METADATA,
"Search: key: %s, tracking: %s, %s" "turtle",
key, WT_META_TRACKING(session) ? "true" : "false",
__metadata_turtle(key) ? "" : "not ");
if (__metadata_turtle(key)) {
/*
* The returned value should only be set if ret is non-zero, but
* Coverity is convinced otherwise. The code path is used enough
* that Coverity complains a lot, add an error check to get some
* peace and quiet.
*/
if ((ret = __wt_turtle_read(session, key, valuep)) != 0)
__wt_free(session, *valuep);
return (ret);
}
/*
* All metadata reads are at read-uncommitted isolation. That's
* because once a schema-level operation completes, subsequent
* operations must see the current version of checkpoint metadata, or
* they may try to read blocks that may have been freed from a file.
* Metadata updates use non-transactional techniques (such as the
* schema and metadata locks) to protect access to in-flight updates.
*/
WT_RET(__wt_metadata_cursor(session, &cursor));
cursor->set_key(cursor, key);
WT_WITH_TXN_ISOLATION(session, WT_ISO_READ_UNCOMMITTED,
ret = cursor->search(cursor));
WT_ERR(ret);
WT_ERR(cursor->get_value(cursor, &value));
WT_ERR(__wt_strdup(session, value, valuep));
err: WT_TRET(__wt_metadata_cursor_release(session, &cursor));
if (ret != 0)
__wt_free(session, *valuep);
return (ret);
}
示例12: findRecord
bool WiredTigerRecordStore::findRecord(OperationContext* txn,
const RecordId& loc,
RecordData* out) const {
WiredTigerCursor curwrap(_uri, _tableId, true, txn);
WT_CURSOR* c = curwrap.get();
invariant(c);
c->set_key(c, _makeKey(loc));
int ret = WT_OP_CHECK(c->search(c));
if (ret == WT_NOTFOUND) {
return false;
}
invariantWTOK(ret);
*out = _getData(curwrap);
return true;
}
示例13:
/*
* 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);
}
示例14: doread
/* perform read command */
int doread(char *name, int rnum, int rnd){
WT_CURSOR *c;
WT_ITEM key, value;
int i, err;
char buf[RECBUFSIZ];
if(showprgr)
printf("<Read Test of Row Store>\n name=%s rnum=%d\n\n", name, rnum);
/* open a database */
if(setup(name, NULL, NULL, NULL, &c) != 0){
fprintf(stderr, "open failed\n");
return 1;
}
err = FALSE;
key.data = value.data = buf;
key.size = value.size = 8;
/* loop for each record */
for(i = 1; i <= rnum; i++){
/* store a record */
sprintf(buf, "%08d", rnd ? myrand() % rnum + 1 : i);
c->set_key(c, &key);
if(c->search(c) != 0){
fprintf(stderr, "search failed\n");
err = TRUE;
break;
}
/* Include the cost of getting the value. */
c->get_value(c, &value);
/* print progression */
if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
putchar('.');
fflush(stdout);
if(i == rnum || i % (rnum / 10) == 0){
printf(" (%08d)\n", i);
fflush(stdout);
}
}
}
/* close the database */
if(teardown() != 0) {
fprintf(stderr, "close failed\n");
return 1;
}
if(showprgr && !err)
printf("ok\n\n");
return err ? 1 : 0;
}
示例15: if
/*
* dump_json_table_config --
* Dump the config for the uri.
*/
static int
dump_json_table_config(WT_SESSION *session, const char *uri)
{
WT_CURSOR *cursor;
WT_DECL_RET;
int tret;
char *value;
/* Dump the config. */
/* Open a metadata cursor. */
if ((ret = session->open_cursor(
session, "metadata:create", NULL, NULL, &cursor)) != 0) {
fprintf(stderr, "%s: %s: session.open_cursor: %s\n",
progname, "metadata:create",
session->strerror(session, ret));
return (1);
}
/*
* Search for the object itself, to make sure it
* exists, and get its config string. This where we
* find out a table object doesn't exist, use a simple
* error message.
*/
cursor->set_key(cursor, uri);
if ((ret = cursor->search(cursor)) == 0) {
if ((ret = cursor->get_value(cursor, &value)) != 0)
ret = util_cerr(cursor, "get_value", ret);
else if (dump_json_table_begin(
session, cursor, uri, value) != 0)
ret = 1;
} else if (ret == WT_NOTFOUND)
ret = util_err(
session, 0, "%s: No such object exists", uri);
else
ret = util_err(session, ret, "%s", uri);
if ((tret = cursor->close(cursor)) != 0) {
tret = util_cerr(cursor, "close", tret);
if (ret == 0)
ret = tret;
}
return (ret);
}