forked from TrueCloudLab/frostfs-node
[#661] blobovnicza: Compute size with record size
To get more accurate size of blobovnicza use record size (lenght of key + lenght of data). Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
e0cb29cb6e
commit
9de91542fe
5 changed files with 19 additions and 14 deletions
|
@ -116,10 +116,11 @@ func (b *Blobovnicza) initializeCounters() error {
|
|||
}
|
||||
|
||||
return b.iterateAllDataBuckets(tx, func(lower, upper uint64, b *bbolt.Bucket) (bool, error) {
|
||||
keysN := uint64(b.Stats().KeyN)
|
||||
size += keysN * upper
|
||||
items += keysN
|
||||
return false, nil
|
||||
return false, b.ForEach(func(k, v []byte) error {
|
||||
size += uint64(len(k) + len(v))
|
||||
items++
|
||||
return nil
|
||||
})
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -49,6 +49,7 @@ func (b *Blobovnicza) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, err
|
|||
var sizeUpperBound uint64
|
||||
var sizeLowerBound uint64
|
||||
var dataSize uint64
|
||||
var recordSize uint64
|
||||
|
||||
err := b.boltDB.Update(func(tx *bbolt.Tx) error {
|
||||
err := b.iterateAllDataBuckets(tx, func(lower, upper uint64, buck *bbolt.Bucket) (bool, error) {
|
||||
|
@ -60,6 +61,7 @@ func (b *Blobovnicza) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, err
|
|||
dataSize = uint64(len(objData))
|
||||
sizeLowerBound = lower
|
||||
sizeUpperBound = upper
|
||||
recordSize = dataSize + uint64(len(addrKey))
|
||||
found = true
|
||||
return true, buck.Delete(addrKey)
|
||||
})
|
||||
|
@ -71,8 +73,10 @@ func (b *Blobovnicza) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, err
|
|||
if count > 0 {
|
||||
count--
|
||||
}
|
||||
if size >= sizeUpperBound {
|
||||
size -= sizeUpperBound
|
||||
if size >= recordSize {
|
||||
size -= recordSize
|
||||
} else {
|
||||
size = 0
|
||||
}
|
||||
return count, size
|
||||
})
|
||||
|
@ -89,7 +93,7 @@ func (b *Blobovnicza) Delete(ctx context.Context, prm DeletePrm) (DeleteRes, err
|
|||
zap.String("binary size", stringifyByteSize(dataSize)),
|
||||
zap.String("range", stringifyBounds(sizeLowerBound, sizeUpperBound)),
|
||||
)
|
||||
b.itemDeleted(sizeUpperBound)
|
||||
b.itemDeleted(recordSize)
|
||||
}
|
||||
|
||||
return DeleteRes{}, err
|
||||
|
|
|
@ -57,8 +57,9 @@ func (b *Blobovnicza) Put(ctx context.Context, prm PutPrm) (PutRes, error) {
|
|||
defer span.End()
|
||||
|
||||
sz := uint64(len(prm.objData))
|
||||
bucketName, upperBound := bucketForSize(sz)
|
||||
bucketName := bucketForSize(sz)
|
||||
key := addressKey(prm.addr)
|
||||
recordSize := sz + uint64(len(key))
|
||||
|
||||
err := b.boltDB.Batch(func(tx *bbolt.Tx) error {
|
||||
buck := tx.Bucket(bucketName)
|
||||
|
@ -75,11 +76,11 @@ func (b *Blobovnicza) Put(ctx context.Context, prm PutPrm) (PutRes, error) {
|
|||
}
|
||||
|
||||
return updateMeta(tx, func(count, size uint64) (uint64, uint64) {
|
||||
return count + 1, size + upperBound
|
||||
return count + 1, size + recordSize
|
||||
})
|
||||
})
|
||||
if err == nil {
|
||||
b.itemAdded(upperBound)
|
||||
b.itemAdded(recordSize)
|
||||
}
|
||||
|
||||
return PutRes{}, err
|
||||
|
|
|
@ -29,9 +29,8 @@ func bucketKeyFromBounds(upperBound uint64) []byte {
|
|||
return buf[:ln]
|
||||
}
|
||||
|
||||
func bucketForSize(sz uint64) ([]byte, uint64) {
|
||||
upperBound := upperPowerOfTwo(sz)
|
||||
return bucketKeyFromBounds(upperBound), upperBound
|
||||
func bucketForSize(sz uint64) []byte {
|
||||
return bucketKeyFromBounds(upperPowerOfTwo(sz))
|
||||
}
|
||||
|
||||
func upperPowerOfTwo(v uint64) uint64 {
|
||||
|
|
|
@ -34,7 +34,7 @@ func TestSizes(t *testing.T) {
|
|||
upperBound: 4 * firstBucketBound,
|
||||
},
|
||||
} {
|
||||
key, _ := bucketForSize(item.sz)
|
||||
key := bucketForSize(item.sz)
|
||||
require.Equal(t, bucketKeyFromBounds(item.upperBound), key)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue