diff options
author | Brad Anderson <brad@cloudant.com> | 2010-05-25 15:21:45 -0400 |
---|---|---|
committer | Brad Anderson <brad@cloudant.com> | 2010-05-25 15:21:45 -0400 |
commit | 4e75ad7622cb190616c653dde5d7a5625245fce0 (patch) | |
tree | 8c9751b4fbcde4fb8afb7944f9b48a4ec135d71c | |
parent | 322ef619409da556cd36b16315c332417a4eba1d (diff) |
all_databases now working with/without Customer param, types moved to mem.hrl, view updater thwarted for updates to dbs db.
-rw-r--r-- | src/fabric.erl | 6 | ||||
-rw-r--r-- | src/fabric_api.erl | 2 | ||||
-rw-r--r-- | src/fabric_create.erl | 20 | ||||
-rw-r--r-- | src/fabric_info.erl | 23 |
4 files changed, 38 insertions, 13 deletions
diff --git a/src/fabric.erl b/src/fabric.erl index d588265f..3e5d9dd8 100644 --- a/src/fabric.erl +++ b/src/fabric.erl @@ -1,6 +1,10 @@ -module(fabric). --export([create_db/2]). +-export([all_databases/1, create_db/2]). + + +all_databases(Customer) -> + fabric_info:all_databases(Customer). create_db(DbName, Options) -> fabric_create:create_db(DbName, Options). diff --git a/src/fabric_api.erl b/src/fabric_api.erl index a26aa7de..f932ff25 100644 --- a/src/fabric_api.erl +++ b/src/fabric_api.erl @@ -23,7 +23,7 @@ db_path(RawUri, Customer) -> -spec all_databases(string()) -> {ok, [bstring()]}. all_databases(Customer) -> - showroom_db:all_databases(Customer). + fabric:all_databases(Customer). -spec create_db(bstring(), [any()]) -> {ok, #db{}} | {error, any()}. create_db(DbName, Options) -> diff --git a/src/fabric_create.erl b/src/fabric_create.erl index 245ae2a2..986e4c2a 100644 --- a/src/fabric_create.erl +++ b/src/fabric_create.erl @@ -2,16 +2,11 @@ -author('Brad Anderson <brad@cloudant.com>'). -include("../../couch/src/couch_db.hrl"). +-include("../../dynomite/include/membership.hrl"). %% api -export([create_db/2]). --type part() :: integer(). --type ref_node_part() :: {reference(), node(), part()}. --type tref() :: reference(). --type np() :: {node(), part()}. --type np_acc() :: [{np(), any()}]. - %% ===================== %% api @@ -21,10 +16,14 @@ %% Options is proplist with user_ctx, n, q -spec create_db(binary(), list()) -> {ok, #db{}} | {error, any()}. create_db(DbName, Options) -> - RefNodePart = send_create_calls(DbName, Options), + Fullmap = partitions:fullmap(DbName, Options), + {ok, FullNodes} = mem3:fullnodes(), + RefNodePart = send_create_calls(DbName, Options, Fullmap), {ok, Results} = create_db_loop(RefNodePart), case create_results(Results, RefNodePart) of - ok -> {ok, #db{name=DbName}}; + ok -> + partitions:install_fullmap(DbName, Fullmap, FullNodes, Options), + {ok, #db{name=DbName}}; Other -> {error, Other} end. @@ -34,9 +33,8 @@ create_db(DbName, Options) -> %% ===================== %% @doc create the partitions on all appropriate nodes (rexi calls) --spec send_create_calls(binary(), list()) -> [{reference(), np()}]. -send_create_calls(DbName, Options) -> - Fullmap = partitions:fullmap(DbName, Options), +-spec send_create_calls(binary(), list(), [mem_node()]) -> [{reference(), np()}]. +send_create_calls(DbName, Options, Fullmap) -> lists:map(fun({Node, Part}) -> ShardName = showroom_utils:shard_name(Part, DbName), Ref = rexi:async_server_call({couch_server, Node}, diff --git a/src/fabric_info.erl b/src/fabric_info.erl new file mode 100644 index 00000000..95408b6f --- /dev/null +++ b/src/fabric_info.erl @@ -0,0 +1,23 @@ +-module(fabric_info). + +-export([all_databases/1]). + +-include("../../couch/src/couch_db.hrl"). + +%% @doc gets all databases in the cluster. +-spec all_databases(binary() | []) -> [binary()]. +all_databases([]) -> + Dbs = ets:foldl(fun({DbName, _}, Acc0) -> + [DbName | Acc0] + end, [], dbs_cache), + {ok, Dbs}; +all_databases(Customer) -> + ?debugFmt("~nCustomer: ~p~n", [Customer]), + Dbs = ets:foldl(fun({DbName, _}, Acc0) -> + DbNameStr = ?b2l(DbName), + case string:str(DbNameStr, Customer) of + 1 -> [DbNameStr | Acc0]; + _ -> Acc0 + end + end, [], dbs_cache), + {ok, Dbs}. |