Skip to content

Commit 73c0998

Browse files
committed
encryption: encrypt data written to disk by Distsql's temp engine.
Now whenever distsql's temp engine writes to disk, the data written will be encrypted. This commit is part of the `use encryption for all local disk usage (non-logs)`. Issue: #19783. Release note: None
1 parent c79f738 commit 73c0998

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

pkg/base/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,16 @@ type TempStorageConfig struct {
438438
// use. If InMemory is set, than this has to be a memory monitor; otherwise it
439439
// has to be a disk monitor.
440440
Mon *mon.BytesMonitor
441+
// Store contains the parameters that temp storage will use.
442+
Store StoreSpec
443+
}
444+
445+
// IsEmpty returns if TempStorageConfig is empty.
446+
func (cfg TempStorageConfig) IsEmpty() bool {
447+
return !cfg.InMemory &&
448+
cfg.Path == "" &&
449+
cfg.Mon == nil &&
450+
cfg.Store.IsEmpty()
441451
}
442452

443453
// TempStorageConfigFromEnv creates a TempStorageConfig.
@@ -479,6 +489,7 @@ func TempStorageConfigFromEnv(
479489
return TempStorageConfig{
480490
InMemory: inMem,
481491
Mon: &monitor,
492+
Store: firstStore,
482493
}
483494
}
484495

pkg/base/store_spec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ type StoreSpec struct {
7878
ExtraOptions []byte
7979
}
8080

81+
// IsEmpty returns if StoreSpec is empty.
82+
func (ss StoreSpec) IsEmpty() bool {
83+
return ss.String() == "" &&
84+
ss.RocksDBOptions == "" &&
85+
!ss.UseFileRegistry &&
86+
ss.ExtraOptions == nil
87+
}
88+
8189
// String returns a fully parsable version of the store spec.
8290
func (ss StoreSpec) String() string {
8391
var buffer bytes.Buffer

pkg/cli/start.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,16 @@ func runStart(cmd *cobra.Command, args []string) error {
436436
if serverCfg.Settings.ExternalIODir, err = initExternalIODir(ctx, serverCfg.Stores.Specs[0]); err != nil {
437437
return err
438438
}
439-
if serverCfg.TempStorageConfig, err = initTempStorageConfig(ctx, serverCfg.Settings, stopper, serverCfg.Stores.Specs[0]); err != nil {
439+
var useStore base.StoreSpec
440+
for i := range serverCfg.Stores.Specs {
441+
if serverCfg.Stores.Specs[i].ExtraOptions != nil {
442+
useStore = serverCfg.Stores.Specs[i]
443+
}
444+
}
445+
if useStore.IsEmpty() {
446+
useStore = serverCfg.Stores.Specs[0]
447+
}
448+
if serverCfg.TempStorageConfig, err = initTempStorageConfig(ctx, serverCfg.Settings, stopper, useStore); err != nil {
440449
return err
441450
}
442451

pkg/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func NewServer(cfg Config, stopper *stop.Stopper) (*Server, error) {
349349
// Remove temporary directory linked to tempEngine after closing
350350
// tempEngine.
351351
s.stopper.AddCloser(stop.CloserFn(func() {
352-
firstStore := cfg.Stores.Specs[0]
352+
firstStore := s.cfg.TempStorageConfig.Store
353353
var err error
354354
if firstStore.InMemory {
355355
// First store is in-memory so we remove the temp

pkg/server/testserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func makeTestConfigFromParams(params base.TestServerArgs) Config {
193193
// TestServer).
194194
}
195195
cfg.Stores = base.StoreSpecList{Specs: params.StoreSpecs}
196-
if params.TempStorageConfig != (base.TempStorageConfig{}) {
196+
if !params.TempStorageConfig.IsEmpty() {
197197
cfg.TempStorageConfig = params.TempStorageConfig
198198
}
199199

pkg/storage/engine/temp_engine.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ func NewTempEngine(tempStorage base.TempStorageConfig) (Engine, error) {
3333
Dir: tempStorage.Path,
3434
// MaxSizeBytes doesn't matter for temp storage - it's not
3535
// enforced in any way.
36-
MaxSizeBytes: 0,
37-
MaxOpenFiles: 128, // TODO(arjun): Revisit this.
36+
MaxSizeBytes: 0,
37+
MaxOpenFiles: 128, // TODO(arjun): Revisit this.
38+
UseFileRegistry: tempStorage.Store.UseFileRegistry,
39+
ExtraOptions: tempStorage.Store.ExtraOptions,
3840
}
3941
rocksDBCache := NewRocksDBCache(0)
4042
rocksdb, err := NewRocksDB(rocksDBCfg, rocksDBCache)

0 commit comments

Comments
 (0)