Skip to content

Commit 3c5a97f

Browse files
committed
broker: ActiveStore.Store may be nil if it didn't initialize
Account for this in broker/fragment/stores.go Also, don't embed ActiveStore.Store to make it more obvious to the reader that it could be nil.
1 parent eb3b2aa commit 3c5a97f

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

broker/fragment/stores.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ func Persist(ctx context.Context, spool Spool, spec *pb.JournalSpec, isExiting b
4747
spool.PathPostfix = postfix
4848
}
4949

50-
var store = stores.Get(spool.Fragment.BackingStore)
51-
store.Mark.Store(true)
50+
var active = stores.Get(spool.Fragment.BackingStore)
51+
active.Mark.Store(true)
5252

53-
exists, err := store.Exists(ctx, spool.ContentPath())
53+
exists, err := active.Exists(ctx, spool.ContentPath())
5454
if err != nil {
55-
if store.IsAuthError(err) && isExiting && len(fs) != 0 {
55+
if isExiting && len(fs) != 0 && active.Store != nil && active.Store.IsAuthError(err) {
5656
continue // Fall back to the next store.
5757
}
5858
return err
@@ -91,9 +91,9 @@ func Persist(ctx context.Context, spool Spool, spec *pb.JournalSpec, isExiting b
9191
contentLength = spool.ContentLength()
9292
}
9393

94-
err = store.Put(timeoutCtx, spool.ContentPath(), reader, contentLength, contentEncoding)
94+
err = active.Put(timeoutCtx, spool.ContentPath(), reader, contentLength, contentEncoding)
9595
if err != nil {
96-
if store.IsAuthError(err) && isExiting && len(fs) != 0 {
96+
if isExiting && len(fs) != 0 && active.Store != nil && active.Store.IsAuthError(err) {
9797
continue // During shutdown with auth errors, try next store.
9898
}
9999
return err

broker/stores/active_store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313

1414
// ActiveStore wraps a Store implementation with mark-and-sweep GC support and instrumentation.
1515
type ActiveStore struct {
16-
Key pb.FragmentStore // FragmentStore from which this ActiveStore was built
17-
Store
18-
Mark atomic.Bool // Mark bit for GC
16+
Key pb.FragmentStore // FragmentStore from which this ActiveStore was built
17+
Store Store
18+
Mark atomic.Bool // Mark bit for GC
1919

2020
initErr error // Initialization error (if any) - checked by all methods
2121

broker/stores/health_check.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func checkLoop(stores map[pb.FragmentStore]*ActiveStore, fs pb.FragmentStore, at
5858
}
5959

6060
log.WithFields(log.Fields{
61-
"store": fs,
62-
"error": err,
63-
"attempt": attempt,
64-
"interval": checkInterval,
65-
"authError": active.IsAuthError(err),
61+
"store": fs,
62+
"error": err,
63+
"attempt": attempt,
64+
"interval": checkInterval,
65+
"authError": active.Store.IsAuthError(err),
6666
}).Warn("store health check failed")
6767
attempt += 1
6868
}

0 commit comments

Comments
 (0)