Skip to content

Commit

Permalink
Create directory paths automatically and make default dirs work in
Browse files Browse the repository at this point in the history
Windows also, fixes issue #1652

Signed-off-by: Michael Burman <yak@iki.fi>
  • Loading branch information
burmanm committed Jul 4, 2019
1 parent ce31531 commit c137280
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions plugin/storage/badger/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
f.Options.primary.KeyDirectory = f.tmpDir
f.Options.primary.ValueDirectory = f.tmpDir
} else {
// Errors are ignored as they're catched in the Open call
initializeDir(f.Options.primary.KeyDirectory)
initializeDir(f.Options.primary.ValueDirectory)

opts.SyncWrites = f.Options.primary.SyncWrites
opts.Dir = f.Options.primary.KeyDirectory
opts.ValueDir = f.Options.primary.ValueDirectory
Expand All @@ -121,6 +125,13 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
return nil
}

// initializeDir makes the directory and parent directories if the path doesn't exists yet.
func initializeDir(path string) {
if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
os.MkdirAll(path, 0700)
}
}

// CreateSpanReader implements storage.Factory
func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
return badgerStore.NewTraceReader(f.store, f.cache), nil
Expand Down
11 changes: 6 additions & 5 deletions plugin/storage/badger/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,24 @@ const (
suffixSpanstoreTTL = ".span-store-ttl"
suffixSyncWrite = ".consistency"
suffixMaintenanceInterval = ".maintenance-interval"
defaultValueDir = "/data/values"
defaultKeysDir = "/data/keys"
defaultDataDir = string(os.PathSeparator) + "data"
defaultValueDir = defaultDataDir + string(os.PathSeparator) + "values"
defaultKeysDir = defaultDataDir + string(os.PathSeparator) + "keys"
)

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

defaultDataDir := getCurrentExecutableDir()
defaultBadgerDataDir := getCurrentExecutableDir()

options := &Options{
primary: &NamespaceConfig{
namespace: primaryNamespace,
SpanStoreTTL: defaultTTL,
SyncWrites: false, // Performance over durability
Ephemeral: true, // Default is ephemeral storage
ValueDirectory: defaultDataDir + defaultValueDir,
KeyDirectory: defaultDataDir + defaultKeysDir,
ValueDirectory: defaultBadgerDataDir + defaultValueDir,
KeyDirectory: defaultBadgerDataDir + defaultKeysDir,
MaintenanceInterval: defaultMaintenanceInterval,
},
}
Expand Down

0 comments on commit c137280

Please sign in to comment.