-
Notifications
You must be signed in to change notification settings - Fork 863
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
Keep Worldstate Storage open for Bonsai archive latest layer #5039
Changes from all commits
faf0180
f6a8900
2b265e9
4780b25
3e92f02
410e034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,9 +75,29 @@ public Optional<BonsaiWorldView> getNextWorldView() { | |
} | ||
|
||
public void setNextWorldView(final Optional<BonsaiWorldView> nextWorldView) { | ||
maybeUnSubscribe(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we close the nextview, how will the layeredworldstate be able to ask it to retrieve the different values? Is it going to recreate it when needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is to close/unsubscribe from the worldstate this layer was initially created with, so we do not leak any snapshots. since this is a mutator, this is the last opportunity we will have to unsubscribe, typically when the BonsaiWorldStateArchive is responding to a BlockAddedEvent, and changes the nextWorldView.
garyschulte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.nextWorldView = nextWorldView; | ||
} | ||
|
||
private void maybeUnSubscribe() { | ||
nextWorldView | ||
.filter(WorldState.class::isInstance) | ||
.map(WorldState.class::cast) | ||
.ifPresent( | ||
ws -> { | ||
try { | ||
ws.close(); | ||
} catch (final Exception e) { | ||
// no-op | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
maybeUnSubscribe(); | ||
} | ||
|
||
public TrieLogLayer getTrieLog() { | ||
return trieLog; | ||
} | ||
|
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.
is this copy can impact the performance ? I see some synchronized method , call to DB . if @ahamlat can confirm that it is safe
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.
Agreed, an alternate implementation is to directly subscribe and unsubscribe to the underlying worldstate storage. This is cleaner code-wise, but if there is a performance impact we can directly sub/unsub to the storage itself.