summaryrefslogtreecommitdiff
path: root/src/btree/bt_sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/btree/bt_sync.c')
-rw-r--r--src/btree/bt_sync.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/btree/bt_sync.c b/src/btree/bt_sync.c
new file mode 100644
index 00000000000..af5a9d65258
--- /dev/null
+++ b/src/btree/bt_sync.c
@@ -0,0 +1,61 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2008-2011 WiredTiger, Inc.
+ * All rights reserved.
+ *
+ * $Id$
+ */
+
+#include "wt_internal.h"
+
+static int __wt_bt_tree_sync(WT_TOC *, WT_PAGE *, void *);
+
+/*
+ * __wt_bt_sync --
+ * Sync the tree.
+ */
+int
+__wt_bt_sync(WT_TOC *toc)
+{
+ ENV *env;
+ IDB *idb;
+ WT_CACHE *cache;
+ int ret;
+
+ env = toc->env;
+ idb = toc->db->idb;
+ cache = env->ienv->cache;
+
+ if (WT_UNOPENED_DATABASE(idb))
+ return (0);
+
+ /*
+ * The tree walk is depth first, that is, the worker function is not
+ * called on internal pages until all children have been visited; so,
+ * we don't have to worry about a page being dirtied after the visit.
+ *
+ * Lock out the cache eviction thread, though, we don't want it trying
+ * to reconcile pages we're flushing.
+ */
+ __wt_lock(env, cache->mtx_reconcile);
+ ret = __wt_tree_walk(toc, NULL,
+ WT_WALK_CACHE | WT_WALK_OFFDUP, __wt_bt_tree_sync, NULL);
+ __wt_unlock(env, cache->mtx_reconcile);
+ return (ret);
+}
+
+/*
+ * __wt_bt_tree_sync --
+ * Sync a page.
+ */
+static int
+__wt_bt_tree_sync(WT_TOC *toc, WT_PAGE *page, void *arg)
+{
+ WT_CC_QUIET(arg, NULL);
+
+ /* Reconcile any dirty pages. */
+ if (WT_PAGE_IS_MODIFIED(page))
+ WT_RET(__wt_page_reconcile(toc, page));
+ return (0);
+}