Skip to content

Commit 239ccc9

Browse files
fix: crash in globalTierJournal when TierConfig is not initialized (minio#17791)
1 parent b762fba commit 239ccc9

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

cmd/globals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ var (
346346

347347
globalTierConfigMgr *TierConfigMgr
348348

349-
globalTierJournal *tierJournal
349+
globalTierJournal *TierJournal
350350

351351
globalConsoleSrv *restapi.Server
352352

cmd/server-main.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ func initAllSubsystems(ctx context.Context) {
362362

363363
// Create new ILM tier configuration subsystem
364364
globalTierConfigMgr = NewTierConfigMgr()
365+
globalTierJournal = NewTierJournal()
365366

366367
globalTransitionState = newTransitionState(GlobalContext)
367368
globalSiteResyncMetrics = newSiteResyncMetrics(GlobalContext)
@@ -798,14 +799,10 @@ func serverMain(ctx *cli.Context) {
798799
go func() {
799800
// Initialize transition tier configuration manager
800801
bootstrapTrace("globalTierConfigMgr.Init")
801-
err := globalTierConfigMgr.Init(GlobalContext, newObject)
802-
if err != nil {
802+
if err := globalTierConfigMgr.Init(GlobalContext, newObject); err != nil {
803803
logger.LogIf(GlobalContext, err)
804804
} else {
805-
globalTierJournal, err = initTierDeletionJournal(GlobalContext)
806-
if err != nil {
807-
logger.FatalIf(err, "Unable to initialize remote tier pending deletes journal")
808-
}
805+
logger.FatalIf(globalTierJournal.Init(GlobalContext), "Unable to initialize remote tier pending deletes journal")
809806
}
810807
}()
811808

cmd/tier-journal.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ import (
3232
)
3333

3434
//go:generate msgp -file $GOFILE -unexported
35-
//msgp:ignore tierJournal tierDiskJournal walkfn
35+
//msgp:ignore TierJournal tierDiskJournal walkfn
3636

3737
type tierDiskJournal struct {
3838
sync.RWMutex
3939
diskPath string
4040
file *os.File // active journal file
4141
}
4242

43-
type tierJournal struct {
43+
// TierJournal holds an in-memory and an on-disk delete journal of tiered content.
44+
type TierJournal struct {
4445
*tierDiskJournal // for processing legacy journal entries
4546
*tierMemJournal // for processing new journal entries
4647
}
@@ -62,24 +63,28 @@ func newTierDiskJournal() *tierDiskJournal {
6263
return &tierDiskJournal{}
6364
}
6465

65-
// initTierDeletionJournal intializes an in-memory journal built using a
66-
// buffered channel for new journal entries. It also initializes the on-disk
67-
// journal only to process existing journal entries made from previous versions.
68-
func initTierDeletionJournal(ctx context.Context) (*tierJournal, error) {
69-
j := &tierJournal{
70-
tierMemJournal: newTierMemJoural(1000),
66+
// NewTierJournal initializes tier deletion journal
67+
func NewTierJournal() *TierJournal {
68+
j := &TierJournal{
69+
tierMemJournal: newTierMemJournal(1000),
7170
tierDiskJournal: newTierDiskJournal(),
7271
}
72+
return j
73+
}
7374

75+
// Init intializes an in-memory journal built using a
76+
// buffered channel for new journal entries. It also initializes the on-disk
77+
// journal only to process existing journal entries made from previous versions.
78+
func (t *TierJournal) Init(ctx context.Context) error {
7479
for _, diskPath := range globalEndpoints.LocalDisksPaths() {
75-
j.diskPath = diskPath
80+
t.diskPath = diskPath
7681

77-
go j.deletePending(ctx) // for existing journal entries from previous MinIO versions
78-
go j.processEntries(ctx) // for newer journal entries circa free-versions
79-
return j, nil
82+
go t.deletePending(ctx) // for existing journal entries from previous MinIO versions
83+
go t.processEntries(ctx) // for newer journal entries circa free-versions
84+
return nil
8085
}
8186

82-
return nil, errors.New("no local drive found")
87+
return errors.New("no local drive found")
8388
}
8489

8590
// rotate rotates the journal. If a read-only journal already exists it does

cmd/tier-mem-journal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type tierMemJournal struct {
2828
entries chan jentry
2929
}
3030

31-
func newTierMemJoural(nevents int) *tierMemJournal {
31+
func newTierMemJournal(nevents int) *tierMemJournal {
3232
return &tierMemJournal{
3333
entries: make(chan jentry, nevents),
3434
}

0 commit comments

Comments
 (0)