Skip to content

Commit adc5114

Browse files
authored
Merge pull request #594 from aduffeck/harden-hybrid-backend
Fix race conditions in the hybrid metadata backend
2 parents e7ab259 + 3edca67 commit adc5114

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

pkg/storage/pkg/decomposedfs/metadata/hybrid_backend.go

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ func (b HybridBackend) getAll(ctx context.Context, n MetadataNode, skipCache, sk
153153
}
154154

155155
if len(attrNames) == 0 {
156+
err = b.metaCache.PushToCache(b.cacheKey(n), attribs)
157+
if err != nil {
158+
return nil, err
159+
}
156160
return attribs, nil
157161
}
158162

@@ -179,6 +183,9 @@ func (b HybridBackend) getAll(ctx context.Context, n MetadataNode, skipCache, sk
179183

180184
// merge the attributes from the offload file
181185
offloaded, err := xattr.Get(path, _metadataOffloadedAttr)
186+
if err != nil && !IsAttrUnset(err) {
187+
return nil, err
188+
}
182189
if !skipOffloaded && err == nil && string(offloaded) == "1" {
183190
msgpackAttribs := map[string][]byte{}
184191
msgBytes, err := os.ReadFile(b.MetadataPath(n))
@@ -308,16 +315,9 @@ func (b HybridBackend) SetMultiple(ctx context.Context, n MetadataNode, attribs
308315
return fmt.Errorf("failed to set %d/%d xattrs: %w", xerrs, total, xerr)
309316
}
310317

311-
attribs, err = b.getAll(ctx, n, true, false, false)
312-
if err != nil {
313-
return err
314-
}
315-
err = b.metaCache.PushToCache(b.cacheKey(n), attribs)
316-
if err != nil {
317-
return err
318-
}
319-
320-
return nil
318+
// Update the cache with the new values
319+
_, err = b.getAll(ctx, n, true, false, false)
320+
return err
321321
}
322322

323323
func (b HybridBackend) offloadMetadata(ctx context.Context, n MetadataNode) error {
@@ -439,11 +439,9 @@ func (b HybridBackend) Remove(ctx context.Context, n MetadataNode, key string, a
439439
}
440440
}
441441

442-
attribs, err := b.getAll(ctx, n, true, false, false)
443-
if err != nil {
444-
return err
445-
}
446-
return b.metaCache.PushToCache(b.cacheKey(n), attribs)
442+
// Update the cache with the new values
443+
_, err := b.getAll(ctx, n, true, false, false)
444+
return err
447445
}
448446

449447
// IsMetaFile returns whether the given path represents a meta file
@@ -455,15 +453,10 @@ func (b HybridBackend) Purge(ctx context.Context, n MetadataNode) error {
455453
_, err := os.Stat(path)
456454
if err == nil {
457455
attribs, err := b.getAll(ctx, n, true, false, true)
458-
if err != nil {
459-
return err
460-
}
461-
462-
for attr := range attribs {
463-
if strings.HasPrefix(attr, prefixes.OcPrefix) {
464-
err := xattr.Remove(path, attr)
465-
if err != nil {
466-
return err
456+
if err == nil {
457+
for attr := range attribs {
458+
if strings.HasPrefix(attr, prefixes.OcPrefix) {
459+
_ = xattr.Remove(path, attr)
467460
}
468461
}
469462
}

0 commit comments

Comments
 (0)