summaryrefslogtreecommitdiff
path: root/src/conn
diff options
context:
space:
mode:
Diffstat (limited to 'src/conn')
-rw-r--r--src/conn/conn_cache_pool.c4
-rw-r--r--src/conn/conn_ckpt.c4
-rw-r--r--src/conn/conn_dhandle.c6
-rw-r--r--src/conn/conn_log.c14
-rw-r--r--src/conn/conn_stat.c4
-rw-r--r--src/conn/conn_sweep.c91
6 files changed, 76 insertions, 47 deletions
diff --git a/src/conn/conn_cache_pool.c b/src/conn/conn_cache_pool.c
index 7bf090496a8..488864ce351 100644
--- a/src/conn/conn_cache_pool.c
+++ b/src/conn/conn_cache_pool.c
@@ -596,7 +596,7 @@ __cache_pool_adjust(WT_SESSION_IMPL *session,
* __wt_cache_pool_server --
* Thread to manage cache pool among connections.
*/
-void *
+WT_THREAD_RET
__wt_cache_pool_server(void *arg)
{
WT_CACHE *cache;
@@ -642,5 +642,5 @@ __wt_cache_pool_server(void *arg)
if (0) {
err: WT_PANIC_MSG(session, ret, "cache pool manager server error");
}
- return (NULL);
+ return (WT_THREAD_RET_VALUE);
}
diff --git a/src/conn/conn_ckpt.c b/src/conn/conn_ckpt.c
index 503c22110f9..74f27d8bd18 100644
--- a/src/conn/conn_ckpt.c
+++ b/src/conn/conn_ckpt.c
@@ -69,7 +69,7 @@ err: __wt_scr_free(session, &tmp);
* __ckpt_server --
* The checkpoint server thread.
*/
-static void *
+static WT_THREAD_RET
__ckpt_server(void *arg)
{
WT_CONNECTION_IMPL *conn;
@@ -112,7 +112,7 @@ __ckpt_server(void *arg)
if (0) {
err: WT_PANIC_MSG(session, ret, "checkpoint server error");
}
- return (NULL);
+ return (WT_THREAD_RET_VALUE);
}
/*
diff --git a/src/conn/conn_dhandle.c b/src/conn/conn_dhandle.c
index 7756158594c..9f308a2569c 100644
--- a/src/conn/conn_dhandle.c
+++ b/src/conn/conn_dhandle.c
@@ -361,8 +361,7 @@ err: __wt_free(session, metaconf);
* Open the current btree handle.
*/
static int
-__conn_btree_open(
- WT_SESSION_IMPL *session, const char *cfg[], uint32_t flags)
+__conn_btree_open(WT_SESSION_IMPL *session, const char *cfg[], uint32_t flags)
{
WT_BTREE *btree;
WT_DATA_HANDLE *dhandle;
@@ -745,7 +744,8 @@ __wt_conn_dhandle_discard_single(WT_SESSION_IMPL *session, int final)
* Kludge: interrupt the eviction server in case it is holding the
* handle list lock.
*/
- F_SET(S2C(session)->cache, WT_CACHE_CLEAR_WALKS);
+ if (!F_ISSET(session, WT_SESSION_HANDLE_LIST_LOCKED))
+ F_SET(S2C(session)->cache, WT_CACHE_CLEAR_WALKS);
/* Try to remove the handle, protected by the data handle lock. */
WT_WITH_DHANDLE_LOCK(session,
diff --git a/src/conn/conn_log.c b/src/conn/conn_log.c
index 4b995114b09..a6d53134ec2 100644
--- a/src/conn/conn_log.c
+++ b/src/conn/conn_log.c
@@ -273,7 +273,7 @@ err:
* __log_close_server --
* The log close server thread.
*/
-static void *
+static WT_THREAD_RET
__log_close_server(void *arg)
{
WT_CONNECTION_IMPL *conn;
@@ -332,7 +332,7 @@ err: __wt_err(session, ret, "log close server error");
}
if (locked)
__wt_spin_unlock(session, &log->log_sync_lock);
- return (NULL);
+ return (WT_THREAD_RET_VALUE);
}
/*
@@ -347,7 +347,7 @@ typedef struct {
* __log_wrlsn_cmp --
* The log wrlsn comparison function for qsort.
*/
-static int
+static int WT_CDECL
__log_wrlsn_cmp(const void *a, const void *b)
{
WT_LOG_WRLSN_ENTRY *ae, *be;
@@ -361,7 +361,7 @@ __log_wrlsn_cmp(const void *a, const void *b)
* __log_wrlsn_server --
* The log wrlsn server thread.
*/
-static void *
+static WT_THREAD_RET
__log_wrlsn_server(void *arg)
{
WT_CONNECTION_IMPL *conn;
@@ -450,14 +450,14 @@ __log_wrlsn_server(void *arg)
if (0)
err: __wt_err(session, ret, "log wrlsn server error");
- return (NULL);
+ return (WT_THREAD_RET_VALUE);
}
/*
* __log_server --
* The log server thread.
*/
-static void *
+static WT_THREAD_RET
__log_server(void *arg)
{
WT_CONNECTION_IMPL *conn;
@@ -502,7 +502,7 @@ err: __wt_err(session, ret, "log server error");
}
if (locked)
(void)__wt_writeunlock(session, log->log_archive_lock);
- return (NULL);
+ return (WT_THREAD_RET_VALUE);
}
/*
diff --git a/src/conn/conn_stat.c b/src/conn/conn_stat.c
index 83c8d539662..0d008939d8c 100644
--- a/src/conn/conn_stat.c
+++ b/src/conn/conn_stat.c
@@ -380,7 +380,7 @@ err: __wt_scr_free(session, &tmp);
* __statlog_server --
* The statistics server thread.
*/
-static void *
+static WT_THREAD_RET
__statlog_server(void *arg)
{
WT_CONNECTION_IMPL *conn;
@@ -419,7 +419,7 @@ err: WT_PANIC_MSG(session, ret, "statistics log server error");
}
__wt_buf_free(session, &path);
__wt_buf_free(session, &tmp);
- return (NULL);
+ return (WT_THREAD_RET_VALUE);
}
/*
diff --git a/src/conn/conn_sweep.c b/src/conn/conn_sweep.c
index 50812ccfa95..2a862758e08 100644
--- a/src/conn/conn_sweep.c
+++ b/src/conn/conn_sweep.c
@@ -9,6 +9,42 @@
#include "wt_internal.h"
/*
+ * __sweep_remove_handles --
+ * Remove closed dhandles from the connection list.
+ */
+static int
+__sweep_remove_handles(WT_SESSION_IMPL *session)
+{
+ WT_CONNECTION_IMPL *conn;
+ WT_DATA_HANDLE *dhandle, *dhandle_next;
+ WT_DECL_RET;
+
+ conn = S2C(session);
+ dhandle = SLIST_FIRST(&conn->dhlh);
+
+ for (; dhandle != NULL; dhandle = dhandle_next) {
+ dhandle_next = SLIST_NEXT(dhandle, l);
+ if (WT_IS_METADATA(dhandle))
+ continue;
+
+ /*
+ * If there are no longer any references to the handle in any
+ * sessions, attempt to discard it.
+ */
+ if (F_ISSET(dhandle, WT_DHANDLE_OPEN) ||
+ dhandle->session_inuse != 0 || dhandle->session_ref != 0)
+ continue;
+
+ WT_WITH_DHANDLE(session, dhandle,
+ ret = __wt_conn_dhandle_discard_single(session, 0));
+ WT_RET_BUSY_OK(ret);
+ WT_STAT_FAST_CONN_INCR(session, dh_conn_ref);
+ }
+
+ return (ret);
+}
+
+/*
* __sweep --
* Close unused dhandles on the connection dhandle list.
*/
@@ -16,22 +52,26 @@ static int
__sweep(WT_SESSION_IMPL *session)
{
WT_CONNECTION_IMPL *conn;
- WT_DATA_HANDLE *dhandle, *dhandle_next;
+ WT_DATA_HANDLE *dhandle;
WT_DECL_RET;
time_t now;
- int locked;
+ int closed_handles;
conn = S2C(session);
+ closed_handles = 0;
/* Don't discard handles that have been open recently. */
WT_RET(__wt_seconds(session, &now));
WT_STAT_FAST_CONN_INCR(session, dh_conn_sweeps);
- dhandle = SLIST_FIRST(&conn->dhlh);
- for (; dhandle != NULL; dhandle = dhandle_next) {
- dhandle_next = SLIST_NEXT(dhandle, l);
+ SLIST_FOREACH(dhandle, &conn->dhlh, l) {
if (WT_IS_METADATA(dhandle))
continue;
+ if (!F_ISSET(dhandle, WT_DHANDLE_OPEN) &&
+ dhandle->session_inuse == 0 && dhandle->session_ref == 0) {
+ ++closed_handles;
+ continue;
+ }
if (dhandle->session_inuse != 0 ||
now <= dhandle->timeofdeath + conn->sweep_idle_time)
continue;
@@ -60,42 +100,31 @@ __sweep(WT_SESSION_IMPL *session)
if ((ret =
__wt_try_writelock(session, dhandle->rwlock)) == EBUSY)
continue;
- WT_RET(ret);
- locked = 1;
/* If the handle is open, try to close it. */
if (F_ISSET(dhandle, WT_DHANDLE_OPEN)) {
WT_WITH_DHANDLE(session, dhandle,
ret = __wt_conn_btree_sync_and_close(session, 0));
- if (ret != 0)
- goto unlock;
/* We closed the btree handle, bump the statistic. */
- WT_STAT_FAST_CONN_INCR(session, dh_conn_handles);
+ if (ret == 0)
+ WT_STAT_FAST_CONN_INCR(
+ session, dh_conn_handles);
}
- /*
- * If there are no longer any references to the handle in any
- * sessions, attempt to discard it. The called function
- * re-checks that the handle is not in use, which is why we
- * don't do any special handling of EBUSY returns above.
- */
- if (dhandle->session_inuse == 0 && dhandle->session_ref == 0) {
- WT_WITH_DHANDLE(session, dhandle,
- ret = __wt_conn_dhandle_discard_single(session, 0));
- if (ret != 0)
- goto unlock;
-
- /* If the handle was discarded, it isn't locked. */
- locked = 0;
- } else
- WT_STAT_FAST_CONN_INCR(session, dh_conn_ref);
-
-unlock: if (locked)
- WT_TRET(__wt_writeunlock(session, dhandle->rwlock));
+ if (dhandle->session_inuse == 0 && dhandle->session_ref == 0)
+ ++closed_handles;
+ WT_TRET(__wt_writeunlock(session, dhandle->rwlock));
WT_RET_BUSY_OK(ret);
}
+
+ if (closed_handles) {
+ WT_WITH_DHANDLE_LOCK(session,
+ ret = __sweep_remove_handles(session));
+ WT_RET(ret);
+ }
+
return (0);
}
@@ -103,7 +132,7 @@ unlock: if (locked)
* __sweep_server --
* The handle sweep server thread.
*/
-static void *
+static WT_THREAD_RET
__sweep_server(void *arg)
{
WT_CONNECTION_IMPL *conn;
@@ -129,7 +158,7 @@ __sweep_server(void *arg)
if (0) {
err: WT_PANIC_MSG(session, ret, "handle sweep server error");
}
- return (NULL);
+ return (WT_THREAD_RET_VALUE);
}
/*