rnewson commented on code in PR #5558:
URL: https://github.com/apache/couchdb/pull/5558#discussion_r2159243718
##########
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:
we call `upgrade` on the header as we open so drop_seq/count get filled in
as `0`. Experimentally I have confirmed this with 1) on `main`, create a
database 2) switch to this branch 3) `GET /dbname` shows `drop_count` of `0`
(and not a crash from trying to do `undefined + undefined`.
--
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]