diff options
author | Adam Kocoloski <adam@cloudant.com> | 2010-07-01 11:44:51 -0400 |
---|---|---|
committer | Adam Kocoloski <adam@cloudant.com> | 2010-08-12 01:23:16 -0400 |
commit | 5f7ff55f41acd820b5aea51fbff6dc3b61a0222c (patch) | |
tree | 826d8fec7ce853269d1d7d7fdbc24e7d81599d1c /src/mem3_util.erl | |
parent | 68a6934ae52b5876054a525411ef69523b6b9a03 (diff) |
converter from Doc to #shard{} is more general
Diffstat (limited to 'src/mem3_util.erl')
-rw-r--r-- | src/mem3_util.erl | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/mem3_util.erl b/src/mem3_util.erl index f6c94748..476742b7 100644 --- a/src/mem3_util.erl +++ b/src/mem3_util.erl @@ -4,7 +4,7 @@ %% API -export([fullmap/2, fullmap/3, hash/1, install_fullmap/4]). -export([for_key/2, all_parts/1]). --export([shard_name/2]). +-export([shard_name/2, build_shards/2]). -define(RINGTOP, trunc(math:pow(2,160))). % SHA-1 space @@ -185,3 +185,17 @@ shard_name(Part, DbName) when is_list(DbName) -> shard_name(Part, DbName) -> PartHex = ?l2b(showroom_utils:int_to_hexstr(Part)), <<"x", PartHex/binary, "/", DbName/binary, "_", PartHex/binary>>. + +build_shards(DbName, DocProps) -> + lists:map(fun({Map}) -> + Begin = couch_util:get_value(<<"b">>, Map), + #shard{ + name = mem3_util:shard_name(Begin, DbName), + dbname = DbName, + node = to_atom(couch_util:get_value(<<"node">>, Map)), + range = [Begin, couch_util:get_value(<<"e">>, Map)] + } + end, couch_util:get_value(<<"map">>, DocProps, {[]})). + +to_atom(Node) when is_binary(Node) -> + list_to_atom(binary_to_list(Node)). |