MCPcopy Create free account
hub / github.com/ethstorage/es-node / summaryLocalKvs

Function summaryLocalKvs

ethstorage/scanner/worker.go:301–325  ·  view source on GitHub ↗

Calculate the total number of KV entries stored locally

(shards []uint64, kvEntries, lastKvIdx uint64)

Source from the content-addressed store, hash-verified

299
300// Calculate the total number of KV entries stored locally
301func summaryLocalKvs(shards []uint64, kvEntries, lastKvIdx uint64) (uint64, string) {
302 var totalEntries uint64
303 var res []string
304 // Shard indices are sorted but may not be continuous: e.g. [0, 1, 3, 4] indicates shard 2 is missing
305 for _, shard := range shards {
306 shardOfLastKv := lastKvIdx / kvEntries
307 if shard > shardOfLastKv {
308 // Skip empty shards
309 break
310 }
311 var lastEntry uint64
312 // The last shard may contain fewer than the full kvEntries
313 if shard == shardOfLastKv {
314 totalEntries += lastKvIdx%kvEntries + 1
315 lastEntry = lastKvIdx
316 } else {
317 // Complete shards
318 totalEntries += kvEntries
319 lastEntry = (shard+1)*kvEntries - 1
320 }
321 shardView := fmt.Sprintf("shard%d%s", shard, formatRange(shard*kvEntries, lastEntry))
322 res = append(res, shardView)
323 }
324 return totalEntries, strings.Join(res, ",")
325}

Callers 2

TestGetKvsInBatchFunction · 0.85
summaryLocalKvsMethod · 0.85

Calls 1

formatRangeFunction · 0.85

Tested by 1

TestGetKvsInBatchFunction · 0.68