metabase: Check parameter for CountAliveObjectsInBucket #1414

Merged
fyrchik merged 1 commit from acid-ant/frostfs-node:bugfix/count-in-bucket into master 2024-10-04 14:52:05 +00:00

View file

@ -452,10 +452,11 @@ func (db *DB) CountAliveObjectsInBucket(ctx context.Context, prm CountAliveObjec
return 0, ErrDegradedMode
}
cidRaw := prm.BucketName[1:bucketKeySize]
if cidRaw == nil {
if len(prm.BucketName) != bucketKeySize {

if len(prm.BucketName) == 0 would be nicer, it prevents a possible panic which is not caught by nil comparison

`if len(prm.BucketName) == 0` would be nicer, it prevents a possible panic which is not caught by `nil` comparison

Thanks, fixed.

Thanks, fixed.

BTW, it still can be less than the bucketKeySize
Not for this PR: is there any reason we leak BucketName to the upper level?
It seems enough to operate with some notion of object type and container id, both of which are already existing abstractions.

BTW, it still can be less than the `bucketKeySize` Not for this PR: is there any reason we leak `BucketName` to the upper level? It seems enough to operate with some notion of `object type` and `container id`, both of which are already existing abstractions.

Right, need to check for bucketKeySize. Updated.
As for BucketName - no strong reason, just for quicker implementation and less compute.
I'll update method signature - will use object type and container id.

Right, need to check for `bucketKeySize`. Updated. As for `BucketName` - no strong reason, just for quicker implementation and less compute. I'll update method signature - will use object type and container id.
return 0, nil
}
cidRaw := prm.BucketName[1:bucketKeySize]
var count uint64
err := db.boltDB.View(func(tx *bbolt.Tx) error {
bkt := tx.Bucket(prm.BucketName)