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 | |
parent | 68a6934ae52b5876054a525411ef69523b6b9a03 (diff) |
converter from Doc to #shard{} is more general
-rw-r--r-- | src/mem3_cache.erl | 16 | ||||
-rw-r--r-- | src/mem3_util.erl | 16 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/mem3_cache.erl b/src/mem3_cache.erl index 532a023a..b17db1a2 100644 --- a/src/mem3_cache.erl +++ b/src/mem3_cache.erl @@ -79,23 +79,9 @@ changes_callback({change, {Change}, _}, _) -> ?LOG_ERROR("missing partition table for ~s: ~p", [DbName, Reason]); {Doc} -> ets:delete(partitions, DbName), - cache_partition_table(DbName, Doc) + ets:insert(partitions, mem3_util:build_shards(DbName, Doc)) end end, {ok, couch_util:get_value(seq, Change)}; changes_callback(timeout, _) -> {ok, nil}. - -cache_partition_table(DbName, Doc) -> - ets:insert(partitions, 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">>, Doc, {[]}))). - -to_atom(Node) when is_binary(Node) -> - list_to_atom(binary_to_list(Node)). 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)). |