Пример #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);
}
Пример #2
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);
}
Пример #3
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);
}
Пример #4
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);
}
Пример #5
0
int
main(int argc, char *argv[])
{
	WT_CONNECTION *conn;
	int ret;

	(void)argc;					/* Unused variable */

	/*
	 * This code deliberately doesn't use the standard test_util macros,
	 * we don't want to link against that code to smoke-test a build.
	 */
	(void)system("rm -rf WT_HOME && mkdir WT_HOME");

	/* Open a connection to the database, creating it if necessary. */
	if ((ret = wiredtiger_open("WT_HOME", NULL, "create", &conn)) != 0) {
		fprintf(stderr,
		    "%s: wiredtiger_open: %s\n",
		    argv[0], wiredtiger_strerror(ret));
		return (EXIT_FAILURE);
	}

	/* Close the connection to the database. */
	if ((ret = conn->close(conn, NULL)) != 0) {
		fprintf(stderr,
		    "%s: WT_CONNECTION.close: %s\n",
		    argv[0], wiredtiger_strerror(ret));
		return (EXIT_FAILURE);
	}

	return (EXIT_SUCCESS);
}
Пример #6
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);
}
Пример #7
0
int
main(void)
{
	int ret;

	{
	/*! [Open a connection] */
	WT_CONNECTION *conn;
	const char *home = "WT_TEST";
	ret = wiredtiger_open(home, NULL, "create,transactional", &conn);
	/*! [Open a connection] */

	(void)conn->close(conn, NULL);
	}

	/*! [Get the WiredTiger library version #1] */
	printf("WiredTiger version %s\n", wiredtiger_version(NULL, NULL, NULL));
	/*! [Get the WiredTiger library version #1] */

	{
	/*! [Get the WiredTiger library version #2] */
	int major, minor, patch;
	(void)wiredtiger_version(&major, &minor, &patch);
	printf("WiredTiger version is %d, %d (patch %d)\n",
	    major, minor, patch);
	/*! [Get the WiredTiger library version #2] */
	}

	return (ret);
}
Пример #8
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);
}
Пример #9
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);
}
Пример #10
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);
}
Пример #11
0
void
wts_close()
{
	WT_CONNECTION *conn;
	int ret;

	conn = g.wts_conn;

	if ((ret = conn->close(conn, NULL)) != 0)
		die(ret, "connection.close");
}
Пример #12
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);
}
Пример #13
0
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);
}
Пример #14
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);
}
Пример #15
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);
}
Пример #16
0
static void
open_normal(const char *sfx, TABLE_INFO *table_data)
{
	WT_CONNECTION *conn;
	char buf[1024];

	printf("=== wt_open normal ===\n");
	if (sfx != NULL)
		testutil_check(__wt_snprintf(buf, sizeof(buf),
		    "%s.%s", home, sfx));
	else
		testutil_check(__wt_snprintf(buf, sizeof(buf), "%s", home));
	testutil_check(wiredtiger_open(buf, &event_handler, NULL, &conn));
	verify_metadata(conn, &table_data[0]);
	testutil_check(conn->close(conn, NULL));
}
Пример #17
0
/*
 * wt_shutdown --
 *	Flush the file to disk and shut down the WiredTiger connection.
 */
static void
wt_shutdown(SHARED_CONFIG *cfg)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;

	conn = cfg->conn;

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

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

	if ((ret = conn->close(conn, NULL)) != 0)
		testutil_die(ret, "conn.close");
}
Пример #18
0
/*
 * check_copy --
 *	Confirm the backup worked.
 */
static void
check_copy(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;

	wts_open(g.home_backup, 0, &conn);

	testutil_checkfmt(
	    conn->open_session(conn, NULL, NULL, &session),
	    "%s", g.home_backup);

	testutil_checkfmt(
	    session->verify(session, g.uri, NULL),
	    "%s: %s", g.home_backup, g.uri);

	testutil_checkfmt(conn->close(conn, NULL), "%s", g.home_backup);
}
Пример #19
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);
}
Пример #20
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);
}
Пример #21
0
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);
}
Пример #22
0
/*
 * check_copy --
 *	Confirm the backup worked.
 */
