diff --git a/backend/frostfs/frostfs.go b/backend/frostfs/frostfs.go index bb9e93d37..dc5bbdd6a 100644 --- a/backend/frostfs/frostfs.go +++ b/backend/frostfs/frostfs.go @@ -572,14 +572,15 @@ func (f *Fs) resolveOrCreateContainer(ctx context.Context, rootDirName string) ( f.m.Lock() defer f.m.Unlock() - cnrID, err := f.resolveContainerIDHelper(ctx, rootDirName) - if err == nil { - return cnrID, err + cnrIDStr, ok := f.containerIDCache[rootDirName] + if ok { + return parseContainerID(cnrIDStr) } - - if cnrID, err = f.createContainer(ctx, rootDirName); err != nil { - delete(f.containerIDCache, rootDirName) - return cid.ID{}, fmt.Errorf("createContainer: %w", err) + cnrID, err := f.resolveCIDByRootDirName(ctx, rootDirName) + if err != nil { + if cnrID, err = f.createContainer(ctx, rootDirName); err != nil { + return cid.ID{}, fmt.Errorf("createContainer: %w", err) + } } f.containerIDCache[rootDirName] = cnrID.String() @@ -1004,7 +1005,10 @@ func (f *Fs) resolveCIDByRootDirName(ctx context.Context, rootDirName string) (c return cid.ID{}, fmt.Errorf("couldn't resolve container '%s'", rootDirName) } -func (f *Fs) resolveContainerIDHelper(ctx context.Context, rootDirName string) (cid.ID, error) { +func (f *Fs) resolveContainerID(ctx context.Context, rootDirName string) (cid.ID, error) { + f.m.Lock() + defer f.m.Unlock() + cnrIDStr, ok := f.containerIDCache[rootDirName] if ok { return parseContainerID(cnrIDStr) @@ -1017,13 +1021,6 @@ func (f *Fs) resolveContainerIDHelper(ctx context.Context, rootDirName string) ( return cnrID, nil } -func (f *Fs) resolveContainerID(ctx context.Context, rootDirName string) (cid.ID, error) { - f.m.Lock() - defer f.m.Unlock() - - return f.resolveContainerIDHelper(ctx, rootDirName) -} - func (f *Fs) parseContainer(ctx context.Context, rootDirName string) (cid.ID, error) { cnrID, err := parseContainerID(rootDirName) if err != nil {