Skip to content

Commit

Permalink
allows data dir to be set in the db config.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitc committed Dec 8, 2012
1 parent 0c79713 commit 458fe73
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/couch/src/couch_compaction_daemon.erl
Expand Up @@ -295,7 +295,7 @@ can_db_compact(#config{db_frag = Threshold} = Config, Db) ->
false ->
false;
true ->
Free = free_space(couch_config:get("couchdb", "database_dir")),
Free = free_space(couch_server:database_dir()),
case Free >= SpaceRequired of
true ->
true;
Expand Down
6 changes: 3 additions & 3 deletions apps/couch/src/couch_db_updater.erl
Expand Up @@ -27,7 +27,7 @@ init({DbName, Filepath, Fd, Options}) ->
Header = #db_header{},
ok = couch_file:write_header(Fd, Header),
% delete any old compaction files that might be hanging around
RootDir = couch_config:get("couchdb", "database_dir", "."),
RootDir = couch_server:database_dir(),
couch_file:delete(RootDir, Filepath ++ ".compact");
false ->
case couch_file:read_header(Fd) of
Expand Down Expand Up @@ -68,7 +68,7 @@ handle_call(cancel_compact, _From, #db{compactor_pid = nil} = Db) ->
handle_call(cancel_compact, _From, #db{compactor_pid = Pid} = Db) ->
unlink(Pid),
exit(Pid, kill),
RootDir = couch_config:get("couchdb", "database_dir", "."),
RootDir = couch_server:database_dir(),
ok = couch_file:delete(RootDir, Db#db.filepath ++ ".compact"),
Db2 = Db#db{compactor_pid = nil},
ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
Expand Down Expand Up @@ -200,7 +200,7 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->

?LOG_DEBUG("CouchDB swapping files ~s and ~s.",
[Filepath, CompactFilepath]),
RootDir = couch_config:get("couchdb", "database_dir", "."),
RootDir = couch_server:database_dir(),
couch_file:delete(RootDir, Filepath),
ok = file:rename(CompactFilepath, Filepath),
close_db(Db),
Expand Down
9 changes: 8 additions & 1 deletion apps/couch/src/couch_server.erl
Expand Up @@ -20,6 +20,7 @@
-export([dev_start/0,is_admin/2,has_admins/0,get_stats/0,config_change/4]).
-export([close_lru/0]).
-export([get_uuid/0]).
-export([database_dir/0]).

-include("couch_db.hrl").

Expand Down Expand Up @@ -156,13 +157,19 @@ hash_admin_passwords(Persist) ->
couch_config:set("admins", User, ?b2l(HashedPassword), Persist)
end, couch_passwords:get_unhashed_admins()).

database_dir() ->
{ok, Cwd} = file:get_cwd(),
Default = couch:get_app_env(database_dir, Cwd),
couch_config:get("couchdb", "database_dir", Default).


init([]) ->
% read config and register for configuration changes

% just stop if one of the config settings change. couch_server_sup
% will restart us and then we will pick up the new settings.

RootDir = couch_config:get("couchdb", "database_dir", "."),
RootDir = database_dir(),
MaxDbsOpen = list_to_integer(
couch_config:get("couchdb", "max_dbs_open")),
ok = couch_config:register(fun ?MODULE:config_change/4),
Expand Down

0 comments on commit 458fe73

Please sign in to comment.