Refresh iterator in DisconnectBlocks to avoid huge snapshot
This commit is contained in:
parent
fdd9c9b99f
commit
ee663944e2
@ -416,27 +416,44 @@ func (d *RocksDB) DisconnectBlocks(
|
|||||||
higher uint32,
|
higher uint32,
|
||||||
) error {
|
) error {
|
||||||
glog.Infof("rocksdb: disconnecting blocks %d-%d", lower, higher)
|
glog.Infof("rocksdb: disconnecting blocks %d-%d", lower, higher)
|
||||||
it := d.db.NewIteratorCF(d.ro, d.cfh[cfOutputs])
|
|
||||||
defer it.Close()
|
|
||||||
outputKeys := [][]byte{}
|
outputKeys := [][]byte{}
|
||||||
outputValues := [][]byte{}
|
outputValues := [][]byte{}
|
||||||
var totalOutputs uint64
|
var totalOutputs, count uint64
|
||||||
for it.SeekToFirst(); it.Valid(); it.Next() {
|
var seekKey []byte
|
||||||
totalOutputs++
|
for {
|
||||||
key := it.Key().Data()
|
var key []byte
|
||||||
l := len(key)
|
it := d.db.NewIteratorCF(d.ro, d.cfh[cfOutputs])
|
||||||
if l > 4 {
|
if totalOutputs == 0 {
|
||||||
height := unpackUint(key[l-4 : l])
|
it.SeekToFirst()
|
||||||
if height >= lower && height <= higher {
|
} else {
|
||||||
outputKey := make([]byte, len(key))
|
it.Seek(seekKey)
|
||||||
copy(outputKey, key)
|
it.Next()
|
||||||
outputKeys = append(outputKeys, outputKey)
|
}
|
||||||
value := it.Value().Data()
|
for count = 0; it.Valid() && count < 1000000; it.Next() {
|
||||||
outputValue := make([]byte, len(value))
|
totalOutputs++
|
||||||
copy(outputValue, value)
|
count++
|
||||||
outputValues = append(outputValues, outputValue)
|
key = it.Key().Data()
|
||||||
|
l := len(key)
|
||||||
|
if l > 4 {
|
||||||
|
height := unpackUint(key[l-4 : l])
|
||||||
|
if height >= lower && height <= higher {
|
||||||
|
outputKey := make([]byte, len(key))
|
||||||
|
copy(outputKey, key)
|
||||||
|
outputKeys = append(outputKeys, outputKey)
|
||||||
|
value := it.Value().Data()
|
||||||
|
outputValue := make([]byte, len(value))
|
||||||
|
copy(outputValue, value)
|
||||||
|
outputValues = append(outputValues, outputValue)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
seekKey = make([]byte, len(key))
|
||||||
|
copy(seekKey, key)
|
||||||
|
valid := it.Valid()
|
||||||
|
it.Close()
|
||||||
|
if !valid {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
glog.Infof("rocksdb: about to disconnect %d outputs from %d", len(outputKeys), totalOutputs)
|
glog.Infof("rocksdb: about to disconnect %d outputs from %d", len(outputKeys), totalOutputs)
|
||||||
wb := gorocksdb.NewWriteBatch()
|
wb := gorocksdb.NewWriteBatch()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user