예제 #1
0
파일: ex_cursor.c 프로젝트: DINKIN/mongo
int
main(int argc, char *argv[])
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;

	home = example_setup(argc, argv);

	/* Open a connection to the database, creating it if necessary. */
	error_check(wiredtiger_open(
	    home, NULL, "create,statistics=(fast)", &conn));

	/* Open a session for the current thread's work. */
	error_check(conn->open_session(conn, NULL, NULL, &session));

	error_check(session->create(session, "table:world",
	    "key_format=r,value_format=5sii,"
	    "columns=(id,country,population,area)"));

	/*! [open cursor #1] */
	error_check(session->open_cursor(
	    session, "table:world", NULL, NULL, &cursor));
	/*! [open cursor #1] */

	/*! [open cursor #2] */
	error_check(session->open_cursor(session,
	    "table:world(country,population)", NULL, NULL, &cursor));
	/*! [open cursor #2] */

	/*! [open cursor #3] */
	error_check(session->open_cursor(
	    session, "statistics:", NULL, NULL, &cursor));
	/*! [open cursor #3] */

	/* Create a simple string table to illustrate basic operations. */
	error_check(session->create(
	    session, "table:map", "key_format=S,value_format=S"));
	error_check(session->open_cursor(
	    session, "table:map", NULL, NULL, &cursor));
	error_check(cursor_insert(cursor));
	error_check(cursor_reset(cursor));
	error_check(cursor_forward_scan(cursor));
	error_check(cursor_reset(cursor));
	error_check(cursor_reverse_scan(cursor));
	error_check(cursor_search_near(cursor));
	error_check(cursor_update(cursor));
	error_check(cursor_remove(cursor));
	error_check(cursor->close(cursor));

	/* Note: closing the connection implicitly closes open session(s). */
	error_check(conn->close(conn, NULL));

	return (EXIT_SUCCESS);
}
예제 #2
0
/*
 * subtest_main --
 *	The main program for the subtest
 */
static void
subtest_main(int argc, char *argv[], bool close_test)
{
	struct rlimit rlim;
	TEST_OPTS *opts, _opts;
	WT_SESSION *session;
	char config[1024], filename[1024];

	opts = &_opts;
	memset(opts, 0, sizeof(*opts));
	memset(&rlim, 0, sizeof(rlim));

	/* No core files during fault injection tests. */
	testutil_check(setrlimit(RLIMIT_CORE, &rlim));
	testutil_check(testutil_parse_opts(argc, argv, opts));
	testutil_make_work_dir(opts->home);

	/* Redirect stderr, stdout. */
	testutil_check(__wt_snprintf(
	    filename, sizeof(filename), "%s/%s", opts->home, STDERR_FILE));
	testutil_assert(freopen(filename, "a", stderr) != NULL);
	testutil_check(__wt_snprintf(
	    filename, sizeof(filename), "%s/%s", opts->home, STDOUT_FILE));
	testutil_assert(freopen(filename, "a", stdout) != NULL);
	testutil_check(__wt_snprintf(config, sizeof(config),
	    "create,cache_size=250M,log=(enabled),"
	    "transaction_sync=(enabled,method=none),extensions=("
	    WT_FAIL_FS_LIB
	    "=(early_load,config={environment=true,verbose=true})]"));

	testutil_check(
	    wiredtiger_open(opts->home, &event_handler, config, &opts->conn));
	testutil_check(
	    opts->conn->open_session(opts->conn, NULL, NULL, &session));

	testutil_check(session->create(session, "table:subtest",
	    "key_format=i,value_format=iiiS,"
	    "columns=(id,v0,v1,v2,big)"));

	testutil_check(session->create(session, "table:subtest2",
	    "key_format=i,value_format=i"));

	testutil_check(session->create(session, "index:subtest:v0",
	    "columns=(v0)"));
	testutil_check(session->create(session, "index:subtest:v1",
	    "columns=(v1)"));
	testutil_check(session->create(session, "index:subtest:v2",
	    "columns=(v2)"));

	testutil_check(session->close(session, NULL));

	subtest_populate(opts, close_test);

	testutil_cleanup(opts);
}
예제 #3
0
int main(void)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	int ret;

	/* Open a connection to the database, creating it if necessary. */
	if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0)
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home, wiredtiger_strerror(ret));

	/* Open a session for the current thread's work. */
	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		fprintf(stderr, "Error opening a session on %s: %s\n",
		    home, wiredtiger_strerror(ret));

	ret = session->create(session, "table:world",
	    "key_format=r,value_format=5sii,"
	    "columns=(id,country,population,area)");

	/*! [open cursor #1] */
	ret = session->open_cursor(session, "table:world", NULL, NULL, &cursor);
	/*! [open cursor #1] */

	/*! [open cursor #2] */
	ret = session->open_cursor(session,
	    "table:world(country,population)", NULL, NULL, &cursor);
	/*! [open cursor #2] */

	/*! [open cursor #3] */
	ret = session->open_cursor(session, "statistics:", NULL, NULL, &cursor);
	/*! [open cursor #3] */

	/* Create a simple string table to illustrate basic operations. */
	ret = session->create(session, "table:map",
	    "key_format=S,value_format=S");
	ret = session->open_cursor(session, "table:map", NULL, NULL, &cursor);
	ret = cursor_insert(cursor);
	ret = cursor_reset(cursor);
	ret = cursor_forward_scan(cursor);
	ret = cursor_reset(cursor);
	ret = cursor_reverse_scan(cursor);
	ret = cursor_update(cursor);
	ret = cursor_remove(cursor);
	ret = cursor->close(cursor);

	/* Note: closing the connection implicitly closes open session(s). */
	if ((ret = conn->close(conn, NULL)) != 0)
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home, wiredtiger_strerror(ret));

	return (ret);
}
        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 );
        }
