Skip to content

Commit

Permalink
MB-17382: Expand bounding box on subsequent calls
Browse files Browse the repository at this point in the history
There can be several flushes of the KVs during the initial indexing.
Make sure the bounding box is calculated for the whole data set and
not just the current call.

Change-Id: I1d4e7f544a981a047d26cb2fe7e70116b57c86ac
Reviewed-on: http://review.couchbase.org/58692
Reviewed-by: Abhishek Singh <abhishek@couchbase.com>
Tested-by: Volker Mische <volker.mische@gmail.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
  • Loading branch information
vmx committed Jan 15, 2016
1 parent 5e15db2 commit d6be069
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion gc-couchbase/src/spatial_view.erl
Expand Up @@ -80,7 +80,8 @@ write_kvs(Group, TmpFiles0, ViewKVs) ->
fun({#set_view{id_num = Id}, KvList}, {AccCount, TmpFiles}) ->
TmpFileInfo0 = dict:fetch(Id, TmpFiles),
Mbb = calc_mbb(KvList),
TmpFileInfo = TmpFileInfo0#set_view_tmp_file_info{extra = Mbb},
Mbb2 = merge_mbbs(Mbb, TmpFileInfo0#set_view_tmp_file_info.extra),
TmpFileInfo = TmpFileInfo0#set_view_tmp_file_info{extra = Mbb2},

KvBins = convert_primary_index_kvs_to_binary(KvList, Group, []),
ViewRecords = lists:foldr(
Expand Down Expand Up @@ -112,6 +113,19 @@ calc_mbb(KvList) ->
end, nil, KvList).


-spec merge_mbbs([[number()]] | nil, [[number()]] | nil) -> [[number()]] | nil.
merge_mbbs(nil, MbbB) ->
MbbB;
merge_mbbs(MbbA, nil) ->
MbbA;
merge_mbbs(MbbA, MbbB) ->
Less = fun(A, B) -> A < B end,
lists:map(fun({[MinA, MaxA], [MinB, MaxB]}) ->
[vtree_util:min({MinA, MinB}, Less),
vtree_util:max({MaxA, MaxB}, Less)]
end, lists:zip(MbbA, MbbB)).


% Convert the key from a list of 2-tuples to a list of raw doubles
% NOTE vmx 2014-12-12: The first case could be more efficient, but for now
% it's good enough. Once the enclosing MBB for the initial index build is
Expand Down

0 comments on commit d6be069

Please sign in to comment.