Ejemplo n.º 1
0
/*
 * 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);
	strcat(config, "log=(enabled=false),");

	CHECK(wiredtiger_open(NULL, NULL, config, &conn) == 0);
	CHECK(conn->open_session(conn, NULL, NULL, &session) == 0);
	CHECK(session->salvage(session, "file:" SLVG, 0) == 0);
	CHECK(conn->close(conn, 0) == 0);

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

	/* Dump. */
	CHECK((fp = fopen(DUMP, "w")) != NULL);
	CHECK(wiredtiger_open(NULL, NULL, config, &conn) == 0);
	CHECK(conn->open_session(conn, NULL, NULL, &session) == 0);
	CHECK(session->open_cursor(
	    session, "file:" SLVG, NULL, "dump=print", &cursor) == 0);
	while (cursor->next(cursor) == 0) {
		if (page_type == WT_PAGE_ROW_LEAF) {
			CHECK(cursor->get_key(cursor, &key) == 0);
			CHECK(fputs(key, fp) >= 0);
			CHECK(fputc('\n', fp) >= 0);
		}
		CHECK(cursor->get_value(cursor, &value) == 0);
		CHECK(fputs(value, fp) >= 0);
		CHECK(fputc('\n', fp) >= 0);
	}
	CHECK(conn->close(conn, 0) == 0);
	CHECK(fclose(fp) == 0);
}
Ejemplo n.º 2
0
void
setup(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;
	char config[512];

	if ((ret = system("rm -f WiredTiger* *.bf")) != 0)
		testutil_die(ret, "system cleanup call failed");

	/*
	 * This test doesn't test public Wired Tiger functionality, it still
	 * needs connection and session handles.
	 */

	/*
	 * Open configuration -- put command line configuration options at the
	 * end so they can override "standard" configuration.
	 */
	snprintf(config, sizeof(config),
	    "create,error_prefix=\"%s\",cache_size=%" PRIu32 "MB,%s",
	    g.progname, g.c_cache, g.config_open == NULL ? "" : g.config_open);

	testutil_check(wiredtiger_open(NULL, NULL, config, &conn));

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

	g.wt_conn = conn;
	g.wt_session = session;
	populate_entries();
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
int
main(int argc, char *argv[])
{
	WT_CONNECTION *conn;
	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", &conn));

	/*! [add collator nocase] */
	error_check(conn->add_collator(conn, "nocase", &nocasecoll, NULL));
	/*! [add collator nocase] */
	/*! [add collator prefix10] */
	error_check(conn->add_collator(conn, "prefix10", &pcoll10.iface, NULL));

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

	/* Do some work... */

	error_check(conn->close(conn, NULL));
	/*! [add collator prefix10] */

	return (EXIT_SUCCESS);
}
Ejemplo n.º 5
0
int main(void)
{
	int ret;
	WT_CONNECTION *conn;
	WT_SESSION *session;

	/*! [processes] */
	/* Open a connection to the database, creating it if necessary. */
	if ((ret =
	    wiredtiger_open(home, NULL, "create,multiprocess", &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));

	/* XXX Do some work... */

	/* 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));
	/*! [processes] */

	return (ret);
}
Ejemplo n.º 6
0
/*
 * 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);
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: ajdavis/mongo
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;
	}
}
Ejemplo n.º 8
0
/*! [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);
}
Ejemplo n.º 9
0
void
wts_salvage(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;

	conn = g.wts_conn;

	track("salvage", 0ULL, NULL);

	/*
	 * Save a copy of the interesting files so we can replay the salvage
	 * step as necessary.
	 */
	if ((ret = system(
	    "cd RUNDIR && "
	    "rm -rf slvg.copy && "
	    "mkdir slvg.copy && "
	    "cp WiredTiger* wt* slvg.copy/")) != 0)
		die(ret, "salvage copy step failed");

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		die(ret, "connection.open_session");
	if ((ret = session->salvage(session, g.uri, NULL)) != 0)
		die(ret, "session.salvage: %s", g.uri);
	if ((ret = session->close(session, NULL)) != 0)
		die(ret, "session.close");
}
Ejemplo n.º 10
0
/*
 * 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);
}
Ejemplo n.º 11
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));
}
Ejemplo n.º 12
0
static int
config_event_handler(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;

	/*! [Configure event_handler] */
	CUSTOM_EVENT_HANDLER event_handler;

	event_handler.h.handle_error = handle_wiredtiger_error;
	event_handler.h.handle_message = handle_wiredtiger_message;
	/* Set handlers to NULL to use the default handler. */
	event_handler.h.handle_progress = NULL;
	event_handler.h.handle_close = NULL;
	event_handler.app_id = "example_event_handler";

	ret = wiredtiger_open(home,
	    (WT_EVENT_HANDLER *)&event_handler, "create", &conn);
	/*! [Configure event_handler] */

	/* Make an invalid API call, to ensure the event handler works. */
	printf("ex_event_handler: expect an error message to follow\n");
	ret = conn->open_session(conn, NULL, "isolation=invalid", &session);

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

	return (ret);
}
Ejemplo n.º 13
0
void
wts_rebalance(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	char cmd[1024];

	if (g.c_rebalance == 0)
		return;

	track("rebalance", 0ULL, NULL);

	/* Dump the current object. */
	testutil_check(__wt_snprintf(cmd, sizeof(cmd),
	    ".." DIR_DELIM_STR ".." DIR_DELIM_STR "wt"
	    " -h %s dump -f %s/rebalance.orig %s",
	    g.home, g.home, g.uri));
	testutil_checkfmt(system(cmd), "command failed: %s", cmd);

	/* Rebalance, then verify the object. */
	wts_reopen();
	conn = g.wts_conn;
	testutil_check(conn->open_session(conn, NULL, NULL, &session));
	if (g.logging != 0)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== rebalance start ===============");

	testutil_checkfmt(
	    session->rebalance(session, g.uri, NULL), "%s", g.uri);

	if (g.logging != 0)
		(void)g.wt_api->msg_printf(g.wt_api, session,
		    "=============== rebalance stop ===============");
	testutil_check(session->close(session, NULL));

	wts_verify("post-rebalance verify");
	wts_close();

	testutil_check(__wt_snprintf(cmd, sizeof(cmd),
	    ".." DIR_DELIM_STR ".." DIR_DELIM_STR "wt"
	    " -h %s dump -f %s/rebalance.new %s",
	    g.home, g.home, g.uri));
	testutil_checkfmt(system(cmd), "command failed: %s", cmd);

	/* Compare the old/new versions of the object. */
#ifdef _WIN32
	testutil_check(__wt_snprintf(cmd, sizeof(cmd),
	    "fc /b %s\\rebalance.orig %s\\rebalance.new > NUL",
	    g.home, g.home));
#else
	testutil_check(__wt_snprintf(cmd, sizeof(cmd),
	    "cmp %s/rebalance.orig %s/rebalance.new > /dev/null",
	    g.home, g.home));
#endif
	testutil_checkfmt(system(cmd), "command failed: %s", cmd);
}
Ejemplo n.º 14
0
int
main(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int i, j, k, 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;

	/* 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 == NULL ? "." : home, wiredtiger_strerror(ret));
		return (EXIT_FAILURE);
	}

	/* 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 == NULL ? "." : home, wiredtiger_strerror(ret));
		return (EXIT_FAILURE);
	}

	{
	/*! [packing] */
	size_t size;
	char buf[50];

	ret = wiredtiger_struct_size(session, &size, "iii", 42, 1000, -9);
	if (size > sizeof(buf)) {
		/* Allocate a bigger buffer. */
	}

	ret = wiredtiger_struct_pack(session, buf, size, "iii", 42, 1000, -9);

	ret = wiredtiger_struct_unpack(session, buf, size, "iii", &i, &j, &k);
	/*! [packing] */
	}

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

	return (EXIT_SUCCESS);
}
Ejemplo n.º 15
0
/*
 * 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");
}
Ejemplo n.º 16
0
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);
}
Ejemplo n.º 17
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);
}
Ejemplo n.º 18
0
/*
 * salvage --
 *	A single salvage.
 */