예제 #5
0
static void
file_create(SHARED_CONFIG *cfg, const char *name)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;
	char config[128];

	conn = cfg->conn;

	testutil_check(conn->open_session(conn, NULL, NULL, &session));

	testutil_check(__wt_snprintf(config, sizeof(config),
	    "key_format=%s,"
	    "internal_page_max=%d,"
	    "split_deepen_min_child=200,"
	    "leaf_page_max=%d,"
	    "%s",
	    cfg->ftype == ROW ? "S" : "r", 16 * 1024, 128 * 1024,
	    cfg->ftype == FIX ? ",value_format=3t" : ""));

	if ((ret = session->create(session, name, config)) != 0)
		if (ret != EEXIST)
			testutil_die(ret, "session.create");

	testutil_check(session->close(session, NULL));
}
예제 #6
0
int
main(void)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	int ret;

	ret = wiredtiger_open(home, NULL, "create,statistics=(all)", &conn);
	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, NULL, &cursor);
	cursor->set_key(cursor, "key");
	cursor->set_value(cursor, "value");
	ret = cursor->insert(cursor);
	cursor->close(cursor);

	ret = session->checkpoint(session, NULL);

	ret = print_database_stats(session);

	ret = print_file_stats(session);

	ret = print_overflow_pages(session);

	ret = print_derived_stats(session);

	return (conn->close(conn, NULL) == 0 ? ret : EXIT_FAILURE);
}
예제 #7
0
파일: thread.c 프로젝트: ajdavis/mongo
/*
 * 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++;
}
예제 #8
0
/*! [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);
}
예제 #9
0
파일: file.c 프로젝트: DINKIN/mongo
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
0
파일: file.c 프로젝트: DINKIN/mongo
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");
}
예제 #11
0
파일: main.c 프로젝트: judahschvimer/mongo
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);
}
예제 #12
0
    TEST(WiredTigerUtilTest, GetStatisticsValueAsUInt8) {
        WiredTigerUtilHarnessHelper harnessHelper("statistics=(all)");
        WiredTigerRecoveryUnit recoveryUnit(harnessHelper.getSessionCache());
        WiredTigerSession* session = recoveryUnit.getSession(NULL);
        WT_SESSION* wtSession = session->getSession();
        ASSERT_OK(wtRCToStatus(wtSession->create(wtSession, "table:mytable", NULL)));

        // Use data source statistics that has a value > 256 on an empty table.
        StatusWith<uint64_t> resultUInt64 = WiredTigerUtil::getStatisticsValue(
            session->getSession(),
            "statistics:table:mytable", "statistics=(fast)", WT_STAT_DSRC_ALLOCATION_SIZE);
        ASSERT_OK(resultUInt64.getStatus());
        ASSERT_GREATER_THAN(resultUInt64.getValue(),
            static_cast<uint64_t>(std::numeric_limits<uint8_t>::max()));

        // Ensure that statistics value retrieved as an 8-bit unsigned value
        // is capped at maximum value for that type.
        StatusWith<uint8_t> resultUInt8 = WiredTigerUtil::getStatisticsValueAs<uint8_t>(
            session->getSession(),
            "statistics:table:mytable", "statistics=(fast)", WT_STAT_DSRC_ALLOCATION_SIZE);
        ASSERT_OK(resultUInt8.getStatus());
        ASSERT_EQUALS(std::numeric_limits<uint8_t>::max(), resultUInt8.getValue());

        // Read statistics value as signed 16-bit value with alternative maximum value to
        // std::numeric_limits.
        StatusWith<int16_t> resultInt16 = WiredTigerUtil::getStatisticsValueAs<int16_t>(
            session->getSession(),
            "statistics:table:mytable", "statistics=(fast)", WT_STAT_DSRC_ALLOCATION_SIZE,
            static_cast<int16_t>(100));
        ASSERT_OK(resultInt16.getStatus());
        ASSERT_EQUALS(static_cast<uint8_t>(100), resultInt16.getValue());
    }
예제 #13
0
파일: file.c 프로젝트: ChineseDr/mongo
static void
file_create(const char *name)
{
    WT_SESSION *session;
    int ret;
    char *p, *end, config[128];

    if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
        testutil_die(ret, "conn.session");

    p = config;
    end = config + sizeof(config);
    p += snprintf(p, (size_t)(end - p),
                  "key_format=%s,"
                  "internal_page_max=%d,"
                  "leaf_page_max=%d,",
                  ftype == ROW ? "u" : "r", 16 * 1024, 128 * 1024);
    if (ftype == FIX)
        (void)snprintf(p, (size_t)(end - p), ",value_format=3t");

    if ((ret = session->create(session, name, config)) != 0)
        if (ret != EEXIST)
            testutil_die(ret, "session.create");

    if ((ret = session->close(session, NULL)) != 0)
        testutil_die(ret, "session.close");
}
예제 #14
0
 TEST(WiredTigerUtilTest, GetStatisticsValueStatisticsDisabled) {
     WiredTigerUtilHarnessHelper harnessHelper("statistics=(none)");
     WiredTigerRecoveryUnit recoveryUnit(harnessHelper.getSessionCache());
     WiredTigerSession* session = recoveryUnit.getSession(NULL);
     WT_SESSION* wtSession = session->getSession();
     ASSERT_OK(wtRCToStatus(wtSession->create(wtSession, "table:mytable", NULL)));
     StatusWith<uint64_t> result = WiredTigerUtil::getStatisticsValue(session->getSession(),
         "statistics:table:mytable", "statistics=(fast)", WT_STAT_DSRC_BLOCK_SIZE);
     ASSERT_NOT_OK(result.getStatus());
     ASSERT_EQUALS(ErrorCodes::CursorNotFound, result.getStatus().code());
 }
예제 #15
0
 TEST(WiredTigerUtilTest, GetStatisticsValueInvalidKey) {
     WiredTigerUtilHarnessHelper harnessHelper("statistics=(all)");
     WiredTigerRecoveryUnit recoveryUnit(harnessHelper.getSessionCache());
     WiredTigerSession* session = recoveryUnit.getSession(NULL);
     WT_SESSION* wtSession = session->getSession();
     ASSERT_OK(wtRCToStatus(wtSession->create(wtSession, "table:mytable", NULL)));
     // Use connection statistics key which does not apply to a table.
     StatusWith<uint64_t> result = WiredTigerUtil::getStatisticsValue(session->getSession(),
         "statistics:table:mytable", "statistics=(fast)", WT_STAT_CONN_SESSION_OPEN);
     ASSERT_NOT_OK(result.getStatus());
     ASSERT_EQUALS(ErrorCodes::NoSuchKey, result.getStatus().code());
 }
예제 #16
0
파일: thread.c 프로젝트: ajdavis/mongo
/*
 * Create a guaranteed unique table and open and close a bulk cursor on it.
 */
