Skip to content

Commit 86dbe1f

Browse files
committed
Create directory paths automatically and make default dirs work in Windows also
Signed-off-by: Michael Burman <[email protected]>
1 parent 3c78819 commit 86dbe1f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Diff for: plugin/storage/badger/factory.go

+11
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
9696
f.Options.primary.KeyDirectory = f.tmpDir
9797
f.Options.primary.ValueDirectory = f.tmpDir
9898
} else {
99+
// Errors are ignored as they're catched in the Open call
100+
initializeDir(f.Options.primary.KeyDirectory)
101+
initializeDir(f.Options.primary.ValueDirectory)
102+
99103
opts.SyncWrites = f.Options.primary.SyncWrites
100104
opts.Dir = f.Options.primary.KeyDirectory
101105
opts.ValueDir = f.Options.primary.ValueDirectory
@@ -121,6 +125,13 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
121125
return nil
122126
}
123127

128+
// initializeDir makes the directory and parent directories if the path doesn't exists yet.
129+
func initializeDir(path string) {
130+
if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
131+
os.MkdirAll(path, 0700)
132+
}
133+
}
134+
124135
// CreateSpanReader implements storage.Factory
125136
func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
126137
return badgerStore.NewTraceReader(f.store, f.cache), nil

Diff for: plugin/storage/badger/options.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,24 @@ const (
5252
suffixSpanstoreTTL = ".span-store-ttl"
5353
suffixSyncWrite = ".consistency"
5454
suffixMaintenanceInterval = ".maintenance-interval"
55-
defaultValueDir = "/data/values"
56-
defaultKeysDir = "/data/keys"
55+
defaultDataDir = string(os.PathSeparator) + "data"
56+
defaultValueDir = defaultDataDir + string(os.PathSeparator) + "values"
57+
defaultKeysDir = defaultDataDir + string(os.PathSeparator) + "keys"
5758
)
5859

5960
// NewOptions creates a new Options struct.
6061
func NewOptions(primaryNamespace string, otherNamespaces ...string) *Options {
6162

62-
defaultDataDir := getCurrentExecutableDir()
63+
defaultBadgerDataDir := getCurrentExecutableDir()
6364

6465
options := &Options{
6566
primary: &NamespaceConfig{
6667
namespace: primaryNamespace,
6768
SpanStoreTTL: defaultTTL,
6869
SyncWrites: false, // Performance over durability
6970
Ephemeral: true, // Default is ephemeral storage
70-
ValueDirectory: defaultDataDir + defaultValueDir,
71-
KeyDirectory: defaultDataDir + defaultKeysDir,
71+
ValueDirectory: defaultBadgerDataDir + defaultValueDir,
72+
KeyDirectory: defaultBadgerDataDir + defaultKeysDir,
7273
MaintenanceInterval: defaultMaintenanceInterval,
7374
},
7475
}

0 commit comments

Comments
 (0)