static void
salvage(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;

	conn = g.wts_conn;
	track("salvage", 0ULL, NULL);

	testutil_check(conn->open_session(conn, NULL, NULL, &session));
	testutil_check(session->salvage(session, g.uri, "force=true"));
	testutil_check(session->close(session, NULL));
}
Ejemplo n.º 19
0
Archivo: main.c Proyecto: 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);
}
Ejemplo n.º 20
0
void
verify(SHARED_CONFIG *cfg, const char *name)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;

	conn = cfg->conn;

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

	testutil_check(session->verify(session, name, NULL));

	testutil_check(session->close(session, NULL));
}
Ejemplo n.º 21
0
static int
run_child(const char *homedir, int op, int expect)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	int i, ret;
	const char *cfg;

	/*
	 * We expect the read-only database will allow the second read-only
	 * handle to succeed because no one can create or set the lock file.
	 */
	if (op == OP_READ)
		cfg = ENV_CONFIG_RD;
	else
		cfg = ENV_CONFIG_WR;
	if ((ret = wiredtiger_open(homedir, NULL, cfg, &conn)) == 0) {
		if (expect == EXPECT_ERR)
			testutil_die(
			    ret, "wiredtiger_open expected error, succeeded");
	} else {
		if (expect == EXPECT_SUCCESS)
			testutil_die(
			    ret, "wiredtiger_open expected success, error");
		/*
		 * If we expect an error and got one, we're done.
		 */
		return (0);
	}

	/*
	 * Make sure we can read the data.
	 */
	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		testutil_die(ret, "WT_CONNECTION:open_session");

	if ((ret =
	    session->open_cursor(session, uri, NULL, NULL, &cursor)) != 0)
		testutil_die(ret, "WT_SESSION.open_cursor: %s", uri);

	i = 0;
	while ((ret = cursor->next(cursor)) == 0)
		++i;
	if (i != MAX_KV)
		testutil_die(EPERM, "cursor walk");
	if ((ret = conn->close(conn, NULL)) != 0)
		testutil_die(ret, "conn_close");
	return (0);
}
Ejemplo n.º 22
0
/*
 * compaction --
 *	Periodically do a compaction operation.
 */
