mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-24 06:50:40 +02:00
perf(s3/lifecycle): defer pool Put on ShardID hasher
defer guarantees the hasher returns to the pool even if h.Write or h.Sum panic, preventing pool leak under unexpected failure modes.
This commit is contained in:
1 parent
3a192c6c57
commit
ec83a87d68
1 file changed
+1
-1
@@ -22,12 +22,12 @@ var shardHashPool = sync.Pool{
|
||||
// the same shard. Implementation: top 4 bits of sha256(bucket || "/" || key).
|
||||
func ShardID(bucket, key string) int {
|
||||
h := shardHashPool.Get().(hash.Hash)
|
||||
defer shardHashPool.Put(h)
|
||||
h.Reset()
|
||||
h.Write([]byte(bucket))
|
||||
h.Write([]byte{'/'})
|
||||
h.Write([]byte(key))
|
||||
var buf [sha256.Size]byte
|
||||
sum := h.Sum(buf[:0])
|
||||
shardHashPool.Put(h)
|
||||
return int(sum[0] >> 4)
|
||||
}
|
||||
Reference in new issue
Block a user