Esempio n. 1
0
int
main(void)
{
	WT_CONNECTION *conn;
	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;

	/*! [Open a connection] */
	ret = wiredtiger_open(home, NULL,
	    "create,cache_size=5GB,log=(enabled,recover=on)", &conn);
	/*! [Open a connection] */

	if (ret == 0)
		ret = connection_ops(conn);
	/*
	 * The connection has been closed.
	 */

#ifdef MIGHT_NOT_RUN
	/*
	 * This example code gets run, and the compression libraries might not
	 * be installed, causing the open to fail.  The documentation requires
	 * the code snippets, use #ifdef's to avoid running it.
	 */
	/*! [Configure lz4 extension] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_lz4.so]", &conn);
	/*! [Configure lz4 extension] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Configure snappy extension] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_snappy.so]", &conn);
	/*! [Configure snappy extension] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Configure zlib extension] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_zlib.so]", &conn);
	/*! [Configure zlib extension] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Configure zlib extension with compression level] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/"
	    "libwiredtiger_zlib.so=[config=[compression_level=3]]]", &conn);
	/*! [Configure zlib extension with compression level] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Configure zstd extension] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_zstd.so]", &conn);
	/*! [Configure zstd extension] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Configure zstd extension with compression level] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/"
	    "libwiredtiger_zstd.so=[config=[compression_level=9]]]", &conn);
	/*! [Configure zstd extension with compression level] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*
	 * This example code gets run, and direct I/O might not be available,
	 * causing the open to fail.  The documentation requires code snippets,
	 * use #ifdef's to avoid running it.
	 */
	/* Might Not Run: direct I/O may not be available. */
	/*! [Configure direct_io for data files] */
	ret = wiredtiger_open(home, NULL, "create,direct_io=[data]", &conn);
	/*! [Configure direct_io for data files] */
	if (ret == 0)
		(void)conn->close(conn, NULL);
#endif

	/*! [Configure file_extend] */
	ret = wiredtiger_open(
	    home, NULL, "create,file_extend=(data=16MB)", &conn);
	/*! [Configure file_extend] */
	if (ret == 0)
		ret = conn->close(conn, NULL);

	/*! [Eviction configuration] */
	/*
	 * Configure eviction to begin at 90% full, and run until the cache
	 * is only 75% dirty.
	 */
	ret = wiredtiger_open(home, NULL,
	    "create,eviction_trigger=90,eviction_dirty_target=75", &conn);
	/*! [Eviction configuration] */
	if (ret == 0)
		ret = conn->close(conn, NULL);

	/*! [Eviction worker configuration] */
	/* Configure up to four eviction threads */
	ret = wiredtiger_open(home, NULL,
	    "create,eviction_trigger=90,eviction=(threads_max=4)", &conn);
	/*! [Eviction worker configuration] */
	if (ret == 0)
		ret = conn->close(conn, NULL);

	/*! [Statistics configuration] */
	ret = wiredtiger_open(home, NULL, "create,statistics=(all)", &conn);
	/*! [Statistics configuration] */
	if (ret == 0)
		ret = conn->close(conn, NULL);

	/*! [Statistics logging] */
	ret = wiredtiger_open(
	    home, NULL, "create,statistics_log=(wait=30)", &conn);
	/*! [Statistics logging] */
	if (ret == 0)
		ret = conn->close(conn, NULL);

#ifdef MIGHT_NOT_RUN
	/*
	 * Don't run this code, statistics logging doesn't yet support tables.
	 */
	/*! [Statistics logging with a table] */
	ret = wiredtiger_open(home, NULL,
	    "create, statistics_log=("
	    "sources=(\"table:table1\",\"table:table2\"), wait=5)",
	    &conn);
	/*! [Statistics logging with a table] */
	if (ret == 0)
		ret = conn->close(conn, NULL);

	/*
	 * Don't run this code, statistics logging doesn't yet support indexes.
	 */
	/*! [Statistics logging with a source type] */
	ret = wiredtiger_open(home, NULL,
	    "create, statistics_log=(sources=(\"index:\"), wait=5)",
	    &conn);
	/*! [Statistics logging with a source type] */
	if (ret == 0)
		ret = conn->close(conn, NULL);

	/*
	 * Don't run this code, because memory checkers get very upset when we
	 * leak memory.
	 */
	(void)wiredtiger_open(home, NULL, "create", &conn);
	/*! [Connection close leaking memory] */
	ret = conn->close(conn, "leak_memory=true");
	/*! [Connection close leaking memory] */
#endif

	/*! [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_v, minor_v, patch;
	(void)wiredtiger_version(&major_v, &minor_v, &patch);
	printf("WiredTiger version is %d, %d (patch %d)\n",
	    major_v, minor_v, patch);
	/*! [Get the WiredTiger library version #2] */
	}

	return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