void
op_bulk_unique(void *arg)
{
	TEST_OPTS *opts;
	TEST_PER_THREAD_OPTS *args;
	WT_CURSOR *c;
	WT_RAND_STATE rnd;
	WT_SESSION *session;
	int ret;
	char new_uri[64];

	args = (TEST_PER_THREAD_OPTS *)arg;
	opts = args->testopts;
	__wt_random_init_seed(NULL, &rnd);

	testutil_check(
	    opts->conn->open_session(opts->conn, NULL, NULL, &session));

	/* Generate a unique object name. */
	testutil_check(__wt_snprintf(
	    new_uri, sizeof(new_uri), "%s.%" PRIu64,
	    opts->uri, __wt_atomic_add64(&opts->unique_id, 1)));
	testutil_check(session->create(session, new_uri, DEFAULT_TABLE_SCHEMA));

	__wt_yield();

	/*
	 * Opening a bulk cursor may have raced with a forced checkpoint
	 * which created a checkpoint of the empty file, and triggers an EINVAL.
	 */
	if ((ret = session->open_cursor(
	    session, new_uri, NULL, "bulk,checkpoint_wait=false", &c)) == 0) {
		testutil_check(c->close(c));
	} else if (ret != EINVAL && ret != EBUSY)
		testutil_die(ret,
		    "session.open_cursor bulk unique: %s", new_uri);

	while ((ret = session->drop(session, new_uri, __wt_random(&rnd) & 1 ?
	    "force,checkpoint_wait=false" : "checkpoint_wait=false")) != 0)
		if (ret != EBUSY)
			testutil_die(ret, "session.drop: %s", new_uri);
		else
			/*
			 * The EBUSY is expected when we run with
			 * checkpoint_wait set to false, so we increment the
			 * counter while in this loop to avoid false positives.
			 */
			args->thread_counter++;

	testutil_check(session->close(session, NULL));
	args->thread_counter++;
}
예제 #17
0
 TEST(WiredTigerUtilTest, GetStatisticsValueValidKey) {
     WiredTigerUtilHarnessHelper harnessHelper("statistics=(all)");
     WiredTigerRecoveryUnit recoveryUnit(harnessHelper.getSessionCache());
     WiredTigerSession* session = recoveryUnit.getSession(NULL);
     WT_SESSION* wtSession = session->getSession();
     ASSERT_OK(wtRCToStatus(wtSession->create(wtSession, "table:mytable", NULL)));
     // Use connection statistics key which does not apply to a table.
     StatusWith<uint64_t> result = WiredTigerUtil::getStatisticsValue(session->getSession(),
         "statistics:table:mytable", "statistics=(fast)", WT_STAT_DSRC_LSM_CHUNK_COUNT);
     ASSERT_OK(result.getStatus());
     // Expect statistics value to be zero for a LSM key on a Btree.
     ASSERT_EQUALS(0U, result.getValue());
 }
