diff options
author | Adam Kocoloski <adam@cloudant.com> | 2010-07-30 10:27:54 -0400 |
---|---|---|
committer | Adam Kocoloski <adam@cloudant.com> | 2010-07-30 15:08:08 -0400 |
commit | 3bddab0c470a2876ffbf9924958b34e79150bf69 (patch) | |
tree | 9f38bb6b0004f9e0f5ac10494a15147677f52811 | |
parent | 1a37af5d8bc9fc72c6ff8e550b858f4a3c6e48ab (diff) |
include a sequence sum in the _changes seq for sorting, BugzID 10588
-rw-r--r-- | src/fabric_view_changes.erl | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/fabric_view_changes.erl b/src/fabric_view_changes.erl index 03f362a7..6030df1d 100644 --- a/src/fabric_view_changes.erl +++ b/src/fabric_view_changes.erl @@ -198,7 +198,9 @@ collect_update_seqs(Seq, Shard, Counters) when is_integer(Seq) -> pack_seqs(Workers) -> SeqList = [{N,R,S} || {#shard{node=N, range=R}, S} <- Workers], - couch_util:encodeBase64Url(term_to_binary(SeqList, [compressed])). + SeqSum = lists:sum(element(2, lists:unzip(Workers))), + Opaque = couch_util:encodeBase64Url(term_to_binary(SeqList, [compressed])), + list_to_binary([integer_to_list(SeqSum), $-, Opaque]). unpack_seqs(0, DbName) -> fabric_dict:init(mem3:shards(DbName), 0); @@ -207,11 +209,13 @@ unpack_seqs("0", DbName) -> fabric_dict:init(mem3:shards(DbName), 0); unpack_seqs(Packed, DbName) -> + {match, [Opaque]} = re:run(Packed, "^([0-9]+-)?(?<opaque>.*)", [{capture, + [opaque], binary}]), % TODO relies on internal structure of fabric_dict as keylist lists:map(fun({Node, [A,B], Seq}) -> Shard = #shard{node=Node, range=[A,B], dbname=DbName}, {mem3_util:name_shard(Shard), Seq} - end, binary_to_term(couch_util:decodeBase64Url(Packed))). + end, binary_to_term(couch_util:decodeBase64Url(Opaque))). start_update_notifiers(DbName) -> lists:map(fun(#shard{node=Node, name=Name}) -> |