Get the shard suffix for a given database This grabs the shards for the given database name, and then pulls out the first shard and extracts out the suffix. mem3:shards is ets backed, so in the general case this should be fast.
BugzId: 29571 Project: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/commit/282e5057 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/tree/282e5057 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/diff/282e5057 Branch: refs/heads/windsor-merge Commit: 282e5057afe90e53ec36f5a789a7e26cbd76863b Parents: 7044f6c Author: Russell Branca <chewbra...@gmail.com> Authored: Tue Apr 29 16:36:06 2014 -0700 Committer: Robert Newson <rnew...@apache.org> Committed: Wed Jul 23 18:52:00 2014 +0100 ---------------------------------------------------------------------- src/mem3.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/282e5057/src/mem3.erl ---------------------------------------------------------------------- diff --git a/src/mem3.erl b/src/mem3.erl index cc76454..c713161 100644 --- a/src/mem3.erl +++ b/src/mem3.erl @@ -14,7 +14,7 @@ -export([start/0, stop/0, restart/0, nodes/0, node_info/2, shards/1, shards/2, choose_shards/2, n/1, dbname/1, ushards/1]). --export([get_shard/3, local_shards/1, fold_shards/2]). +-export([get_shard/3, local_shards/1, shard_suffix/1, fold_shards/2]). -export([sync_security/0, sync_security/1]). -export([compare_nodelists/0, compare_shards/1]). -export([quorum/1, group_by_proximity/1]). @@ -142,6 +142,14 @@ get_shard(DbName, Node, Range) -> local_shards(DbName) -> mem3_shards:local(DbName). +shard_suffix(#db{name=DbName}) -> + shard_suffix(DbName); +shard_suffix(DbName0) -> + Shard = hd(shards(DbName0)), + <<"shards/", _:8/binary, "-", _:8/binary, "/", DbName/binary>> = + Shard#shard.name, + filename:extension(binary_to_list(DbName)). + fold_shards(Fun, Acc) -> mem3_shards:fold(Fun, Acc).