WT_THREAD_RET
compact(void *arg)
{
	WT_CONNECTION *conn;
	WT_DECL_RET;
	WT_SESSION *session;
	u_int period;

	(void)(arg);

	/* Compaction isn't supported for all data sources. */
	if (DATASOURCE("helium") || DATASOURCE("kvsbdb"))
		return (WT_THREAD_RET_VALUE);

	/* Open a session. */
	conn = g.wts_conn;
	testutil_check(conn->open_session(conn, NULL, NULL, &session));

	/*
	 * Perform compaction at somewhere under 15 seconds (so we get at
	 * least one done), and then at 23 second intervals.
	 */
	for (period = mmrand(NULL, 1, 15);; period = 23) {
		/* Sleep for short periods so we don't make the run wait. */
		while (period > 0 && !g.workers_finished) {
			--period;
			__wt_sleep(1, 0);
		}
		if (g.workers_finished)
			break;

		/*
		 * Compact can return EBUSY if concurrent with alter or if there
		 * is eviction pressure, or we collide with checkpoints.
		 *
		 * Compact returns ETIMEDOUT if the compaction doesn't finish in
		 * in some number of seconds. We don't configure a timeout and
		 * occasionally exceed the default of 1200 seconds.
		 */
		ret = session->compact(session, g.uri, NULL);
		if (ret != 0 &&
		    ret != EBUSY && ret != ETIMEDOUT && ret != WT_ROLLBACK)
			testutil_die(ret, "session.compact");
	}

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

	return (WT_THREAD_RET_VALUE);
}
Ejemplo n.º 23
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);
}
Ejemplo n.º 24
0
/*
 * salvage --
 *	A single salvage.
 */
