mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-09 22:47:24 +00:00
state: txindex/kv: fsync data to disk immediately after receiving it (#4104)
## Issue Why this pr: When restarting chain node, sometimes we lost tx index about recent(around 80)blocks, and some client complains that they can't find the tx by RPC call(tx_search) when the tx do exist in the block. I try to partially fix this issue in a simple way by writing the index data in a sync way. There is no performance difference under 1K TPS according to our test. It is still possible that lost index data after restarting the node, but only 2 block data will lost at most. I try to totally fix this in https://github.com/tendermint/tendermint/pull/3847/files, but this one is simple and can solve most part of the issue. Please review first, thks. ## Comments Anton: BEFORE: BenchmarkTxIndex1-2 100000 12434 ns/op BenchmarkTxIndex500-2 300 5151564 ns/op BenchmarkTxIndex1000-2 100 15053910 ns/op BenchmarkTxIndex2000-2 100 18238892 ns/op BenchmarkTxIndex10000-2 20 124287930 ns/op AFTER: BenchmarkTxIndex1-2 2000 795431 ns/op BenchmarkTxIndex500-2 200 6385124 ns/op BenchmarkTxIndex1000-2 100 11388219 ns/op BenchmarkTxIndex2000-2 100 20514873 ns/op BenchmarkTxIndex10000-2 20 107456004 ns/op Performance drop is pretty steep, but I think it's the right thing to do UNTIL we have a WAL.
This commit is contained in:
@@ -30,3 +30,4 @@ program](https://hackerone.com/tendermint).
|
||||
### BUG FIXES:
|
||||
|
||||
- [tools] [\#4023](https://github.com/tendermint/tendermint/issues/4023) Refresh `tm-monitor` health when validator count is updated (@erikgrinaker)
|
||||
- [state] [\#4104](https://github.com/tendermint/tendermint/pull/4104) txindex/kv: Fsync data to disk immediately after receiving it (@guagualvcha)
|
||||
|
||||
@@ -103,7 +103,7 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error {
|
||||
storeBatch.Set(hash, rawBytes)
|
||||
}
|
||||
|
||||
storeBatch.Write()
|
||||
storeBatch.WriteSync()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ func (txi *TxIndex) Index(result *types.TxResult) error {
|
||||
}
|
||||
|
||||
b.Set(hash, rawBytes)
|
||||
b.Write()
|
||||
b.WriteSync()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user