couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] branch COUCHDB-3298-optimize-writing-btree-nodes updated: Fix check for prefix of suffix
Date Tue, 09 May 2017 20:20:50 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3298-optimize-writing-btree-nodes
in repository https://gitbox.apache.org/repos/asf/couchdb.git

The following commit(s) were added to refs/heads/COUCHDB-3298-optimize-writing-btree-nodes
by this push:
       new  fd0e0e3   Fix check for prefix of suffix
fd0e0e3 is described below

commit fd0e0e33d40f666dcba07440cc2858e7f7b459f8
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Tue May 9 15:20:24 2017 -0500

    Fix check for prefix of suffix
---
 src/couch/src/couch_btree.erl | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/src/couch/src/couch_btree.erl b/src/couch/src/couch_btree.erl
index df01788..0882993 100644
--- a/src/couch/src/couch_btree.erl
+++ b/src/couch/src/couch_btree.erl
@@ -487,33 +487,38 @@ write_node(Bt, OldNode, NodeType, OldList, NewList) ->
     end.
 
 can_reuse_old_node(OldList, NewList) ->
-    Prefix = remove_prefix_kvs(hd(OldList), NewList),
-    case contains_old_list(OldList, NewList, 0) of
+    {Prefix, RestNewList} = remove_prefix_kvs(hd(OldList), NewList),
+    case old_list_is_prefix(OldList, RestNewList, 0) of
         {true, Size, Suffix} ->
             ReuseThreshold = get_chunk_size() * ?FILL_RATIO,
-            if Size < ReuseThreshold -> false; true ->
+            if Size < ReuseThreshold -> blog("XKCD: NOT FULL ENOUGH", []), false; true
->
+                blog("XKCD: OPTIMIZED ~p ~p", [length(Prefix), length(Suffix)]),
                 {true, Prefix, Suffix}
             end;
         false ->
+            Ks1 = [element(1, KV) || KV <- OldList],
+            Ks2 = [element(1, KV) || KV <- NewList],
+            blog("XKCD: OldList not contained! ~p vs ~p", [Ks1, Ks2]),
             false
     end.
 
 remove_prefix_kvs(KV1, [KV2 | Rest]) when KV2 < KV1 ->
-    [KV2 | remove_prefix_kvs(KV1, Rest)];
-remove_prefix_kvs(_, _) ->
-    [].
+    {Prefix, RestNewList} = remove_prefix_kvs(KV1, Rest),
+    {[KV2 | Prefix], RestNewList};
+remove_prefix_kvs(_, RestNewList) ->
+    {[], RestNewList}.
 
-% No more KV's in the old node so its contained
-contains_old_list([], Suffix, Size) ->
+% No more KV's in the old node so its a prefix
+old_list_is_prefix([], Suffix, Size) ->
     {true, Size, Suffix};
 % Some KV's have been removed from the old node
-contains_old_list(_OldList, [], _Size) ->
+old_list_is_prefix(_OldList, [], _Size) ->
     false;
 % KV is equal in both old and new node so continue
-contains_old_list([KV | Rest1], [KV | Rest2], Acc) ->
-    contains_old_list(Rest1, Rest2, ?term_size(KV) + Acc);
-% KV mismatch between old and new node so not contained
-contains_old_list(_OldList, _NewList, _Acc) ->
+old_list_is_prefix([KV | Rest1], [KV | Rest2], Acc) ->
+    old_list_is_prefix(Rest1, Rest2, ?term_size(KV) + Acc);
+% KV mismatch between old and new node so not a prefxi
+old_list_is_prefix(_OldList, _NewList, _Acc) ->
     false.
 
 modify_kpnode(Bt, {}, _LowerBound, Actions, [], QueryOutput) ->

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <commits@couchdb.apache.org>'].

Mime
View raw message