Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Merge remote-tracking branch 'kxepal/rename-system-databases'
This closes #6
  • Loading branch information
kxepal committed Feb 26, 2015
2 parents 7f59504 + 6e3254e commit ee36909f0e3064e02301637c5273c1cbd1eea786
Showing 5 changed files with 13 additions and 13 deletions.
@@ -89,7 +89,7 @@ shards_int(DbName, Options) when is_list(DbName) ->
shards_int(DbName, Options) ->
Ordered = lists:member(ordered, Options),
ShardDbName =
list_to_binary(config:get("mem3", "shard_db", "dbs")),
list_to_binary(config:get("mem3", "shards_db", "_dbs")),
case DbName of
ShardDbName when Ordered ->
%% shard_db is treated as a single sharded db to support calls to db_info
@@ -90,7 +90,7 @@ code_change(_OldVsn, #state{}=State, _Extra) ->
%% internal functions

initialize_nodelist() ->
DbName = config:get("mem3", "node_db", "nodes"),
DbName = config:get("mem3", "nodes_db", "_nodes"),
{ok, Db} = mem3_util:ensure_exists(DbName),
{ok, _, Db} = couch_btree:fold(Db#db.id_tree, fun first_fold/3, Db, []),
% add self if not already present
@@ -115,7 +115,7 @@ first_fold(#full_doc_info{id=Id}=DocInfo, _, Db) ->
{ok, Db}.

listen_for_changes(Since) ->
DbName = config:get("mem3", "node_db", "nodes"),
DbName = config:get("mem3", "nodes_db", "_nodes"),
{ok, Db} = mem3_util:ensure_exists(DbName),
Args = #changes_args{
feed = "continuous",
@@ -114,7 +114,7 @@ local(DbName) ->
lists:filter(Pred, for_db(DbName)).

fold(Fun, Acc) ->
DbName = config:get("mem3", "shards_db", "dbs"),
DbName = config:get("mem3", "shards_db", "_dbs"),
{ok, Db} = mem3_util:ensure_exists(DbName),
FAcc = {Db, Fun, Acc},
try
@@ -131,7 +131,7 @@ set_max_size(Size) when is_integer(Size), Size > 0 ->
handle_config_change("mem3", "shard_cache_size", SizeList, _, _) ->
Size = list_to_integer(SizeList),
{ok, gen_server:call(?MODULE, {set_max_size, Size}, infinity)};
handle_config_change("mem3", "shard_db", _DbName, _, _) ->
handle_config_change("mem3", "shards_db", _DbName, _, _) ->
{ok, gen_server:call(?MODULE, shard_db_changed, infinity)};
handle_config_change(_, _, _, _, _) ->
{ok, nil}.
@@ -219,13 +219,13 @@ fold_fun(#doc_info{}=DI, _, {Db, UFun, UAcc}) ->
end.

get_update_seq() ->
DbName = config:get("mem3", "shards_db", "dbs"),
DbName = config:get("mem3", "shards_db", "_dbs"),
{ok, Db} = mem3_util:ensure_exists(DbName),
couch_db:close(Db),
Db#db.update_seq.

listen_for_changes(Since) ->
DbName = config:get("mem3", "shards_db", "dbs"),
DbName = config:get("mem3", "shards_db", "_dbs"),
{ok, Db} = mem3_util:ensure_exists(DbName),
Args = #changes_args{
feed = "continuous",
@@ -264,7 +264,7 @@ changes_callback(timeout, _) ->
ok.

load_shards_from_disk(DbName) when is_binary(DbName) ->
X = ?l2b(config:get("mem3", "shard_db", "dbs")),
X = ?l2b(config:get("mem3", "shards_db", "_dbs")),
{ok, Db} = mem3_util:ensure_exists(X),
try
load_shards_from_db(Db, DbName)
@@ -345,10 +345,10 @@ local_dbs() ->
[nodes_db(), shards_db(), users_db()].

nodes_db() ->
?l2b(config:get("mem3", "node_db", "nodes")).
?l2b(config:get("mem3", "nodes_db", "_nodes")).

shards_db() ->
?l2b(config:get("mem3", "shard_db", "dbs")).
?l2b(config:get("mem3", "shards_db", "_dbs")).

users_db() ->
?l2b(config:get("couch_httpd_auth", "authentication_db", "_users")).
@@ -77,12 +77,12 @@ attach_nodes([S | Rest], Acc, [Node | Nodes], UsedNodes) ->
attach_nodes(Rest, [S#shard{node=Node} | Acc], Nodes, [Node | UsedNodes]).

open_db_doc(DocId) ->
DbName = ?l2b(config:get("mem3", "shard_db", "dbs")),
DbName = ?l2b(config:get("mem3", "shards_db", "_dbs")),
{ok, Db} = couch_db:open(DbName, []),
try couch_db:open_doc(Db, DocId, [ejson_body]) after couch_db:close(Db) end.

write_db_doc(Doc) ->
DbName = ?l2b(config:get("mem3", "shard_db", "dbs")),
DbName = ?l2b(config:get("mem3", "shards_db", "_dbs")),
write_db_doc(DbName, Doc, true).

write_db_doc(DbName, #doc{id=Id, body=Body} = Doc, ShouldMutate) ->
@@ -108,7 +108,7 @@ write_db_doc(DbName, #doc{id=Id, body=Body} = Doc, ShouldMutate) ->

delete_db_doc(DocId) ->
gen_server:cast(mem3_shards, {cache_remove, DocId}),
DbName = ?l2b(config:get("mem3", "shard_db", "dbs")),
DbName = ?l2b(config:get("mem3", "shards_db", "_dbs")),
delete_db_doc(DbName, DocId, true).

delete_db_doc(DbName, DocId, ShouldMutate) ->

0 comments on commit ee36909

Please sign in to comment.