static void
check_copy(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int ret;

	wts_open(g.home_backup, 0, &conn);

	if ((ret = conn->open_session(
	    conn, NULL, NULL, &session)) != 0)
		die(ret, "connection.open_session: %s", g.home_backup);

	ret = session->verify(session, g.uri, NULL);
	if (ret != 0)
		die(ret, "session.verify: %s: %s", g.home_backup, g.uri);

	if ((ret = conn->close(conn, NULL)) != 0)
		die(ret, "connection.close: %s", g.home_backup);
}
Пример #23
0
int
main(int argc, char *argv[])
{
	WT_CONNECTION *conn;
	WT_SESSION *session;

	home = example_setup(argc, argv);

	error_check(
	    wiredtiger_open(home, NULL, "create,cache_size=500M", &conn));
	add_extractor(conn);
	error_check(conn->open_session(conn, NULL, NULL, &session));

	setup_table(session);
	read_index(session);
	remove_items(session);

	error_check(conn->close(conn, NULL));

	return (EXIT_SUCCESS);
}
Пример #24
0
int main(void)
{
	int ret;
	WT_CONNECTION *conn;
	WT_SESSION *session;
	WT_CURSOR *cursor;
	const char *key, *value;

	/*! [configure cache size] */
	if ((ret = wiredtiger_open(home, NULL,
	    "create,cache_size=500M", &conn)) != 0)
		fprintf(stderr, "Error connecting to %s: %s\n",
		    home, wiredtiger_strerror(ret));
	/*! [configure cache size] */

	/*! [create a table] */
	ret = conn->open_session(conn, NULL, NULL, &session);

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

	/*! [transaction] */
	ret = session->begin_transaction(session, "priority=100,name=mytxn");

	ret = session->open_cursor(session, "config:", NULL, NULL, &cursor);

	while ((ret = cursor->next(cursor)) == 0) {
		cursor->get_key(cursor, &key);
		cursor->get_value(cursor, &value);
		printf("configuration value: %s = %s\n", key, value);
	}

	ret = session->commit_transaction(session, NULL);
	/*! [transaction] */

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

	return (ret);
}
Пример #25
0
int
main(void)
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;
	int ret, tret;

	/*
	 * 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, create a simple table, open a cursor. */
	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);
	}

	ret = session->create(session,
	    "table:scope", "key_format=S,value_format=S,columns=(k,v)");

	ret = session->open_cursor(session,
	    "table:scope", NULL, NULL, &cursor);

	ret = cursor_scope_ops(cursor);

	/* Close the connection and clean up. */
	if ((tret = conn->close(conn, NULL)) != 0 && ret == 0)
		ret = tret;

	return (ret);
}
Пример #26
0
int
main(void)
{
	int ret;
	WT_CONNECTION *conn;
	WT_SESSION *session;

	/*
	 * 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));

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

	/* 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));

	/* Do some work... */

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

	return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
Пример #27
0
int
main(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	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));
	/* Note: further error checking omitted for clarity. */

	/*! [file create] */
	ret = session->create(session, "file:example",
	    "key_format=u,"
	    "internal_page_max=32KB,internal_item_max=1KB,"
	    "leaf_page_max=1MB,leaf_item_max=32KB");
	/*! [file create] */

	return (conn->close(conn, NULL) == 0 ? ret : EXIT_FAILURE);
}
Пример #28
0
int
main(int argc, char *argv[])
{
	WT_CONNECTION *conn;
	WT_CURSOR *cursor;
	WT_SESSION *session;

	home = example_setup(argc, argv);

	error_check(
	    wiredtiger_open(home, NULL, "create,statistics=(all)", &conn));
	error_check(conn->open_session(conn, NULL, NULL, &session));
	error_check(session->create(session,
	    "table:access", "key_format=S,value_format=S,columns=(k,v)"));

	error_check(session->open_cursor(
	    session, "table:access", NULL, NULL, &cursor));
	cursor->set_key(cursor, "key");
	cursor->set_value(cursor, "value");
	error_check(cursor->insert(cursor));
	error_check(cursor->close(cursor));

	error_check(session->checkpoint(session, NULL));

	print_database_stats(session);

	print_file_stats(session);

	print_join_cursor_stats(session);

	print_overflow_pages(session);

	print_derived_stats(session);

	error_check(conn->close(conn, NULL));

	return (EXIT_SUCCESS);
}
Пример #29
0
static void
open_with_salvage(const char *sfx, TABLE_INFO *table_data)
{
	WT_CONNECTION *conn;
	char buf[1024];

	printf("=== wt_open with salvage ===\n");
	/*
	 * Then call wiredtiger_open with the salvage configuration setting.
	 * That should succeed. We should be able to then verify the contents
	 * of the metadata file.
	 */
	test_abort = true;
	if (sfx != NULL)
		testutil_check(__wt_snprintf(buf, sizeof(buf),
		    "%s.%s", home, sfx));
	else
		testutil_check(__wt_snprintf(buf, sizeof(buf), "%s", home));
	testutil_check(wiredtiger_open(buf,
	    &event_handler, "salvage=true", &conn));
	testutil_assert(conn != NULL);
	if (sfx != NULL)
		testutil_check(__wt_snprintf(buf, sizeof(buf),
		    "%s.%s/%s", home, sfx, WT_METAFILE_SLVG));
	else
		testutil_check(__wt_snprintf(buf, sizeof(buf),
		    "%s/%s", home, WT_METAFILE_SLVG));
	testutil_assert(file_exists(buf));

	/*
	 * Confirm we salvaged the metadata file by looking for the saved
	 * copy of the original metadata.
	 */
	printf("verify with salvaged connection\n");
	verify_metadata(conn, &table_data[0]);
	testutil_check(conn->close(conn, NULL));
}
Пример #30
0
int main(void)
{
	WT_CONNECTION *conn;
	WT_SESSION *session;
	char buf[50];
	size_t size;
	int i, j, k, 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));

	/*! [packing] */
	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 connecting to %s: %s\n",
		    home, wiredtiger_strerror(ret));

	return (ret);
}