Esempio n. 2
0
int
main(void)
{
	WT_CONNECTION *conn;
	int ret;

	/*! [Open a connection] */
	ret = wiredtiger_open(home, NULL, "create,cache_size=500M", &conn);
	/*! [Open a connection] */

	if (ret == 0)
		connection_ops(conn);
	/*
	 * The connection has been closed.
	 */

#ifdef MIGHT_NOT_RUN
	/*
	 * This example code gets run, and the compression libraries might not
	 * be installed, causing the open to fail.  The documentation requires
	 * the code snippets, use #ifdef's to avoid running it.
	 */
	/*! [Configure bzip2 extension] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_bzip2.so]", &conn);
	/*! [Configure bzip2 extension] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Configure snappy extension] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_snappy.so]", &conn);
	/*! [Configure snappy extension] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Configure zlib extension] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_zlib.so]", &conn);
	/*! [Configure zlib extension] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*
	 * This example code gets run, and direct I/O might not be available,
	 * causing the open to fail.  The documentation requires code snippets,
	 * use #ifdef's to avoid running it.
	 */
	/* Might Not Run: direct I/O may not be available. */
	/*! [Configure direct_io for data files] */
	ret = wiredtiger_open(home, NULL, "create,direct_io=[data]", &conn);
	/*! [Configure direct_io for data files] */
	if (ret == 0)
		(void)conn->close(conn, NULL);
#endif

	/*! [Configure file_extend] */
	ret = wiredtiger_open(
	    home, NULL, "create,file_extend=(data=16MB)", &conn);
	/*! [Configure file_extend] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Statistics configuration] */
	ret = wiredtiger_open(home, NULL, "create,statistics=(all)", &conn);
	/*! [Statistics configuration] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Statistics logging] */
	ret = wiredtiger_open(
	    home, NULL, "create,statistics_log=(wait=30)", &conn);
	/*! [Statistics logging] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Statistics logging with a table] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "statistics_log=(sources=(\"table:table1\",\"table:table2\"))",
	    &conn);
	/*! [Statistics logging with a table] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

	/*! [Statistics logging with all tables] */
	ret = wiredtiger_open(home, NULL,
	    "create,statistics_log=(sources=(\"table:\"))",
	    &conn);
	/*! [Statistics logging with all tables] */
	if (ret == 0)
		(void)conn->close(conn, NULL);

#ifdef MIGHT_NOT_RUN
	/*
	 * This example code gets run, and a non-existent log file path might
	 * cause the open to fail.  The documentation requires code snippets,
	 * use #ifdef's to avoid running it.
	 */
	/*! [Statistics logging with path] */
	ret = wiredtiger_open(home, NULL,
	    "create,"
	    "statistics_log=(wait=120,path=/log/log.%m.%d.%y)", &conn);
	/*! [Statistics logging with path] */
	if (ret == 0)
		(void)conn->close(conn, NULL);
#endif

	/*! [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);
}
Esempio n. 3
0
int
main(int argc, char *argv[])
{
	WT_CONNECTION *conn;

	home = example_setup(argc, argv);

	/*! [Open a connection] */
	error_check(wiredtiger_open(home, NULL,
	    "create,cache_size=5GB,log=(enabled,recover=on),statistics=(all)",
	    &conn));
	/*! [Open a connection] */

	connection_ops(conn);
	/*
	 * The connection has been closed.
	 */

#ifdef MIGHT_NOT_RUN
	/*
	 * This example code gets run, and the compression libraries might not
	 * be installed, causing the open to fail.  The documentation requires
	 * the code snippets, use #ifdef's to avoid running it.
	 */
	/*! [Configure lz4 extension] */
	error_check(wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_lz4.so]", &conn));
	/*! [Configure lz4 extension] */
	error_check(conn->close(conn, NULL));

	/*! [Configure snappy extension] */
	error_check(wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_snappy.so]", &conn));
	/*! [Configure snappy extension] */
	error_check(conn->close(conn, NULL));

	/*! [Configure zlib extension] */
	error_check(wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_zlib.so]", &conn));
	/*! [Configure zlib extension] */
	error_check(conn->close(conn, NULL));

	/*! [Configure zlib extension with compression level] */
	error_check(wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/"
	    "libwiredtiger_zlib.so=[config=[compression_level=3]]]", &conn));
	/*! [Configure zlib extension with compression level] */
	error_check(conn->close(conn, NULL));

	/*! [Configure zstd extension] */
	error_check(wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/libwiredtiger_zstd.so]", &conn));
	/*! [Configure zstd extension] */
	error_check(conn->close(conn, NULL));

	/*! [Configure zstd extension with compression level] */
	error_check(wiredtiger_open(home, NULL,
	    "create,"
	    "extensions=[/usr/local/lib/"
	    "libwiredtiger_zstd.so=[config=[compression_level=9]]]", &conn));
	/*! [Configure zstd extension with compression level] */
	error_check(conn->close(conn, NULL));

	/*
	 * This example code gets run, and direct I/O might not be available,
	 * causing the open to fail.  The documentation requires code snippets,
	 * use #ifdef's to avoid running it.
	 */
	/* Might Not Run: direct I/O may not be available. */
	/*! [Configure direct_io for data files] */
	error_check(wiredtiger_open(
	    home, NULL, "create,direct_io=[data]", &conn));
	/*! [Configure direct_io for data files] */
	error_check(conn->close(conn, NULL));
