当前位置: 首页>>代码示例>>C++>>正文


C++ WT_CONNECTION::async_flush方法代码示例

本文整理汇总了C++中WT_CONNECTION::async_flush方法的典型用法代码示例。如果您正苦于以下问题:C++ WT_CONNECTION::async_flush方法的具体用法?C++ WT_CONNECTION::async_flush怎么用?C++ WT_CONNECTION::async_flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WT_CONNECTION的用法示例。


在下文中一共展示了WT_CONNECTION::async_flush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sizeof

int
main(void)
{
	WT_ASYNC_OP *op;
	WT_CONNECTION *conn;
	WT_SESSION *session;
	int i, ret;
	char k[MAX_KEYS][16], v[MAX_KEYS][16];

	/*! [async example connection] */
	ret = wiredtiger_open(home, NULL,
	    "create,cache_size=100MB,"
	    "async=(enabled=true,ops_max=20,threads=2)", &conn);
	/*! [async example connection] */

	/*! [async example table create] */
	ret = conn->open_session(conn, NULL, NULL, &session);
	ret = session->create(
	    session, "table:async", "key_format=S,value_format=S");
	/*! [async example table create] */

	/* Insert a set of keys asynchronously. */
	for (i = 0; i < MAX_KEYS; i++) {
		/*! [async handle allocation] */
		while ((ret = conn->async_new_op(conn,
		    "table:async", NULL, &ex_asynckeys.iface, &op)) != 0) {
			/*
			 * If we used up all the handles, pause and retry to
			 * give the workers a chance to catch up.
			 */
			fprintf(stderr,
			    "asynchronous operation handle not available\n");
			if (ret == EBUSY)
				sleep(1);
			else
				return (ret);
		}
		/*! [async handle allocation] */

		/*! [async insert] */
		/*
		 * Set the operation's string key and value, and then do
		 * an asynchronous insert.
		 */
		/*! [async set the operation's string key] */
		snprintf(k[i], sizeof(k), "key%d", i);
		op->set_key(op, k[i]);
		/*! [async set the operation's string key] */

		/*! [async set the operation's string value] */
		snprintf(v[i], sizeof(v), "value%d", i);
		op->set_value(op, v[i]);
		/*! [async set the operation's string value] */

		ret = op->insert(op);
		/*! [async insert] */
	}

	/*! [async flush] */
	/* Wait for all outstanding operations to complete. */
	ret = conn->async_flush(conn);
	/*! [async flush] */

	/*! [async compaction] */
	/*
	 * Compact a table asynchronously, limiting the run-time to 5 minutes.
	 */
	ret = conn->async_new_op(
	    conn, "table:async", "timeout=300", &ex_asynckeys.iface, &op);
	ret = op->compact(op);
	/*! [async compaction] */

	/* Search for the keys we just inserted, asynchronously. */
	for (i = 0; i < MAX_KEYS; i++) {
		while ((ret = conn->async_new_op(conn,
		    "table:async", NULL, &ex_asynckeys.iface, &op)) != 0) {
			/*
			 * If we used up all the handles, pause and retry to
			 * give the workers a chance to catch up.
			 */
			fprintf(stderr,
			    "asynchronous operation handle not available\n");
			if (ret == EBUSY)
				sleep(1);
			else
				return (ret);
		}

		/*! [async search] */
		/*
		 * Set the operation's string key and value, and then do
		 * an asynchronous search.
		 */
		snprintf(k[i], sizeof(k), "key%d", i);
		op->set_key(op, k[i]);
		op->search(op);
		/*! [async search] */
	}

	/*
//.........这里部分代码省略.........
开发者ID:EaseTech,项目名称:wiredtiger,代码行数:101,代码来源:ex_async.c


注:本文中的WT_CONNECTION::async_flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。