Skip to content

Commit 6504f8c

Browse files
authored
fix(fracmanager): using frac info cache in loader (#236)
1 parent c307351 commit 6504f8c

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

fracmanager/loader.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
type Loader struct {
1919
config *Config // loader configuration
2020
provider *fractionProvider // provider for creating fraction objects
21-
infoCache *fracInfoCache // fraction metadata cache
21+
infoCache *fracInfoCache // new empty info cache
2222

2323
cacheStat struct {
2424
hits int // counter of fractions loaded from frac info cache
@@ -125,20 +125,20 @@ func (l *Loader) discover(ctx context.Context) ([]*frac.Active, []*frac.Sealed,
125125
total := len(manifests)
126126
logProgress := progressLogger(time.Millisecond * 500)
127127

128-
// Load fractions according to their stage (active, sealed, and remote)
129128
actives := make([]*frac.Active, 0)
130129
locals := make([]*frac.Sealed, 0, total)
131130
remotes := make([]*frac.Remote, 0, total)
132131

133-
// Iterate through all manifests and load corresponding fraction types
132+
loadedInfoCache := NewFracInfoCacheFromDisk(l.infoCache.fileName)
133+
134134
for i, manifest := range manifests {
135135
switch manifest.Stage() {
136136
case fracStageActive:
137137
actives = append(actives, l.provider.NewActive(manifest.basePath))
138138
case fracStageSealed:
139-
locals = append(locals, l.loadSealed(manifest.basePath))
139+
locals = append(locals, l.loadSealed(manifest.basePath, loadedInfoCache))
140140
case fracStageRemote:
141-
remotes = append(remotes, l.loadRemote(ctx, manifest.basePath))
141+
remotes = append(remotes, l.loadRemote(ctx, manifest.basePath, loadedInfoCache))
142142
default:
143143
logger.Error("unexpected fraction stage", zap.Any("manifest", manifest))
144144
}
@@ -153,9 +153,8 @@ func (l *Loader) discover(ctx context.Context) ([]*frac.Active, []*frac.Sealed,
153153
}
154154

155155
// loadSealed loads a sealed fraction using cache
156-
// Optimizes loading through pre-saved metadata
157-
func (l *Loader) loadSealed(basePath string) *frac.Sealed {
158-
info, found := l.infoCache.Get(filepath.Base(basePath))
156+
func (l *Loader) loadSealed(basePath string, loadedInfoCache *fracInfoCache) *frac.Sealed {
157+
info, found := loadedInfoCache.Get(filepath.Base(basePath))
159158
l.updateStats(found)
160159

161160
f := l.provider.NewSealed(basePath, info)
@@ -164,9 +163,8 @@ func (l *Loader) loadSealed(basePath string) *frac.Sealed {
164163
}
165164

166165
// loadRemote loads a remote fraction
167-
// Works with external storages through context
168-
func (l *Loader) loadRemote(ctx context.Context, basePath string) *frac.Remote {
169-
info, found := l.infoCache.Get(filepath.Base(basePath))
166+
func (l *Loader) loadRemote(ctx context.Context, basePath string, loadedInfoCache *fracInfoCache) *frac.Remote {
167+
info, found := loadedInfoCache.Get(filepath.Base(basePath))
170168
l.updateStats(found)
171169

172170
f := l.provider.NewRemote(ctx, basePath, info)
@@ -185,7 +183,6 @@ func (l *Loader) updateStats(found bool) {
185183
}
186184

187185
// scanFiles scans filesystem for fraction files
188-
// Uses glob pattern to find all matching files
189186
func (l *Loader) scanFiles() []string {
190187
fullPattern := filepath.Join(l.config.DataDir, fileBasePattern+"*")
191188
files, err := filepath.Glob(fullPattern)

0 commit comments

Comments
 (0)