Skip to content

Commit

Permalink
Persist/Load the per vbucket MaxDeletedSeqno values
Browse files Browse the repository at this point in the history
The max deleted seqno values are initialized to _local/vbstate as part
set_vbucket_state() function the first time vbuckets are created.

The persisted values are returned as part of get_state() which is
used during warmup to build the initial state.

A separate change set will add the code to incrementally update the
seqno values as delete mutations are received and persisted to Couch.

Change-Id: Ic63c77d4fa3724382ca05def3d5ca1681251e0a7
Reviewed-on: http://review.couchbase.org/11903
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Srinivas Vadlamani <srinivas@couchbase.com>
  • Loading branch information
Srinivas Vadlamani committed Mar 16, 2012
1 parent 20ff2a3 commit 373f5d1
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/mc_couch_vbucket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

get_state(VBucket, Prefix) when is_binary(Prefix) ->
mc_daemon:with_open_db(fun(Db) ->
case mc_couch_kv:get(Db, <<"_local/vbstate">>) of
{ok, _Flags, _Expiration, StateDoc} ->
StateDoc;
not_found ->
<<"{\"state\": \"dead\", \"checkpoint_id\": \"0\"}">>
end
case mc_couch_kv:get(Db, <<"_local/vbstate">>) of
{ok, _Flags, _Expiration, StateDoc} ->
StateDoc;
not_found ->
<<"{\"state\": \"dead\",
\"checkpoint_id\": \"0\",
\"max_deleted_seqno\": \"0\"}">>
end
end,
VBucket, Prefix);

Expand All @@ -36,10 +38,20 @@ set_vbucket(VBucket, StateName, CheckpointId, State) ->
_ ->
couch_db:open(DbName, Options)
end,

MaxDeletedSeqno =
case couch_db:open_doc(Db, <<"_local/vbstate">>, [ejson_body]) of
{ok, #doc{body = {Json}}} ->
couch_util:get_value(<<"max_deleted_seqno">>, Json, "0");
_ ->
"0"
end,
CheckpointId2 = integer_to_list(CheckpointId),
StateJson = iolist_to_binary(["{\"state\": \"", StateName,
"\", \"checkpoint_id\": \"",
CheckpointId2, "\"}"]),
StateJson = iolist_to_binary(
["{", "\"state\": \"", StateName, "\"",
", \"checkpoint_id\": \"", CheckpointId2, "\"",
", \"max_deleted_seqno\": \"", MaxDeletedSeqno, "\"",
"}"]),
StateAtom = erlang:binary_to_existing_atom(StateName, latin1),
Bucket = binary_to_list(mc_daemon:db_prefix(State)),

Expand Down

0 comments on commit 373f5d1

Please sign in to comment.