Skip to content

Commit 2209534

Browse files
committed
Fix: Address GH #2 by adding local short path on discovery
1 parent 1158810 commit 2209534

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

bitcask/bitcask.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ func OpenDB(path string) *DB {
150150
// discover is a helper function to discover and initialize all existing bitcask stores at the path.
151151
// caller must hold write lock.
152152
func (db *DB) discover() ([]string, error) {
153+
if db.initialized.Load() {
154+
stores := make([]string, 0, len(db.store))
155+
for store := range db.store {
156+
if store == "" {
157+
continue
158+
}
159+
stores = append(stores, store)
160+
}
161+
return stores, nil
162+
}
153163
stores := make([]string, 0, len(db.store))
154164
errs := make([]error, 0, len(db.store))
155165
if db.store == nil {
@@ -510,8 +520,11 @@ func (db *DB) CloseAll() error {
510520
}
511521
func (db *DB) addAllStoresToMeta() {
512522
storeMap := db.allStores()
513-
storeNames := make([]string, len(storeMap))
523+
storeNames := make([]string, 0, len(storeMap))
514524
for name := range storeMap {
525+
if name == "" {
526+
continue
527+
}
515528
storeNames = append(storeNames, name)
516529
}
517530
db.meta = db.meta.WithStores(storeNames...)

pogreb/pogreb.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,11 @@ func (db *DB) allMetrics() map[string]*pogreb.Metrics {
547547

548548
func (db *DB) addAllStoresToMeta() {
549549
storeMap := db.allStores()
550-
storeNames := make([]string, len(storeMap))
550+
storeNames := make([]string, 0, len(storeMap))
551551
for name := range storeMap {
552+
if name == "" {
553+
continue
554+
}
552555
storeNames = append(storeNames, name)
553556
}
554557
db.meta = db.meta.WithStores(storeNames...)
@@ -570,6 +573,16 @@ func (db *DB) SyncAll() error {
570573
}
571574

572575
func (db *DB) discover() ([]string, error) {
576+
if db.initialized.Load() {
577+
stores := make([]string, 0, len(db.store))
578+
for name := range db.store {
579+
if name == "" {
580+
continue
581+
}
582+
stores = append(stores, name)
583+
}
584+
return stores, nil
585+
}
573586
stores := make([]string, 0)
574587
errs := make([]error, 0)
575588
if db.store == nil {

0 commit comments

Comments
 (0)