예제 #18
0
파일: main.c 프로젝트: ksuarz/mongo
int
main(int argc, char *argv[])
{
	int ret;
	WT_CONNECTION *conn;
	WT_SESSION *session;

	(void)argc;
	(void)argv;
	fprintf(stderr, SEPARATOR "wiredtiger_open\n");
	if ((ret = wiredtiger_open(".", NULL, "create", &conn)) != 0)
		fail(ret);

	usleep(100);
	fflush(stderr);
	fprintf(stderr, SEPARATOR "open_session\n");
	fflush(stderr);

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		fail(ret);

	usleep(100);
	fflush(stderr);
	fprintf(stderr, SEPARATOR "create\n");
	fflush(stderr);

	if ((ret = session->create(
	    session, "table:hello", "key_format=S,value_format=S")) != 0)
		fail(ret);

	usleep(100);
	fprintf(stderr, SEPARATOR "rename\n");

	if ((ret = session->rename(
	    session, "table:hello", "table:world", NULL)) != 0)
		fail(ret);

	fflush(stdout);
	fprintf(stderr, SEPARATOR "drop\n");
	fflush(stdout);

	if ((ret = session->drop(session, "table:world", NULL)) != 0)
		fail(ret);

	fprintf(stderr, SEPARATOR "WT_CONNECTION::close\n");

	if ((ret = conn->close(conn, NULL)) != 0)
		fail(ret);

	return (0);
}
예제 #19
0
int main(void)
{
	/*! [access example connection] */
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	const char *key, *value;
	int ret;

	if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0 ||
	    (ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home, wiredtiger_strerror(ret));
		return (ret);
	}
	/*! [access example connection] */

	/*! [access example table create] */
	ret = session->create(session,
	    "table:access", "key_format=S,value_format=S");
	/*! [access example table create] */

	/*! [access example cursor open] */
	ret = session->open_cursor(session,
	    "table:access", NULL, NULL, &cursor);
	/*! [access example cursor open] */

	/*! [access example cursor insert] */
	cursor->set_key(cursor, "key1");	/* Insert a record. */
	cursor->set_value(cursor, "value1");
	ret = cursor->insert(cursor);
	/*! [access example cursor insert] */

	/*! [access example cursor list] */
	ret = cursor->reset(cursor);	        /* Restart the scan. */
	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);
	}
	/*! [access example cursor list] */

	/*! [access example close] */
	ret = conn->close(conn, NULL);
	/*! [access example close] */

	return (ret);
}
예제 #20
0
WiredTigerSizeStorer::WiredTigerSizeStorer(WT_CONNECTION* conn, const std::string& storageUri)
    : _session(conn) {
    WT_SESSION* session = _session.getSession();
    int ret = session->open_cursor(session, storageUri.c_str(), NULL, "overwrite=true", &_cursor);
    if (ret == ENOENT) {
        // Need to create table.
        std::string config = WiredTigerCustomizationHooks::get(getGlobalServiceContext())
                                 ->getTableCreateConfig(storageUri);
        invariantWTOK(session->create(session, storageUri.c_str(), config.c_str()));
        ret = session->open_cursor(session, storageUri.c_str(), NULL, "overwrite=true", &_cursor);
    }
    invariantWTOK(ret);

    _magic = MAGIC;
}
예제 #21
0
파일: file.c 프로젝트: DINKIN/mongo
void
obj_create(void)
{
	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 = session->close(session, NULL)) != 0)
		testutil_die(ret, "session.close");
}
예제 #22
0
파일: file.c 프로젝트: qixin/wiredtiger
void
obj_create(void)
{
	WT_SESSION *session;
	int ret;

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		die("conn.session", ret);

	if ((ret = session->create(session, uri, NULL)) != 0)
		if (ret != EEXIST)
			die("session.create", ret);

	if ((ret = session->close(session, NULL)) != 0)
		die("session.close", ret);
}
예제 #23
0
파일: salvage.c 프로젝트: qixin/wiredtiger
/*
 * process --
 *	Salvage, verify and dump the created file.
 */
