-
Notifications
You must be signed in to change notification settings - Fork 2
Add live logical backup control plane #1119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bootjp
merged 8 commits into
design/live-backup-pin-substrate
from
design/live-backup-control-plane
Jul 23, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6a85349
backup: add live logical backup control plane
bootjp f30bd74
backup: harden control-plane fencing
bootjp 85e98d7
backup: fence live snapshot timestamp races
bootjp 2f927a6
backup: harden live backup fences
bootjp dd9f499
backup: stop unsafe live backup windows
bootjp 6608a1c
backup: harden renewal deadline publication
bootjp b3b8ab9
backup: gate renewals on live sessions
bootjp d91744b
backup: harden live scan edge cases
bootjp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package adapter | ||
|
|
||
| import ( | ||
| "context" | ||
| stderrors "errors" | ||
| "testing" | ||
|
|
||
| "github.com/bootjp/elastickv/internal/raftengine" | ||
| "github.com/bootjp/elastickv/kv" | ||
| pb "github.com/bootjp/elastickv/proto" | ||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| type internalAdminLeaderView struct { | ||
| state raftengine.State | ||
| readIndex uint64 | ||
| } | ||
|
|
||
| func (v internalAdminLeaderView) State() raftengine.State { return v.state } | ||
| func (internalAdminLeaderView) Leader() raftengine.LeaderInfo { | ||
| return raftengine.LeaderInfo{ID: "leader", Address: "leader:50051"} | ||
| } | ||
| func (internalAdminLeaderView) VerifyLeader(context.Context) error { return nil } | ||
| func (v internalAdminLeaderView) LinearizableRead(context.Context) (uint64, error) { | ||
| return v.readIndex, nil | ||
| } | ||
|
|
||
| func TestInternalForwardLeaseReadUsesLeaderBarrier(t *testing.T) { | ||
| t.Parallel() | ||
| internal := NewInternalWithEngine( | ||
| nil, | ||
| internalAdminLeaderView{state: raftengine.StateLeader, readIndex: 23}, | ||
| nil, | ||
| nil, | ||
| WithInternalLastCommitTimestamp(func() uint64 { return 37 }), | ||
| ) | ||
| resp, err := internal.ForwardLeaseRead(context.Background(), &pb.ForwardLeaseReadRequest{}) | ||
| require.NoError(t, err) | ||
| require.Equal(t, uint64(23), resp.GetAppliedIndex()) | ||
| require.Equal(t, uint64(37), resp.GetLastCommitTs()) | ||
|
|
||
| internal.leader = internalAdminLeaderView{state: raftengine.StateFollower} | ||
| _, err = internal.ForwardLeaseRead(context.Background(), &pb.ForwardLeaseReadRequest{}) | ||
| require.ErrorIs(t, err, ErrNotLeader) | ||
| } | ||
|
|
||
| type internalAdminProposer struct { | ||
| payload []byte | ||
| response any | ||
| } | ||
|
|
||
| func (p *internalAdminProposer) Propose(context.Context, []byte) (*raftengine.ProposalResult, error) { | ||
| return nil, stderrors.New("unexpected user proposal") | ||
| } | ||
|
|
||
| func (p *internalAdminProposer) ProposeAdmin( | ||
| _ context.Context, | ||
| payload []byte, | ||
| ) (*raftengine.ProposalResult, error) { | ||
| p.payload = append([]byte(nil), payload...) | ||
| return &raftengine.ProposalResult{CommitIndex: 17, Response: p.response}, nil | ||
| } | ||
|
|
||
| func TestInternalForwardAdminProposalUsesLeaderProposer(t *testing.T) { | ||
| t.Parallel() | ||
| proposer := &internalAdminProposer{} | ||
| internal := NewInternalWithEngine( | ||
| nil, | ||
| internalAdminLeaderView{state: raftengine.StateLeader}, | ||
| nil, | ||
| nil, | ||
| WithInternalAdminProposer(proposer), | ||
| ) | ||
|
|
||
| resp, err := internal.ForwardAdminProposal( | ||
| context.Background(), | ||
| &pb.ForwardAdminProposalRequest{Payload: []byte("pin")}, | ||
| ) | ||
| require.NoError(t, err) | ||
| require.Equal(t, uint64(17), resp.GetCommitIndex()) | ||
| require.Equal(t, []byte("pin"), proposer.payload) | ||
| } | ||
|
|
||
| func TestInternalForwardAdminProposalFailsClosed(t *testing.T) { | ||
| t.Parallel() | ||
| tests := []struct { | ||
| name string | ||
| state raftengine.State | ||
| proposer raftengine.Proposer | ||
| errTarget error | ||
| errCode codes.Code | ||
| errText string | ||
| }{ | ||
| {name: "follower", state: raftengine.StateFollower, errTarget: ErrNotLeader}, | ||
| { | ||
| name: "apply response", state: raftengine.StateLeader, | ||
| proposer: &internalAdminProposer{response: stderrors.New("apply failed")}, | ||
| errText: "apply failed", | ||
| }, | ||
| { | ||
| name: "capacity response", state: raftengine.StateLeader, | ||
| proposer: &internalAdminProposer{response: kv.ErrTooManyActiveBackups}, | ||
| errCode: codes.ResourceExhausted, | ||
| errText: kv.ErrTooManyActiveBackups.Error(), | ||
| }, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| internal := NewInternalWithEngine( | ||
| nil, | ||
| internalAdminLeaderView{state: tc.state}, | ||
| nil, | ||
| nil, | ||
| WithInternalAdminProposer(tc.proposer), | ||
| ) | ||
| _, err := internal.ForwardAdminProposal(context.Background(), &pb.ForwardAdminProposalRequest{}) | ||
| if tc.errTarget != nil { | ||
| require.ErrorIs(t, err, tc.errTarget) | ||
| } | ||
| if tc.errCode != codes.OK { | ||
| require.Equal(t, tc.errCode, status.Code(err)) | ||
| } | ||
| if tc.errText != "" { | ||
| require.ErrorContains(t, err, tc.errText) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.