8e74562179
* Redesign triePrefetcher to make it thread safe There are 2 types of triePrefetcher instances: 1.New created triePrefetcher: it is key to do trie prefetch to speed up validation phase. 2.Copied triePrefetcher: it only copy the prefetched trie information, actually it won't do prefetch at all, the copied tries are all kept in p.fetches. Here we try to improve the new created one, to make it concurrent safe, while the copied one's behavior stay unchanged(its logic is very simple). As commented in triePrefetcher struct, its APIs are not thread safe. So callers should make sure the created triePrefetcher should be used within a single routine. As we are trying to improve triePrefetcher, we would use it concurrently, so it is necessary to redesign it for concurrent access. The design is simple: ** start a mainLoop to do all the work, APIs just send channel message. Others: ** remove the metrics copy, since it is useless for copied triePrefetcher ** for trie(), only get subfetcher through channel to reduce the workload of mainloop * some code enhancement for triePrefetcher redesign * some fixup: rename, temporary trie chan for concurrent safe. * fix review comments * add some protection in case the trie prefetcher is already stopped * fix review comments ** make close concurrent safe ** fix potential deadlock * replace channel by RWMutex for a few triePrefetcher APIs For APIs like: trie(), copy(), used(), it is simpler and more efficient to use a RWMutex instead of channel communicaton. Since the mainLoop would be busy handling trie request, while these trie request can be processed in parallism. We would only keep prefetch and close within the mainLoop, since they could update the fetchers * add lock for subfecter.used access to make it concurrent safe * no need to create channel for copied triePrefetcher * fix trie_prefetcher_test.go trie prefetcher’s behavior has changed, prefetch() won't create subfetcher immediately. it is reasonable, but break the UT, to fix the failed UT |
||
---|---|---|
.. | ||
asm | ||
beacon | ||
bloombits | ||
forkid | ||
rawdb | ||
state | ||
systemcontracts | ||
types | ||
vm | ||
.gitignore | ||
bench_test.go | ||
block_validator_test.go | ||
block_validator.go | ||
blockchain_diff_test.go | ||
blockchain_insert.go | ||
blockchain_notries_test.go | ||
blockchain_reader.go | ||
blockchain_repair_test.go | ||
blockchain_sethead_test.go | ||
blockchain_snapshot_test.go | ||
blockchain_test.go | ||
blockchain.go | ||
blocks.go | ||
bloom_indexer.go | ||
chain_indexer_test.go | ||
chain_indexer.go | ||
chain_makers_test.go | ||
chain_makers.go | ||
dao_test.go | ||
error.go | ||
events.go | ||
evm.go | ||
forkchoice.go | ||
gaspool.go | ||
gen_genesis_account.go | ||
gen_genesis.go | ||
genesis_alloc.go | ||
genesis_test.go | ||
genesis.go | ||
headerchain_test.go | ||
headerchain.go | ||
mkalloc.go | ||
receipt_processor.go | ||
remote_state_verifier.go | ||
rlp_test.go | ||
state_prefetcher.go | ||
state_processor_test.go | ||
state_processor.go | ||
state_transition.go | ||
tx_cacher.go | ||
tx_journal.go | ||
tx_list_test.go | ||
tx_list.go | ||
tx_noncer.go | ||
tx_pool_test.go | ||
tx_pool.go | ||
types.go |