mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-11 17:31:35 +00:00
improve readability of keyspace splitting
This commit is contained in:
parent
bfeb828460
commit
749fe860c6
1 changed files with 8 additions and 6 deletions
|
|
@ -415,20 +415,22 @@ func PruneTransactionIndex(db ethdb.Database, pruneBlock uint64) {
|
||||||
// Split the keyspace by the first byte of the tx hash.
|
// Split the keyspace by the first byte of the tx hash.
|
||||||
// Tx hashes are uniformly distributed so each worker gets
|
// Tx hashes are uniformly distributed so each worker gets
|
||||||
// roughly equal work.
|
// roughly equal work.
|
||||||
rangeStart := byte(i * 256 / workers)
|
rangeStart := []byte{byte(i * 256 / workers)}
|
||||||
rangeEnd := byte((i + 1) * 256 / workers)
|
// nil rangeEnd lets the last worker run to the end of the iterator.
|
||||||
isLast := i == workers-1
|
var rangeEnd []byte
|
||||||
|
if i < workers-1 {
|
||||||
|
rangeEnd = []byte{byte((i + 1) * 256 / workers)}
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
it := NewKeyLengthIterator(db.NewIterator(txLookupPrefix, []byte{rangeStart}), common.HashLength+len(txLookupPrefix))
|
it := NewKeyLengthIterator(db.NewIterator(txLookupPrefix, rangeStart), common.HashLength+len(txLookupPrefix))
|
||||||
defer it.Release()
|
defer it.Release()
|
||||||
|
|
||||||
batch := db.NewBatch()
|
batch := db.NewBatch()
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
// Stop if we've passed this worker's range.
|
if rangeEnd != nil && it.Key()[len(txLookupPrefix)] >= rangeEnd[0] {
|
||||||
if !isLast && it.Key()[len(txLookupPrefix)] >= rangeEnd {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
scanned.Add(1)
|
scanned.Add(1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue