-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVM: API method for setting cache fork graph #3169
base: master
Are you sure you want to change the base?
Conversation
5d4d0f3
to
d0eb47c
Compare
649ea08
to
abffbd9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know most changes were in tests, but be careful that acquiring a write lock is an expensive operation, so preferably acquire it only once.
transaction_processor.set_fork_graph_in_program_cache(fork_graph); | ||
|
||
let mut program_cache = transaction_processor.program_cache.write().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maintaining the older method here avoids acquiring the write lock twice.
// Initialize the mocked fork graph. | ||
processor.set_fork_graph_in_program_cache(fork_graph); | ||
|
||
{ | ||
let mut cache = processor.program_cache.write().unwrap(); | ||
|
||
// Initialize the mocked fork graph. | ||
cache.fork_graph = Some(Arc::downgrade(&fork_graph)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two consecutive write locks here again.
pub fn set_fork_graph_in_program_cache(&self, fork_graph: Arc<RwLock<FG>>) { | ||
self.program_cache | ||
.write() | ||
.unwrap() | ||
.set_fork_graph(Arc::downgrade(&fork_graph)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this function can receive a reference to a fork graph, can't it? Like
pub fn set_fork_graph_in_program_cache(&self, fork_graph: &Arc<RwLock<FG>>)
Or maybe:
pub fn set_fork_graph_in_program_cache(&self, fork_graph: &RwLock<FG>)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the cache's method requires a Weak<RwLock<FG>>
, and from what I could tell, you can only obtain a Weak
from an Arc
.
batch_processor.set_fork_graph_in_program_cache(Arc::new(RwLock::new(MockForkGraph {}))); | ||
|
||
let fork_graph = Arc::new(RwLock::new(MockForkGraph {})); | ||
{ | ||
let mut program_cache = batch_processor.program_cache.write().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consecutive write locks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this kinda stinks. Do you suggest closing this PR then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is better? #3203
Problem
When creating a new
TransactionBatchProcessor
instance, you must configure the fork graph of the program cache in order for the cache to work properly. This can trip up many consumers of the SVM API.We typically set this value on the program cache manually through something like this...
... which is just, awful.
Summary of Changes
Add an API method for setting the cache's fork graph, and use it everywhere.