Skip to content

Commit

Permalink
Do not check SSR State when Snapshotter should be stopped (#680)
Browse files Browse the repository at this point in the history
* Specify send/recv

Allows type checking of channel interactions

* Close instead of sending on channel

I think that closing the channel makes it clearer that this channels purpose has been fulfilled and it no longer needs to be considered. All the places that use the channel are recieving all values from the channel so they will continue to function in the same way

* Do not check ssr state in handleSsrStopRequest

The snapshotter is not set to active state until an initial delta
snapshot or a fullsnapshot has been taken. If a leadership election
takes place while the snapshot is being taken and the current leader
loses that election, then handleSsrRequest does not send on the
ssrStopCh. This in turn causes ssr.snapshotEventHandler to never return
and snapshots would continue to be taken.
  • Loading branch information
avestuk authored Mar 26, 2024
1 parent 53356a0 commit 0247d8d
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pkg/server/backuprestoreserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (b *BackupRestoreServer) runServer(ctx context.Context, restoreOpts *brtype

// runEtcdProbeLoopWithSnapshotter runs the etcd probe loop
// for the case when backup-restore becomes leading sidecar.
func (b *BackupRestoreServer) runEtcdProbeLoopWithSnapshotter(ctx context.Context, handler *HTTPHandler, ssr *snapshotter.Snapshotter, ss brtypes.SnapStore, ssrStopCh chan struct{}, ackCh chan struct{}) {
func (b *BackupRestoreServer) runEtcdProbeLoopWithSnapshotter(ctx context.Context, handler *HTTPHandler, ssr *snapshotter.Snapshotter, ss brtypes.SnapStore, ssrStopCh <-chan struct{}, ackCh chan<- struct{}) {
var (
err error
initialDeltaSnapshotTaken bool
Expand Down Expand Up @@ -513,7 +513,7 @@ func handleAckState(handler *HTTPHandler, ackCh chan struct{}) {
}

// handleSsrStopRequest responds to handlers request and stop interrupt.
func handleSsrStopRequest(ctx context.Context, handler *HTTPHandler, ssr *snapshotter.Snapshotter, ackCh, ssrStopCh chan struct{}, logger *logrus.Entry) {
func handleSsrStopRequest(ctx context.Context, handler *HTTPHandler, ssr *snapshotter.Snapshotter, ackCh chan<- struct{}, ssrStopCh chan<- struct{}, logger *logrus.Entry) {
logger.Info("Starting the handleSsrStopRequest handler...")
for {
var ok bool
Expand All @@ -523,15 +523,9 @@ func handleSsrStopRequest(ctx context.Context, handler *HTTPHandler, ssr *snapsh
logger.Infof("handleSsrStopRequest: %v", ctx.Err())
}

ssr.SsrStateMutex.Lock()
if ssr.SsrState == brtypes.SnapshotterActive {
ssr.SsrStateMutex.Unlock()
ssrStopCh <- emptyStruct
} else {
ssr.SsrState = brtypes.SnapshotterInactive
ssr.SsrStateMutex.Unlock()
ackCh <- emptyStruct
}
ackCh <- emptyStruct
close(ssrStopCh)

if !ok {
logger.Info("Stopping handleSsrStopRequest handler...")
return
Expand Down

0 comments on commit 0247d8d

Please sign in to comment.