static void
salvage(void)
{
	WT_CONNECTION *conn;
	WT_DECL_RET;
	WT_SESSION *session;

	conn = g.wts_conn;
	track("salvage", 0ULL, NULL);

	testutil_check(conn->open_session(conn, NULL, NULL, &session));
	if ((ret = session->salvage(session, g.uri, "force=true")) != 0)
		testutil_die(ret, "session.salvage: %s", g.uri);
	testutil_check(session->close(session, NULL));
}
Ejemplo n.º 25
0
void
load(SHARED_CONFIG *cfg, const char *name)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_ITEM *value, _value;
	WT_SESSION *session;
	size_t len;
	uint64_t keyno;
	char keybuf[64], valuebuf[64];

	conn = cfg->conn;

	file_create(cfg, name);

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

	testutil_check(
	    session->open_cursor(session, name, NULL, "bulk", &cursor));

	value = &_value;
	for (keyno = 1; keyno <= cfg->nkeys; ++keyno) {
		if (cfg->ftype == ROW) {
			testutil_check(__wt_snprintf(
			    keybuf, sizeof(keybuf), "%016" PRIu64, keyno));
			cursor->set_key(cursor, keybuf);
		} else
			cursor->set_key(cursor, (uint32_t)keyno);
		value->data = valuebuf;
		if (cfg->ftype == FIX)
			cursor->set_value(cursor, 0x01);
		else {
			testutil_check(__wt_snprintf_len_set(
			    valuebuf, sizeof(valuebuf),
			    &len, "%37" PRIu64, keyno));
			value->size = (uint32_t)len;
			cursor->set_value(cursor, value);
		}
		testutil_check(cursor->insert(cursor));
	}

	/* Setup the starting key range for the workload phase. */
	cfg->key_range = cfg->nkeys;
	testutil_check(cursor->close(cursor));
	testutil_check(session->checkpoint(session, NULL));

	testutil_check(session->close(session, NULL));
}
Ejemplo n.º 26
0
Archivo: main.c Proyecto: jbreams/mongo
/*
 * 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);
}
Ejemplo n.º 27
0
	explicit WtDbTransaction(WtWritableSegment* seg)
		: m_seg(seg), m_sconf(*seg->m_schema)
	{
		WT_CONNECTION* conn = seg->m_wtConn;
		int err = conn->open_session(conn, NULL, NULL, &m_session.ses);
		if (err) {
			THROW_STD(invalid_argument
				, "FATAL: wiredtiger open session(dir=%s) = %s"
				, conn->get_home(conn), wiredtiger_strerror(err)
				);
		}
		WT_SESSION* ses = m_session.ses;
		err = ses->open_cursor(ses, g_dataStoreUri, NULL, "overwrite=true", &m_store.cursor);
		if (err) {
			THROW_STD(invalid_argument
				, "ERROR: wiredtiger store open cursor: %s"
				, ses->strerror(ses, err));
		}
		m_indices.resize(seg->m_indices.size());
		for (size_t indexId = 0; indexId < m_indices.size(); ++indexId) {
			ReadableIndex* index = seg->m_indices[indexId].get();
			WtWritableIndex* wtIndex = dynamic_cast<WtWritableIndex*>(index);
			assert(NULL != wtIndex);
			const char* uri = wtIndex->getIndexUri().c_str();
			err = ses->open_cursor(ses, uri, NULL, "overwrite=false", &m_indices[indexId].insert.cursor);
			if (err) {
				THROW_STD(invalid_argument
					, "ERROR: wiredtiger open index cursor: %s"
					, ses->strerror(ses, err));
			}
			err = ses->open_cursor(ses, uri, NULL, "overwrite=true", &m_indices[indexId].overwrite.cursor);
			if (err) {
				THROW_STD(invalid_argument
					, "ERROR: wiredtiger open index cursor: %s"
					, ses->strerror(ses, err));
			}
		}
		m_sizeDiff = 0;
		m_wrtStore = dynamic_cast<WtWritableStore*>(seg->m_wrtStore.get());
		assert(nullptr != m_store);
		g_wtDbTxnLiveCnt++;
		g_wtDbTxnCreatedCnt++;
		if (getEnvBool("TerarkDB_TrackBuggyObjectLife")) {
			fprintf(stderr, "DEBUG: WtDbTransaction live count = %zd, created = %zd\n"
				, g_wtDbTxnLiveCnt.load(), g_wtDbTxnCreatedCnt.load());
		}
	}
Ejemplo n.º 28
0
    int WiredTigerUtil::verifyTable(OperationContext* txn, const std::string& uri,
                                    std::vector<std::string>* errors) {

        class MyEventHandlers : public WT_EVENT_HANDLER {
        public:
            MyEventHandlers(std::vector<std::string>* errors)
                : WT_EVENT_HANDLER(defaultEventHandlers())
                , _errors(errors)
                , _defaultErrorHandler(handle_error)
            {
                handle_error = onError;
            }

        private:
            static int onError(WT_EVENT_HANDLER* handler, WT_SESSION* session, int error,
                               const char* message) {
                try {
                    MyEventHandlers* self = static_cast<MyEventHandlers*>(handler);
                    self->_errors->push_back(message);
                    return self->_defaultErrorHandler(handler, session, error, message);
                }
                catch (...) {
                    std::terminate();
                }
            }

            typedef int(*ErrorHandler)(WT_EVENT_HANDLER*, WT_SESSION*, int, const char*);

            std::vector<std::string>* const _errors;
            const ErrorHandler _defaultErrorHandler;
        } eventHandler(errors);

        // Try to close as much as possible to avoid EBUSY errors.
        WiredTigerRecoveryUnit::get(txn)->getSession(txn)->closeAllCursors();
        WiredTigerSessionCache* sessionCache = WiredTigerRecoveryUnit::get(txn)->getSessionCache();
        sessionCache->closeAll();

        // Open a new session with custom error handlers.
        WT_CONNECTION* conn = WiredTigerRecoveryUnit::get(txn)->getSessionCache()->conn();
        WT_SESSION* session;
        invariantWTOK(conn->open_session(conn, errors ? &eventHandler : NULL, NULL, &session));
        ON_BLOCK_EXIT(session->close, session, "");

        // Do the verify. Weird parens prevent treating "verify" as a macro.
        return (session->verify)(session, uri.c_str(), NULL);
    }
Ejemplo n.º 29
0
void *
checkpoint_worker(void *arg)
{
	CONFIG *cfg;
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;
	struct timeval e, s;
	uint32_t i;
	uint64_t ms;

	session = NULL;
	cfg = (CONFIG *)arg;
	conn = cfg->conn;

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
		lprintf(cfg, ret, 0,
		    "open_session failed in checkpoint thread.");
		goto err;
	}

	while (g_util_running) {
		/*
		 * TODO: do we care how long the checkpoint takes?
		 */
		/* Break the sleep up, so we notice interrupts faster. */
		for (i = 0; i < cfg->checkpoint_interval; i++) {
			sleep(cfg->report_interval);
			if (!g_util_running)
				break;
		}

		gettimeofday(&s, NULL);
		if ((ret = session->checkpoint(session, NULL)) != 0)
			/* Report errors and continue. */
			lprintf(cfg, ret, 0, "Checkpoint failed.");
		gettimeofday(&e, NULL);
		ms = (e.tv_sec * 1000) + (e.tv_usec / 1000.0);
		ms -= (s.tv_sec * 1000) + (s.tv_usec / 1000.0);
		lprintf(cfg, 0, 1,
		    "Finished checkpoint in %" PRIu64 " ms.", ms);
	}
err:	if (session != NULL)
		session->close(session, NULL);
	return (arg);
}
Ejemplo n.º 30
0
/*
 * salvage --
 *	A single salvage.
 */
static void
salvage(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;

	conn = g.wts_conn;
	track("salvage", 0ULL, NULL);

	if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
		die(ret, "connection.open_session");
	if ((ret = session->salvage(session, g.uri, "force=true")) != 0)
		die(ret, "session.salvage: %s", g.uri);
	if ((ret = session->close(session, NULL)) != 0)
		die(ret, "session.close");
}