You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2019/07/31 09:09:53 UTC

[couchdb] 03/04: Fix default key ranges for fold_range

This is an automated email from the ASF dual-hosted git repository.

garren pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e8d22f2c8ccad64d1652fd6a896ef64b8796bf38
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Jul 25 12:37:05 2019 -0500

    Fix default key ranges for fold_range
    
    If a start or end key is not specified we still need to scope the range
    read to the given `RangePrefix`.
---
 src/fabric/src/fabric2_fdb.erl | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 670ce8b..71cb68f 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -985,18 +985,19 @@ get_fold_opts(RangePrefix, Options) ->
 
     % Set the maximum bounds for the start and endkey
     StartKey2 = case StartKey1 of
-        undefined -> <<>>;
-        SK2 -> SK2
+        undefined ->
+            <<RangePrefix/binary, 16#00>>;
+        SK2 ->
+            erlfdb_tuple:pack({SK2}, RangePrefix)
     end,
 
     EndKey2 = case EndKey1 of
-        undefined -> <<255>>;
-        EK2 -> EK2
+        undefined ->
+            <<RangePrefix/binary, 16#FF>>;
+        EK2 ->
+            erlfdb_tuple:pack({EK2}, RangePrefix)
     end,
 
-    StartKey3 = erlfdb_tuple:pack({StartKey2}, RangePrefix),
-    EndKey3 = erlfdb_tuple:pack({EndKey2}, RangePrefix),
-
     % FoundationDB ranges are applied as SK <= key < EK
     % By default, CouchDB is SK <= key <= EK with the
     % optional inclusive_end=false option changing that
@@ -1006,20 +1007,20 @@ get_fold_opts(RangePrefix, Options) ->
     % Thus we have this wonderful bit of logic to account
     % for all of those combinations.
 
-    StartKey4 = case {Reverse, InclusiveEnd} of
+    StartKey3 = case {Reverse, InclusiveEnd} of
         {true, false} ->
-            erlfdb_key:first_greater_than(StartKey3);
+            erlfdb_key:first_greater_than(StartKey2);
         _ ->
-            StartKey3
+            StartKey2
     end,
 
-    EndKey4 = case {Reverse, InclusiveEnd} of
+    EndKey3 = case {Reverse, InclusiveEnd} of
         {false, true} when EndKey0 /= undefined ->
-            erlfdb_key:first_greater_than(EndKey3);
+            erlfdb_key:first_greater_than(EndKey2);
         {true, _} ->
-            erlfdb_key:first_greater_than(EndKey3);
+            erlfdb_key:first_greater_than(EndKey2);
         _ ->
-            EndKey3
+            EndKey2
     end,
 
     Skip = case fabric2_util:get_value(skip, Options) of
@@ -1053,7 +1054,7 @@ get_fold_opts(RangePrefix, Options) ->
             ++ StreamingMode
             ++ Snapshot,
 
-    {StartKey4, EndKey4, Skip, OutOpts}.
+    {StartKey3, EndKey3, Skip, OutOpts}.
 
 
 fold_range_cb(KV, {skip, 0, Callback, Acc}) ->