void
process(void)
{
	FILE *fp;
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	const char *key, *value;
	WT_SESSION *session;
	char config[100];

	/* Salvage. */
	config[0] = '\0';
	if (verbose)
		snprintf(config, sizeof(config),
		    "error_prefix=\"%s\",verbose=[salvage,verify]",
		    progname);
	assert(wiredtiger_open(NULL, NULL, config, &conn) == 0);
	assert(conn->open_session(conn, NULL, NULL, &session) == 0);
	assert(session->salvage(session, "file:" SLVG, 0) == 0);
	assert(conn->close(conn, 0) == 0);

	/* Verify. */
	assert(wiredtiger_open(NULL, NULL, "", &conn) == 0);
	assert(conn->open_session(conn, NULL, NULL, &session) == 0);
	assert(session->verify(session, "file:" SLVG, 0) == 0);
	assert(conn->close(conn, 0) == 0);

	/* Dump. */
	assert((fp = fopen(DUMP, "w")) != NULL);
	assert(wiredtiger_open(NULL, NULL, "", &conn) == 0);
	assert(conn->open_session(conn, NULL, NULL, &session) == 0);
	assert(session->create(session, "file:" SLVG, NULL) == 0);
	assert(session->open_cursor(
	    session, "file:" SLVG, NULL, "dump=print", &cursor) == 0);
	while (cursor->next(cursor) == 0) {
		if (page_type == WT_PAGE_ROW_LEAF) {
			assert(cursor->get_key(cursor, &key) == 0);
			assert(fputs(key, fp) >= 0);
			assert(fputc('\n', fp) >= 0);
		}
		assert(cursor->get_value(cursor, &value) == 0);
		assert(fputs(value, fp) >= 0);
		assert(fputc('\n', fp) >= 0);
	}
	assert(conn->close(conn, 0) == 0);
	assert(fclose(fp) == 0);
}
예제 #24
0
    WiredTigerSizeStorer::WiredTigerSizeStorer(WT_CONNECTION* conn, const std::string& storageUri)
            : _session(conn)
    {
        WT_SESSION* session = _session.getSession();
        int ret = session->open_cursor(session, storageUri.c_str(), NULL,
                                       "overwrite=true", &_cursor);
        if (ret == ENOENT) {
            // Need to create table.
            // TODO any config options we want?
            invariantWTOK(session->create(session, storageUri.c_str(), NULL));
            ret = session->open_cursor(session, storageUri.c_str(), NULL,
                                       "overwrite=true", &_cursor);
        }
        invariantWTOK(ret);

        _magic = MAGIC;
    }
