Dmitrii Stepanov
f2811f8585
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m29s
Build / Build Components (1.21) (pull_request) Successful in 3m23s
DCO action / DCO (pull_request) Successful in 3m50s
Tests and linters / Tests (1.21) (pull_request) Successful in 4m27s
Tests and linters / Lint (pull_request) Successful in 4m48s
Tests and linters / Tests (1.20) (pull_request) Successful in 5m6s
Tests and linters / Staticcheck (pull_request) Successful in 5m8s
Tests and linters / Tests with -race (pull_request) Successful in 5m38s
Build / Build Components (1.20) (pull_request) Successful in 7m46s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package blobovnicza
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"math"
|
|
"math/bits"
|
|
"strconv"
|
|
)
|
|
|
|
const firstBucketBound = uint64(32 * 1 << 10) // 32KB
|
|
|
|
func stringifyBounds(lower, upper uint64) string {
|
|
return fmt.Sprintf("[%s:%s]",
|
|
stringifyByteSize(lower),
|
|
stringifyByteSize(upper),
|
|
)
|
|
}
|
|
|
|
func stringifyByteSize(sz uint64) string {
|
|
return strconv.FormatUint(sz, 10)
|
|
}
|
|
|
|
func bucketKeyFromBounds(upperBound uint64) []byte {
|
|
buf := make([]byte, binary.MaxVarintLen64)
|
|
|
|
ln := binary.PutUvarint(buf, upperBound)
|
|
|
|
return buf[:ln]
|
|
}
|
|
|
|
func bucketForSize(sz uint64) ([]byte, uint64) {
|
|
upperBound := upperPowerOfTwo(sz)
|
|
return bucketKeyFromBounds(upperBound), upperBound
|
|
}
|
|
|
|
func upperPowerOfTwo(v uint64) uint64 {
|
|
if v <= firstBucketBound {
|
|
return firstBucketBound
|
|
}
|
|
return 1 << bits.Len64(v-1)
|
|
}
|
|
|
|
func (b *Blobovnicza) itemAdded(itemSize uint64) {
|
|
b.dataSize.Add(itemSize)
|
|
b.itemsCount.Add(1)
|
|
b.metrics.AddOpenBlobovniczaSize(itemSize)
|
|
b.metrics.AddOpenBlobovniczaItems(1)
|
|
}
|
|
|
|
func (b *Blobovnicza) itemDeleted(itemSize uint64) {
|
|
b.dataSize.Add(^(itemSize - 1))
|
|
b.itemsCount.Add(math.MaxUint64)
|
|
b.metrics.SubOpenBlobovniczaSize(itemSize)
|
|
b.metrics.SubOpenBlobovniczaItems(1)
|
|
}
|
|
|
|
func (b *Blobovnicza) full() bool {
|
|
return b.dataSize.Load() >= b.fullSizeLimit
|
|
}
|