summaryrefslogtreecommitdiff
path: root/src/fabric_all_databases.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/fabric_all_databases.erl')
-rw-r--r--src/fabric_all_databases.erl38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/fabric_all_databases.erl b/src/fabric_all_databases.erl
new file mode 100644
index 00000000..1b1d4d00
--- /dev/null
+++ b/src/fabric_all_databases.erl
@@ -0,0 +1,38 @@
+-module(fabric_all_databases).
+-author(brad@cloudant.com).
+
+-export([all_databases/1]).
+
+-include("../../couch/src/couch_db.hrl").
+-include("../../dynomite/include/membership.hrl").
+
+
+%% @doc gets all databases in the cluster.
+-spec all_databases(binary() | []) -> [binary()].
+all_databases([]) ->
+ Dbs = ets:foldl(fun(#shard{dbname=DbName}, AccIn) ->
+ new_acc(DbName, AccIn)
+ end, [], partitions),
+ {ok, Dbs};
+all_databases(Customer) ->
+ ?debugFmt("~nCustomer: ~p~n", [Customer]),
+ Dbs = ets:foldl(fun(#shard{dbname=DbName}, AccIn) ->
+ DbNameStr = ?b2l(DbName),
+ case string:str(DbNameStr, Customer) of
+ 1 ->
+ new_acc(DbNameStr, AccIn);
+ _ -> AccIn
+ end
+ end, [], dbs_cache),
+ {ok, Dbs}.
+
+
+%% =====================
+%% internal
+%% =====================
+
+new_acc(DbName, Acc) ->
+ case lists:member(DbName, Acc) of
+ true -> Acc;
+ _ ->[DbName | Acc]
+ end.