iilyak commented on code in PR #5558:
URL: https://github.com/apache/couchdb/pull/5558#discussion_r2155175450


##########
src/couch/src/couch_bt_engine.erl:
##########
@@ -809,6 +819,35 @@ set_update_seq(#st{header = Header} = St, UpdateSeq) ->
         needs_commit = true
     }}.
 
+set_drop_seq(#st{header = Header} = St, ExpectedUuidPrefix, NewDropSeq) when
+    is_binary(ExpectedUuidPrefix), is_integer(NewDropSeq), NewDropSeq >= 0
+->
+    CurrentDropSeq = get_drop_seq(St),
+    Uuid = get_uuid(St),
+    ActualUuidPrefix = binary:part(Uuid, 0, byte_size(ExpectedUuidPrefix)),
+    if
+        ExpectedUuidPrefix /= ActualUuidPrefix ->
+            {error, uuid_mismatch};
+        NewDropSeq < CurrentDropSeq ->
+            {error, {drop_seq_cant_decrease, CurrentDropSeq, NewDropSeq}};
+        true ->
+            NewSt = St#st{
+                header = couch_bt_engine_header:set(Header, [
+                    {drop_seq, NewDropSeq}
+                ]),
+                needs_commit = true
+            },
+            {ok, increment_update_seq(NewSt)}
+    end.
+
+increment_drop_count(#st{header = Header} = St, Inc) when is_integer(Inc), Inc 
>= 0 ->
+    CurrentDropCount = get_drop_count(St),
+    NewSt = St#st{
+        header = couch_bt_engine_header:set(Header, [{drop_count, 
CurrentDropCount + Inc}]),

Review Comment:
   `get_drop_count/1` is implemented in terms of `couch_bt_engine_header:get/2` 
which uses `undefined` as default value. An attempt to do `undefined + Inc` 
would cause an exception. Which would terminate the compaction process. I don't 
know whether we can have a state where the `drop_count` is not present in the 
header when we are calling the `increment_drop_count`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to