From e9ba8931f8f535a5eefc97ef92b367a101c1cefd Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 22 Jul 2022 09:31:24 +0300 Subject: [PATCH] [#1621] pilorama: Simplify bucket creation Signed-off-by: Evgenii Stratonikov Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/pilorama/boltdb.go | 28 ++++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/pkg/local_object_storage/pilorama/boltdb.go b/pkg/local_object_storage/pilorama/boltdb.go index d6a7d67680..0a5cd1130e 100644 --- a/pkg/local_object_storage/pilorama/boltdb.go +++ b/pkg/local_object_storage/pilorama/boltdb.go @@ -273,25 +273,23 @@ func (t *boltForest) TreeApply(d CIDDescriptor, treeID string, m *Move) error { func (t *boltForest) getTreeBuckets(tx *bbolt.Tx, cid cidSDK.ID, treeID string) (*bbolt.Bucket, *bbolt.Bucket, error) { treeRoot := bucketName(cid, treeID) + child := tx.Bucket(treeRoot) + if child != nil { + return child.Bucket(logBucket), child.Bucket(dataBucket), nil + } + child, err := tx.CreateBucket(treeRoot) - if err != nil && err != bbolt.ErrBucketExists { + if err != nil { return nil, nil, err } - - var bLog, bData *bbolt.Bucket - if err == nil { - if bLog, err = child.CreateBucket(logBucket); err != nil { - return nil, nil, err - } - if bData, err = child.CreateBucket(dataBucket); err != nil { - return nil, nil, err - } - } else { - child = tx.Bucket(treeRoot) - bLog = child.Bucket(logBucket) - bData = child.Bucket(dataBucket) + bLog, err := child.CreateBucket(logBucket) + if err != nil { + return nil, nil, err + } + bData, err := child.CreateBucket(dataBucket) + if err != nil { + return nil, nil, err } - return bLog, bData, nil }