Skip to content

Commit

Permalink
Merge pull request #104141 from jbowens/22.1-1ef0d356
Browse files Browse the repository at this point in the history
release-22.1: storage: lock database before initializing encryption-at-rest
  • Loading branch information
jbowens authored May 31, 2023
2 parents 77c382e + 5ec7e50 commit 276b5d4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ type Pebble struct {
// intents.
settings *cluster.Settings
encryption *EncryptionEnv
fileLock *pebble.Lock
fileRegistry *PebbleFileRegistry

// Stats updated by pebble.EventListener invocations, and returned in
Expand Down Expand Up @@ -762,6 +763,27 @@ func NewPebble(ctx context.Context, cfg PebbleConfig) (p *Pebble, err error) {
filesystemCloser.Close()
}
}()
if !cfg.Opts.ReadOnly {
if err := cfg.Opts.FS.MkdirAll(cfg.Dir, os.ModePerm); err != nil {
return nil, err
}
}

// Acquire the database lock in the store directory to ensure that no other
// process is simultaneously accessing the same store. We manually acquire
// the database lock here (rather than allowing Pebble to acquire the lock)
// so that we hold the lock when we initialize encryption-at-rest subsystem.
cfg.Opts.Lock, err = pebble.LockDirectory(cfg.Dir, cfg.Opts.FS)
if err != nil {
return nil, err
}
defer func() {
// If we fail to open the database, release the file lock before
// returning.
if err != nil {
err = errors.WithSecondaryError(err, cfg.Opts.Lock.Close())
}
}()

cfg.Opts.EnsureDefaults()
cfg.Opts.ErrorIfNotExists = cfg.MustExist
Expand Down Expand Up @@ -841,6 +863,7 @@ func NewPebble(ctx context.Context, cfg PebbleConfig) (p *Pebble, err error) {
properties: storeProps,
settings: cfg.Settings,
encryption: env,
fileLock: cfg.Opts.Lock,
fileRegistry: fileRegistry,
fs: cfg.Opts.FS,
unencryptedFS: unencryptedFS,
Expand Down Expand Up @@ -1002,6 +1025,7 @@ func (p *Pebble) Close() {
if p.closer != nil {
_ = p.closer.Close()
}
_ = p.fileLock.Close()
}

// Closed implements the Engine interface.
Expand Down

0 comments on commit 276b5d4

Please sign in to comment.