-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wal: failoverWriter, for switching across a sequence of record.LogWri…
…ters Except for Close, failoverWriter methods do not block on IO. Close can block on IO if we run out of failover slots (10 slots) and new LogWriters cannot be created. Informs #3230 Informs CRDB-35401
- Loading branch information
1 parent
3e083df
commit 38e3430
Showing
10 changed files
with
2,293 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,64 @@ | ||
// Copyright 2024 The LevelDB-Go and Pebble Authors. All rights reserved. Use | ||
// of this source code is governed by a BSD-style license that can be found in | ||
// the LICENSE file. | ||
|
||
package wal | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/cockroachdb/pebble/vfs" | ||
) | ||
|
||
type dirIndex int | ||
|
||
const ( | ||
primaryDirIndex dirIndex = iota | ||
secondaryDirIndex | ||
numDirIndices | ||
) | ||
|
||
type dirAndFileHandle struct { | ||
Dir | ||
vfs.File | ||
} | ||
|
||
// switchableWriter is a subset of failoverWriter needed by failoverMonitor. | ||
type switchableWriter interface { | ||
switchToNewDir(dirAndFileHandle) error | ||
ongoingLatencyOrErrorForCurDir() (time.Duration, error) | ||
} | ||
|
||
type stopper struct { | ||
quiescer chan struct{} // Closed when quiescing | ||
wg sync.WaitGroup | ||
} | ||
|
||
func newStopper() *stopper { | ||
return &stopper{ | ||
quiescer: make(chan struct{}), | ||
} | ||
} | ||
|
||
func (s *stopper) runAsync(f func()) { | ||
s.wg.Add(1) | ||
go func() { | ||
f() | ||
s.wg.Done() | ||
}() | ||
} | ||
|
||
// shouldQuiesce returns a channel which will be closed when stop() has been | ||
// invoked and outstanding goroutines should begin to quiesce. | ||
func (s *stopper) shouldQuiesce() <-chan struct{} { | ||
return s.quiescer | ||
} | ||
|
||
func (s *stopper) stop() { | ||
close(s.quiescer) | ||
s.wg.Wait() | ||
} | ||
|
||
// Make lint happy. | ||
var _ = (&stopper{}).shouldQuiesce |
Oops, something went wrong.