#endif

	/*! [Configure file_extend] */
	error_check(wiredtiger_open(
	    home, NULL, "create,file_extend=(data=16MB)", &conn));
	/*! [Configure file_extend] */
	error_check(conn->close(conn, NULL));

	/*! [Eviction configuration] */
	/*
	 * Configure eviction to begin at 90% full, and run until the cache
	 * is only 75% dirty.
	 */
	error_check(wiredtiger_open(home, NULL,
	    "create,eviction_trigger=90,eviction_dirty_target=75", &conn));
	/*! [Eviction configuration] */
	error_check(conn->close(conn, NULL));

	/*! [Eviction worker configuration] */
	/* Configure up to four eviction threads */
	error_check(wiredtiger_open(home, NULL,
	    "create,eviction_trigger=90,eviction=(threads_max=4)", &conn));
	/*! [Eviction worker configuration] */
	error_check(conn->close(conn, NULL));

	/*! [Statistics configuration] */
	error_check(wiredtiger_open(
	    home, NULL, "create,statistics=(all)", &conn));
	/*! [Statistics configuration] */
	error_check(conn->close(conn, NULL));

	/*! [Statistics logging] */
	error_check(wiredtiger_open(
	    home, NULL, "create,statistics_log=(wait=30)", &conn));
	/*! [Statistics logging] */
	error_check(conn->close(conn, NULL));

#ifdef MIGHT_NOT_RUN
	/*
	 * Don't run this code, statistics logging doesn't yet support tables.
	 */
	/*! [Statistics logging with a table] */
	error_check(wiredtiger_open(home, NULL,
	    "create, statistics_log=("
	    "sources=(\"table:table1\",\"table:table2\"), wait=5)", &conn));
	/*! [Statistics logging with a table] */
	error_check(conn->close(conn, NULL));

	/*
	 * Don't run this code, statistics logging doesn't yet support indexes.
	 */
	/*! [Statistics logging with a source type] */
	error_check(wiredtiger_open(home, NULL,
	    "create, statistics_log=(sources=(\"index:\"), wait=5)", &conn));
	/*! [Statistics logging with a source type] */
	error_check(conn->close(conn, NULL));

	/*
	 * Don't run this code, because memory checkers get very upset when we
	 * leak memory.
	 */
	error_check(wiredtiger_open(home, NULL, "create", &conn));
	/*! [Connection close leaking memory] */
	error_check(conn->close(conn, "leak_memory=true"));
	/*! [Connection close leaking memory] */
#endif

	/*! [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_v, minor_v, patch;
	(void)wiredtiger_version(&major_v, &minor_v, &patch);
	printf("WiredTiger version is %d, %d (patch %d)\n",
	    major_v, minor_v, patch);
	/*! [Get the WiredTiger library version #2] */
	}

	{
	/*! [Calculate a modify operation] */
	WT_MODIFY mod[3];
	int nmod = 3;
	WT_ITEM prev, newv;
	prev.data = "the quick brown fox jumped over the lazy dog. " \
		"THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \
		"the quick brown fox jumped over the lazy dog. " \
		"THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. ";
	prev.size = strlen(prev.data);
	newv.data = "A quick brown fox jumped over the lazy dog. " \
		"THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \
		"then a quick brown fox jumped over the lazy dog. " \
		"THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. " \
		"then what?";
	newv.size = strlen(newv.data);
	error_check(wiredtiger_calc_modify(NULL, &prev, &newv, 20, mod, &nmod));
	/*! [Calculate a modify operation] */
	}

	{
	const char *buffer = "some string";
	size_t len = strlen(buffer);
	/*! [Checksum a buffer] */
	uint32_t crc32c, (*func)(const void *, size_t);
	func = wiredtiger_crc32c_func();
	crc32c = func(buffer, len);
	/*! [Checksum a buffer] */
	(void)crc32c;
	}

	return (EXIT_SUCCESS);
}