Skip to content

Commit 7ac9a86

Browse files
craig[bot]pav-kv
andcommitted
Merge #158337
158337: kvserver: use StateEngine for SST snapshot storage r=arulajmani a=pav-kv This PR clarifies that SST snapshot storage uses `StateEngine`. As a drive-by, `SSTSnapshotStorage` is refactored to use the `fs.Env` directly, so that there is only one place it uses a `storage.Engine` (in its constructor). Part of #97627 Co-authored-by: Pavel Kalinnikov <[email protected]>
2 parents e31e41a + 61b5d2f commit 7ac9a86

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

pkg/kv/kvserver/kvstorage/snaprecv/sst_snapshot_storage.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// directory of scratches created. A scratch manages the SSTs created during a
3030
// specific snapshot.
3131
type SSTSnapshotStorage struct {
32-
engine storage.Engine
32+
env *fs.Env
3333
limiter *rate.Limiter
3434
dir string
3535
mu struct {
@@ -41,7 +41,7 @@ type SSTSnapshotStorage struct {
4141
// NewSSTSnapshotStorage creates a new SST snapshot storage.
4242
func NewSSTSnapshotStorage(engine storage.Engine, limiter *rate.Limiter) SSTSnapshotStorage {
4343
return SSTSnapshotStorage{
44-
engine: engine,
44+
env: engine.Env(),
4545
limiter: limiter,
4646
dir: filepath.Join(engine.GetAuxiliaryDir(), "sstsnapshot"),
4747
mu: struct {
@@ -70,7 +70,7 @@ func (s *SSTSnapshotStorage) NewScratchSpace(
7070

7171
// Clear removes all created directories and SSTs.
7272
func (s *SSTSnapshotStorage) Clear() error {
73-
return s.engine.Env().RemoveAll(s.dir)
73+
return s.env.RemoveAll(s.dir)
7474
}
7575

7676
// scratchClosed is called when an SSTSnapshotStorageScratch created by this
@@ -91,7 +91,7 @@ func (s *SSTSnapshotStorage) scratchClosed(rangeID roachpb.RangeID) {
9191
// Suppressing an error here is okay, as orphaned directories are at worst
9292
// a performance issue when we later walk directories in pebble.Capacity()
9393
// but not a correctness issue.
94-
_ = s.engine.Env().RemoveAll(filepath.Join(s.dir, strconv.Itoa(int(rangeID))))
94+
_ = s.env.RemoveAll(filepath.Join(s.dir, strconv.Itoa(int(rangeID))))
9595
}
9696
}
9797

@@ -113,7 +113,7 @@ func (s *SSTSnapshotStorageScratch) filename(id int) string {
113113
}
114114

115115
func (s *SSTSnapshotStorageScratch) createDir() error {
116-
err := s.storage.engine.Env().MkdirAll(s.snapDir, os.ModePerm)
116+
err := s.storage.env.MkdirAll(s.snapDir, os.ModePerm)
117117
s.dirCreated = s.dirCreated || err == nil
118118
return err
119119
}
@@ -187,7 +187,7 @@ func (s *SSTSnapshotStorageScratch) Close() error {
187187
}
188188
s.closed = true
189189
defer s.storage.scratchClosed(s.rangeID)
190-
return s.storage.engine.Env().RemoveAll(s.snapDir)
190+
return s.storage.env.RemoveAll(s.snapDir)
191191
}
192192

193193
// SSTSnapshotStorageFile is an SST file managed by a
@@ -220,9 +220,9 @@ func (f *SSTSnapshotStorageFile) ensureFile() error {
220220
}
221221
var err error
222222
if f.bytesPerSync > 0 {
223-
f.file, err = fs.CreateWithSync(f.scratch.storage.engine.Env(), f.filename, int(f.bytesPerSync), fs.RaftSnapshotWriteCategory)
223+
f.file, err = fs.CreateWithSync(f.scratch.storage.env, f.filename, int(f.bytesPerSync), fs.RaftSnapshotWriteCategory)
224224
} else {
225-
f.file, err = f.scratch.storage.engine.Env().Create(f.filename, fs.RaftSnapshotWriteCategory)
225+
f.file, err = f.scratch.storage.env.Create(f.filename, fs.RaftSnapshotWriteCategory)
226226
}
227227
if err != nil {
228228
return err

pkg/kv/kvserver/store.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,12 +1673,9 @@ func NewStore(
16731673
// it can clean it up. If this fails it's not a correctness issue since the
16741674
// storage is also cleared before receiving a snapshot.
16751675
//
1676-
// TODO(sep-raft-log): need a snapshot storage per engine since we'll need to split
1677-
// the SSTs. Or probably we don't need snapshots on the raft SST at all - the reason
1678-
// we use them now is because we want snapshot apply to be completely atomic but that
1679-
// is out the window with two engines, so we may as well break the atomicity in the
1680-
// common case and do something more effective.
1681-
s.sstSnapshotStorage = snaprecv.NewSSTSnapshotStorage(s.TODOEngine(), s.limiters.BulkIOWriteRate)
1676+
// NB: we don't need the snapshot storage in the raft engine. With separated
1677+
// storage, the log engine part of snapshot ingestion is written as a batch.
1678+
s.sstSnapshotStorage = snaprecv.NewSSTSnapshotStorage(s.StateEngine(), s.limiters.BulkIOWriteRate)
16821679
if err := s.sstSnapshotStorage.Clear(); err != nil {
16831680
log.KvDistribution.Warningf(ctx, "failed to clear snapshot storage: %v", err)
16841681
}

0 commit comments

Comments
 (0)