summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Gorrod <alexg@wiredtiger.com>2014-12-22 10:54:43 +1100
committerAlex Gorrod <alexg@wiredtiger.com>2014-12-22 10:54:43 +1100
commit42a5beaba747023f0b6b96651a83ab4b4543d520 (patch)
tree2b5d2286d2e746b2bd0cdb675a5b574c7fae689a /src
parente913b0811114d65b543cd78824e809eb487fd330 (diff)
parent7349568e154f116ebf4845baf2140b1afd942a7b (diff)
downloadmongo-42a5beaba747023f0b6b96651a83ab4b4543d520.tar.gz
Merge branch 'develop' into evict-trickle
Diffstat (limited to 'src')
-rw-r--r--src/conn/conn_api.c33
-rw-r--r--src/conn/conn_dhandle.c2
-rw-r--r--src/include/dhandle.h13
-rw-r--r--src/include/extern.h1
-rw-r--r--src/lsm/lsm_worker.c6
-rw-r--r--src/os_posix/os_getenv.c26
-rw-r--r--src/os_win/os_getenv.c35
-rw-r--r--src/schema/schema_drop.c4
8 files changed, 89 insertions, 31 deletions
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c
index cc88f848861..33e04826644 100644
--- a/src/conn/conn_api.c
+++ b/src/conn/conn_api.c
@@ -1007,15 +1007,17 @@ static int
__conn_config_env(WT_SESSION_IMPL *session, const char *cfg[], WT_ITEM *cbuf)
{
WT_CONFIG_ITEM cval;
+ WT_DECL_RET;
const char *env_config;
size_t len;
- if ((env_config = getenv("WIREDTIGER_CONFIG")) == NULL)
+ ret = __wt_getenv(session, "WIREDTIGER_CONFIG", &env_config);
+ if (ret == WT_NOTFOUND)
return (0);
len = strlen(env_config);
if (len == 0)
return (0);
- WT_RET(__wt_buf_set(session, cbuf, env_config, len + 1));
+ WT_ERR(__wt_buf_set(session, cbuf, env_config, len + 1));
/*
* Security stuff:
@@ -1023,26 +1025,29 @@ __conn_config_env(WT_SESSION_IMPL *session, const char *cfg[], WT_ITEM *cbuf)
* If the "use_environment_priv" configuration string is set, use the
* environment variable if the process has appropriate privileges.
*/
- WT_RET(__wt_config_gets(session, cfg, "use_environment_priv", &cval));
+ WT_ERR(__wt_config_gets(session, cfg, "use_environment_priv", &cval));
if (cval.val == 0 && __wt_has_priv())
- WT_RET_MSG(session, WT_ERROR, "%s",
+ WT_ERR_MSG(session, WT_ERROR, "%s",
"WIREDTIGER_CONFIG environment variable set but process "
"lacks privileges to use that environment variable");
/* Check any version. */
- WT_RET(__conn_config_check_version(session, env_config));
+ WT_ERR(__conn_config_check_version(session, env_config));
/* Upgrade the configuration string. */
- WT_RET(__wt_config_upgrade(session, cbuf));
+ WT_ERR(__wt_config_upgrade(session, cbuf));
/* Check the configuration information. */
- WT_RET(__wt_config_check(session,
+ WT_ERR(__wt_config_check(session,
WT_CONFIG_REF(session, wiredtiger_open), env_config, 0));
/* Append it to the stack. */
- __conn_config_append(cfg, env_config);
+ __conn_config_append(cfg, cbuf->data);
- return (0);
+err: if (env_config != NULL)
+ __wt_free(session, env_config);
+
+ return (ret);
}
/*
@@ -1052,17 +1057,19 @@ __conn_config_env(WT_SESSION_IMPL *session, const char *cfg[], WT_ITEM *cbuf)
static int
__conn_home(WT_SESSION_IMPL *session, const char *home, const char *cfg[])
{
+ WT_DECL_RET;
WT_CONFIG_ITEM cval;
/* If the application specifies a home directory, use it. */
if (home != NULL)
goto copy;
+ ret = __wt_getenv(session, "WIREDTIGER_HOME", &S2C(session)->home);
+ if (ret == 0)
+ return (0);
+
/* If there's no WIREDTIGER_HOME environment variable, use ".". */
- if ((home = getenv("WIREDTIGER_HOME")) == NULL || strlen(home) == 0) {
- home = ".";
- goto copy;
- }
+ home = ".";
/*
* Security stuff:
diff --git a/src/conn/conn_dhandle.c b/src/conn/conn_dhandle.c
index 6d331f691fd..184fac26d7c 100644
--- a/src/conn/conn_dhandle.c
+++ b/src/conn/conn_dhandle.c
@@ -716,7 +716,7 @@ __wt_conn_dhandle_discard_single(WT_SESSION_IMPL *session, int final)
__wt_spin_destroy(session, &dhandle->close_lock);
__wt_overwrite_and_free(session, dhandle);
- WT_CLEAR_BTREE_IN_SESSION(session);
+ session->dhandle = NULL;
}
return (ret);
diff --git a/src/include/dhandle.h b/src/include/dhandle.h
index 8cd7c9ba90b..1a6839b11fe 100644
--- a/src/include/dhandle.h
+++ b/src/include/dhandle.h
@@ -5,19 +5,6 @@
* See the file LICENSE for redistribution information.
*/
-/*
- * XXX
- * The server threads use their own WT_SESSION_IMPL handles because they may
- * want to block (for example, the eviction server calls reconciliation, and
- * some of the reconciliation diagnostic code reads pages), and the user's
- * session handle is already blocking on a server thread. The problem is the
- * server thread needs to reference the correct btree handle, and that's
- * hanging off the application's thread of control. For now, I'm just making
- * it obvious where that's getting done.
- */
-#define WT_SET_BTREE_IN_SESSION(s, b) ((s)->dhandle = b->dhandle)
-#define WT_CLEAR_BTREE_IN_SESSION(s) ((s)->dhandle = NULL)
-
#define WT_WITH_DHANDLE(s, d, e) do { \
WT_DATA_HANDLE *__saved_dhandle = (s)->dhandle; \
(s)->dhandle = (d); \
diff --git a/src/include/extern.h b/src/include/extern.h
index bb7caa991d6..99323a0b126 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -442,6 +442,7 @@ extern int __wt_directory_sync(WT_SESSION_IMPL *session, char *path);
extern int __wt_fsync(WT_SESSION_IMPL *session, WT_FH *fh);
extern int __wt_fsync_async(WT_SESSION_IMPL *session, WT_FH *fh);
extern int __wt_ftruncate(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t len);
+extern int __wt_getenv(WT_SESSION_IMPL *session, const char *variable, const char **env);
extern int __wt_getline(WT_SESSION_IMPL *session, WT_ITEM *buf, FILE *fp);
extern int __wt_getopt( const char *progname, int nargc, char *const *nargv, const char *ostr);
extern int __wt_mmap(WT_SESSION_IMPL *session, WT_FH *fh, void *mapp, size_t *lenp, void **mappingcookie);
diff --git a/src/lsm/lsm_worker.c b/src/lsm/lsm_worker.c
index 955dd09193b..703453305ba 100644
--- a/src/lsm/lsm_worker.c
+++ b/src/lsm/lsm_worker.c
@@ -141,8 +141,10 @@ __lsm_worker(void *arg)
ret = 0;
} else if (ret == EBUSY)
ret = 0;
- /* Clear any state */
- WT_CLEAR_BTREE_IN_SESSION(session);
+
+ /* Paranoia: clear session state. */
+ session->dhandle = NULL;
+
__wt_lsm_manager_free_work_unit(session, entry);
entry = NULL;
progress = 1;
diff --git a/src/os_posix/os_getenv.c b/src/os_posix/os_getenv.c
new file mode 100644
index 00000000000..83cf8a75770
--- /dev/null
+++ b/src/os_posix/os_getenv.c
@@ -0,0 +1,26 @@
+/*-
+ * Copyright (c) 2008-2014 WiredTiger, Inc.
+ * All rights reserved.
+ *
+ * See the file LICENSE for redistribution information.
+ */
+
+#include "wt_internal.h"
+
+/*
+ * __wt_getenv --
+ * Get a non-null environment variable
+ */
+int
+__wt_getenv(WT_SESSION_IMPL *session, const char *variable, const char **env)
+{
+ const char *temp;
+
+ *env = NULL;
+
+ if (((temp = getenv(variable)) != NULL) && strlen(temp) > 0) {
+ return (__wt_strdup(session, temp, env));
+ }
+
+ return (WT_NOTFOUND);
+}
diff --git a/src/os_win/os_getenv.c b/src/os_win/os_getenv.c
new file mode 100644
index 00000000000..31505266d76
--- /dev/null
+++ b/src/os_win/os_getenv.c
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2008-2014 WiredTiger, Inc.
+ * All rights reserved.
+ *
+ * See the file LICENSE for redistribution information.
+ */
+
+#include "wt_internal.h"
+
+/*
+ * __wt_getenv --
+ * Get a non-null environment variable
+ */
+int
+__wt_getenv(WT_SESSION_IMPL *session, const char *variable, const char **env)
+{
+ WT_DECL_RET;
+ DWORD size;
+
+ *env = NULL;
+
+ size = GetEnvironmentVariableA(variable, NULL, 0);
+ if (size <= 1)
+ return (WT_NOTFOUND);
+
+ WT_RET(__wt_calloc(session, 1, size, env));
+
+ ret = GetEnvironmentVariableA(variable, *env, size);
+ /* We expect the number of bytes not including null terminator */
+ if ((ret + 1) != size)
+ WT_RET_MSG(session, __wt_errno(),
+ "GetEnvironmentVariableA failed: %s", variable);
+
+ return (0);
+}
diff --git a/src/schema/schema_drop.c b/src/schema/schema_drop.c
index ca09d25a495..9a74b26ffec 100644
--- a/src/schema/schema_drop.c
+++ b/src/schema/schema_drop.c
@@ -165,8 +165,8 @@ __wt_schema_drop(WT_SESSION_IMPL *session, const char *uri, const char *cfg[])
WT_RET(__wt_meta_track_on(session));
- /* Be careful to ignore any btree handle in our caller. */
- WT_CLEAR_BTREE_IN_SESSION(session);
+ /* Paranoia: clear any handle from our caller. */
+ session->dhandle = NULL;
if (WT_PREFIX_MATCH(uri, "colgroup:"))
ret = __drop_colgroup(session, uri, force, cfg);