예제 #25
0
    Status WiredTigerKVEngine::createRecordStore( OperationContext* opCtx,
                                                  const StringData& ns,
                                                  const StringData& ident,
                                                  const CollectionOptions& options ) {
        WiredTigerSession session( _conn, -1 );

        StatusWith<std::string> result = WiredTigerRecordStore::generateCreateString(ns, options, _rsOptions);
        if (!result.isOK()) {
            return result.getStatus();
        }
        std::string config = result.getValue();

        string uri = _uri( ident );
        WT_SESSION* s = session.getSession();
        LOG(1) << "WiredTigerKVEngine::createRecordStore uri: " << uri << " config: " << config;
        return wtRCToStatus( s->create( s, uri.c_str(), config.c_str() ) );
    }
예제 #26
0
/*! [thread main] */
int
main(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	WT_CURSOR *cursor;
	pthread_t threads[NUM_THREADS];
	int i, ret;

	/*
	 * Create a clean test directory for this run of the test program if the
	 * environment variable isn't already set (as is done by make check).
	 */
	if (getenv("WIREDTIGER_HOME") == NULL) {
		home = "WT_HOME";
		ret = system("rm -rf WT_HOME && mkdir WT_HOME");
	} else
		home = NULL;

	if ((ret = wiredtiger_open(home, NULL, "create", &conn)) != 0)
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home == NULL ? "." : 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, conn);

	for (i = 0; i < NUM_THREADS; i++)
		ret = pthread_join(threads[i], NULL);

	ret = conn->close(conn, NULL);

	return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
예제 #27
0
파일: file.c 프로젝트: DINKIN/mongo
void
obj_bulk_unique(int force)
{
	WT_CURSOR *c;
	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: %s", new_uri);

	__wt_yield();
	/*
	 * Opening a bulk cursor may have raced with a forced checkpoint
	 * which created a checkpoint of the empty file, and triggers an EINVAL
	 */
	if ((ret = session->open_cursor(
	    session, new_uri, NULL, "bulk", &c)) == 0) {
		if ((ret = c->close(c)) != 0)
			testutil_die(ret, "cursor.close");
	} else if (ret != EINVAL)
		testutil_die(ret,
		    "session.open_cursor bulk unique: %s, new_uri");

	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");
}
예제 #28
0
int
main(void)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	int ret;

	/*
	 * Create a clean test directory for this run of the test program if the
	 * environment variable isn't already set (as is done by make check).
	 */
	if (getenv("WIREDTIGER_HOME") == NULL) {
		home = "WT_HOME";
		ret = system("rm -rf WT_HOME && mkdir WT_HOME");
	} else
		home = NULL;

	ret = wiredtiger_open(home, NULL, "create,statistics=(all)", &conn);
	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, NULL, &cursor);
	cursor->set_key(cursor, "key");
	cursor->set_value(cursor, "value");
	ret = cursor->insert(cursor);
	ret = cursor->close(cursor);

	ret = session->checkpoint(session, NULL);

	ret = print_database_stats(session);

	ret = print_file_stats(session);

	ret = print_overflow_pages(session);

	ret = print_derived_stats(session);

	return (conn->close(conn, NULL) == 0 ? ret : EXIT_FAILURE);
}
예제 #29
0
파일: ex_stat.c 프로젝트: qixin/wiredtiger
int
main(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;

	ret = wiredtiger_open(home, NULL, "create", &conn);
	ret = conn->open_session(conn, NULL, NULL, &session);
	ret = session->create(
	    session, "table:access", "key_format=S,value_format=S");

	ret = print_database_stats(session);

	ret = print_file_stats(session);

	ret = print_overflow_pages(session);

	return (conn->close(conn, NULL) == 0 ? ret : EXIT_FAILURE);
}
예제 #30
0
int setup(char *name, const char *kf, const char *vf, const char *cconfig, WT_CURSOR **cursor){
  WT_SESSION *session;
  int creating, ret;
  char tconfig[64];

  creating = (kf != NULL);

  if((ret = wiredtiger_open(NULL, NULL, "create", &conn) != 0) ||
    (ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
    return ret;

  /* If we get a configuration, create the table. */
  if(creating) {
    (void)session->drop(session, name, "force");
    snprintf(tconfig, sizeof(tconfig), "key_format=%s,value_format=%s", kf, vf);
    if ((ret = session->create(session, name, tconfig)) != 0)
      return ret;
  }

  return session->open_cursor(session, name, NULL, cconfig, cursor);
}