Skip to content

Commit

Permalink
Merge pull request #2302 from wiredtiger/WT-2212
Browse files Browse the repository at this point in the history
WT-2212 Add a "use_environment" config to "wiredtiger_open"
  • Loading branch information
agorrod committed Nov 12, 2015
2 parents 9d023ab + 1b9c3da commit c360d53
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
9 changes: 7 additions & 2 deletions dist/api_data.py
Expand Up @@ -705,10 +705,15 @@ def __cmp__(self, other):
Config('in_memory', 'false', r'''
keep data in-memory only, minimize disk I/O''',
type='boolean', undoc=True),
Config('use_environment', 'true', r'''
use the \c WIREDTIGER_CONFIG and \c WIREDTIGER_HOME environment
variables if the process is not running with special privileges.
See @ref home for more information''',
type='boolean'),
Config('use_environment_priv', 'false', r'''
use the \c WIREDTIGER_CONFIG and \c WIREDTIGER_HOME environment
variables regardless of whether or not the process is running
with special privileges. See @ref home for more information''',
variables even if the process is running with special privileges.
See @ref home for more information''',
type='boolean'),
]

Expand Down
15 changes: 9 additions & 6 deletions src/config/config_def.c
Expand Up @@ -543,6 +543,7 @@ static const WT_CONFIG_CHECK confchk_wiredtiger_open[] = {
{ "transaction_sync", "category",
NULL, NULL,
confchk_wiredtiger_open_transaction_sync_subconfigs, 2 },
{ "use_environment", "boolean", NULL, NULL, NULL, 0 },
{ "use_environment_priv", "boolean", NULL, NULL, NULL, 0 },
{ "verbose", "list",
NULL, "choices=[\"api\",\"block\",\"checkpoint\",\"compact\","
Expand Down Expand Up @@ -622,6 +623,7 @@ static const WT_CONFIG_CHECK confchk_wiredtiger_open_all[] = {
{ "transaction_sync", "category",
NULL, NULL,
confchk_wiredtiger_open_transaction_sync_subconfigs, 2 },
{ "use_environment", "boolean", NULL, NULL, NULL, 0 },
{ "use_environment_priv", "boolean", NULL, NULL, NULL, 0 },
{ "verbose", "list",
NULL, "choices=[\"api\",\"block\",\"checkpoint\",\"compact\","
Expand Down Expand Up @@ -995,9 +997,9 @@ static const WT_CONFIG_ENTRY config_entries[] = {
",name=,quota=0,reserve=0,size=500MB),statistics=none,"
"statistics_log=(on_close=0,path=\"WiredTigerStat.%d.%H\","
"sources=,timestamp=\"%b %d %H:%M:%S\",wait=0),"
"transaction_sync=(enabled=0,method=fsync),use_environment_priv=0"
",verbose=,write_through=",
confchk_wiredtiger_open, 36
"transaction_sync=(enabled=0,method=fsync),use_environment=,"
"use_environment_priv=0,verbose=,write_through=",
confchk_wiredtiger_open, 37
},
{ "wiredtiger_open_all",
"async=(enabled=0,ops_max=1024,threads=2),buffer_alignment=-1,"
Expand All @@ -1016,9 +1018,10 @@ static const WT_CONFIG_ENTRY config_entries[] = {
",name=,quota=0,reserve=0,size=500MB),statistics=none,"
"statistics_log=(on_close=0,path=\"WiredTigerStat.%d.%H\","
"sources=,timestamp=\"%b %d %H:%M:%S\",wait=0),"
"transaction_sync=(enabled=0,method=fsync),use_environment_priv=0"
",verbose=,version=(major=0,minor=0),write_through=",
confchk_wiredtiger_open_all, 37
"transaction_sync=(enabled=0,method=fsync),use_environment=,"
"use_environment_priv=0,verbose=,version=(major=0,minor=0),"
"write_through=",
confchk_wiredtiger_open_all, 38
},
{ "wiredtiger_open_basecfg",
"async=(enabled=0,ops_max=1024,threads=2),buffer_alignment=-1,"
Expand Down
12 changes: 9 additions & 3 deletions src/conn/conn_api.c
Expand Up @@ -1286,6 +1286,11 @@ __conn_config_env(WT_SESSION_IMPL *session, const char *cfg[], WT_ITEM *cbuf)
const char *env_config;
size_t len;

/* Only use the environment variable if configured. */
WT_RET(__wt_config_gets(session, cfg, "use_environment", &cval));
if (cval.val == 0)
return (0);

ret = __wt_getenv(session, "WIREDTIGER_CONFIG", &env_config);
if (ret == WT_NOTFOUND)
return (0);
Expand Down Expand Up @@ -1333,15 +1338,16 @@ err: __wt_free(session, env_config);
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)
/* Only use the environment variable if configured. */
WT_RET(__wt_config_gets(session, cfg, "use_environment", &cval));
if (cval.val != 0 &&
__wt_getenv(session, "WIREDTIGER_HOME", &S2C(session)->home) == 0)
return (0);

/* If there's no WIREDTIGER_HOME environment variable, use ".". */
Expand Down
9 changes: 6 additions & 3 deletions src/include/wiredtiger.in
Expand Up @@ -2328,10 +2328,13 @@ struct __wt_connection {
* string\, chosen from the following options: \c "dsync"\, \c "fsync"\, \c
* "none"; default \c fsync.}
* @config{ ),,}
* @config{use_environment, use the \c WIREDTIGER_CONFIG and \c WIREDTIGER_HOME
* environment variables if the process is not running with special privileges.
* See @ref home for more information., a boolean flag; default \c true.}
* @config{use_environment_priv, use the \c WIREDTIGER_CONFIG and \c
* WIREDTIGER_HOME environment variables regardless of whether or not the
* process is running with special privileges. See @ref home for more
* information., a boolean flag; default \c false.}
* WIREDTIGER_HOME environment variables even if the process is running with
* special privileges. See @ref home for more information., a boolean flag;
* default \c false.}
* @config{verbose, enable messages for various events. Only available if
* WiredTiger is configured with --enable-verbose. Options are given as a
* list\, such as <code>"verbose=[evictserver\,read]"</code>., a list\, with
Expand Down
15 changes: 15 additions & 0 deletions test/suite/test_priv01.py → test/suite/test_env01.py
Expand Up @@ -147,7 +147,22 @@ def test_env_conf_without_env_var_priv(self):
self.common_test(None, None, 'use_environment_priv=true')
self.checkfiles(".")

def test_env_conf(self):
# If no homedir is set, use environment
edir = 'envdir'
os.mkdir(edir)
self.common_test(None, edir, 'use_environment=true')
# this check fails because of test harness files:
#self.checknofiles('.')
self.checkfiles(edir)

def test_env_conf_off(self):
# If no homedir is set, use environment
edir = 'envdir'
os.mkdir(edir)
self.common_test(None, edir, 'use_environment=false')
self.checknofiles(edir)
self.checkfiles('.')

if __name__ == '__main__':
wttest.run()

0 comments on commit c360d53

Please sign in to comment.