-
Notifications
You must be signed in to change notification settings - Fork 19
feat(delayed-persist): Part 1: Roots may be in mem #1041
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
Conversation
Introduces a new type, `MemDiskNode`, which is a node which is either a SharedNode or a LinearAddress. This new type will allow writes to occur while readers are still reading this revision using an `ArcSwap`. Note that this does not actually put any additional nodes in memory, it just sets things up so they could be in memory. Additional changes needed for this feature to be complete are: - [ ] BranchNode children can now be Node, LinearAddress or MemDiskNode - [ ] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. - [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. - [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
The goal of this set of diffs is to separate persistence from both proposals and committed revisions. When proposing, we currently allocate space and modify the freelist. When committing, we currently flush all the modified nodes to disk. This diff is step 1. The only thing this diff does is allow for the root node (and only the root node) of proposals and revisions to be kept in memory and, using a lockless type, allow them to be persisted even while being read by other threads. It doesn't do that, since they are currently always created as an allocated node, but that will change on future diffs. In other words, it still always marks the node as persisted by assigning the address at propose time and using the persisted variant of the new |
This is a better name.
storage/src/node/memdisk.rs
Outdated
/// # Arguments | ||
/// | ||
/// * `addr` - The `LinearAddress` where the node has been persisted on disk | ||
pub fn persist_at(&self, addr: LinearAddress) { |
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.
Sounds like this function is really called when the node is evicted from cache instead of when it gets persisted. Maybe rename?
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.
No, it's called after the. node is written to disk.
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.
Oh because after you persist it you can read it from the cache of linear storage using its address right? Then I think MaybeAllocated
may be a better name than MemDiskNode
.
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.
It's not just allocated, it's persisted. The states here are:
- Node in memory (SharedNode)
- Node on disk (LinearAddress)
Allocation is the verb that describes part of persisting a node. First you allocate space, then you write (persist) it. If it has a LinearAddress, and I'm done with all my changes, the only thing that will have LinearAddresses are persisted. Right now we get a LinearAddress at allocation time, which is at propose time, but that's all moving.
c51a807
to
c31a9ce
Compare
Upcoming changes make supporting this harder, and it's not necessary, as the size of a LinearAddress and the size of a pointer are the same, so it's more efficient to return the actual value rather than a pointer to the value.
Members renamed from Mem to Unpersisted and Disk to Persisted, just to keep the naming a bit more consistent.
c31a9ce
to
7575745
Compare
storage/src/node/persist.rs
Outdated
/// - `Unpersisted(SharedNode)`: The node is currently in memory | ||
/// - `Persisted(LinearAddress)`: The node is currently on disk at the specified address | ||
#[derive(Debug)] | ||
pub enum MaybePersisted { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Most important test is that the node is no longer referenced after it becomes persisted, and it's shared across clones.
Create a table explaining the type more clearly. Lower visibility of MaybePersisted.
Branch children might also not be persisted. This also splits up hash_helper which got too long for clippy. - [x] Roots may not be persisted (Part 1: #1041) - [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and this PR #1047) - [ ] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. - [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. - [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The commit logic is also different, with far fewer steps. See the comments in `commit` in manager.rs. Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The commit logic is also different, with far fewer steps. See the comments in `commit` in manager.rs. Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The commit logic is also different, with far fewer steps. See the comments in `commit` in manager.rs. Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The commit logic is also different, with far fewer steps. See the comments in `commit` in manager.rs. Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The commit logic is also different, with far fewer steps. See the comments in `commit` in manager.rs. Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
Branch children might also not be persisted. This also splits up hash_helper which got too long for clippy. - [x] Roots may not be persisted (Part 1: ava-labs#1041) - [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: ava-labs#1045 and this PR ava-labs#1047) - [ ] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. - [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. - [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The commit logic is also different, with far fewer steps. See the comments in `commit` in manager.rs. Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
Create a new type, NodeAllocator, to handle allocations. Currently only uses references to the original NodeStore, but this will change in an upcoming diff. Also: - Branch children iterators will soon no longer be able to return references to hashes, since they are behind an ArcSwap, so they are now cloned. - Added logger feature to benchmark (helped with debugging) - Remove use of stored_len in tests feat(deferred-allocate): Part 3.2: Implementation This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The commit logic is also different, with far fewer steps. See the comments in `commit` in manager.rs. Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The implementation constisted of: - A new type, NodeAllocator, to consolidate all the allocation code - Removing the 'new' hashmap, as freshly allocatred nodes are found by traversing the trie and inspecting their state - Rewrite flush_nodes to serialize then allocate. Previously, the node was serialized twice, once to determine the size during proposal creation and once to store it - Branch children iterators can no longer return reference to hashes, since they are sometimes behind an ArcSwap - Changes to the commit flow by separating the node persistence logic Some miscellaneous changes included in this diff (could be split out): - Propogate logger feature in fwdctl (helped with debugging) - Remove use of stored_len in tests - size_from_area_index was a method on nodestore, but didn't use nodestore - uncached_node_and_size was dead code Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The implementation constisted of: - A new type, NodeAllocator, to consolidate all the allocation code - Removing the 'new' hashmap, as freshly allocatred nodes are found by traversing the trie and inspecting their state - Use the most recently committed revision's freelist to allocate new nodes. This will change in a future revision when the freelist is tied to storage rather than the revision. - Rewrite flush_nodes to serialize then allocate. Previously, the node was serialized twice, once to determine the size during proposal creation (allocation time) and once to store it - Changes to the commit flow by separating the node persistence logic (see comments in commit.rs) Some miscellaneous changes included in this diff (could be split out): - Branch children iterators can no longer return reference to hashes, since they are sometimes behind an ArcSwap - Propogate logger feature in fwdctl (helped with debugging) - Remove use of stored_len in tests - size_from_area_index was a method on nodestore, but didn't use nodestore - uncached_node_and_size was dead code Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The implementation constisted of: - A new type, NodeAllocator, to consolidate all the allocation code - Removing the 'new' hashmap, as freshly allocatred nodes are found by traversing the trie and inspecting their state - Use the most recently committed revision's freelist to allocate new nodes. This will change in a future revision when the freelist is tied to storage rather than the revision. - Rewrite flush_nodes to serialize then allocate. Previously, the node was serialized twice, once to determine the size during proposal creation (allocation time) and once to store it - Changes to the commit flow by separating the node persistence logic (see comments in commit.rs) Some miscellaneous changes included in this diff (could be split out): - Branch children iterators can no longer return reference to hashes, since they are sometimes behind an ArcSwap - Propogate logger feature in fwdctl (helped with debugging) - Remove use of stored_len in tests - size_from_area_index was a method on nodestore, but didn't use nodestore - uncached_node_and_size was dead code Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The implementation constisted of: - A new type, NodeAllocator, to consolidate all the allocation code - Removing the 'new' hashmap, as freshly allocatred nodes are found by traversing the trie and inspecting their state - Use the most recently committed revision's freelist to allocate new nodes. This will change in a future revision when the freelist is tied to storage rather than the revision. - Rewrite flush_nodes to serialize then allocate. Previously, the node was serialized twice, once to determine the size during proposal creation (allocation time) and once to store it - Changes to the commit flow by separating the node persistence logic (see comments in commit.rs) Some miscellaneous changes included in this diff (could be split out): - Branch children iterators can no longer return reference to hashes, since they are sometimes behind an ArcSwap - Propogate logger feature in fwdctl (helped with debugging) - Remove use of stored_len in tests - size_from_area_index was a method on nodestore, but didn't use nodestore - uncached_node_and_size was dead code - New clippy lint for hash_helper not needing &self in non-ethhash fixed Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The implementation constisted of: - A new type, NodeAllocator, to consolidate all the allocation code - Removing the 'new' hashmap, as freshly allocatred nodes are found by traversing the trie and inspecting their state - Use the most recently committed revision's freelist to allocate new nodes. This will change in a future revision when the freelist is tied to storage rather than the revision. - Rewrite flush_nodes to serialize then allocate. Previously, the node was serialized twice, once to determine the size during proposal creation (allocation time) and once to store it - Changes to the commit flow by separating the node persistence logic (see comments in commit.rs) Some miscellaneous changes included in this diff (could be split out): - Branch children iterators can no longer return reference to hashes, since they are sometimes behind an ArcSwap - Propogate logger feature in fwdctl (helped with debugging) - Remove use of stored_len in tests - size_from_area_index was a method on nodestore, but didn't use nodestore - uncached_node_and_size was dead code - New clippy lint for hash_helper not needing &self in non-ethhash fixed Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
feat(deferred-allocate): Part 3: Defer allocate This implements deferred allocaion that delays allocating space for nodes until commit time. The nodestore refactor consisted of removing the 'new' hashmap, which mapped newly allocated nodes to their contents in a proposal. Instead, now we store those newly allocated nodes directly from the `Child` struct. The implementation constisted of: - A new type, NodeAllocator, to consolidate all the allocation code - Removing the 'new' hashmap, as freshly allocatred nodes are found by traversing the trie and inspecting their state - Use the most recently committed revision's freelist to allocate new nodes. This will change in a future revision when the freelist is tied to storage rather than the revision. - Rewrite flush_nodes to serialize then allocate. Previously, the node was serialized twice, once to determine the size during proposal creation (allocation time) and once to store it - Changes to the commit flow by separating the node persistence logic (see comments in commit.rs) Some miscellaneous changes included in this diff (could be split out): - Branch children iterators can no longer return reference to hashes, since they are sometimes behind an ArcSwap - Propogate logger feature in fwdctl (helped with debugging) - Remove use of stored_len in tests - size_from_area_index was a method on nodestore, but didn't use nodestore - uncached_node_and_size was dead code - New clippy lint for hash_helper not needing &self in non-ethhash fixed Task completion status: [x] Roots may not be persisted (Part 1: #1041) [x] BranchNode children can now be Node, LinearAddress or a MaybePersistedNode (Part 2: #1045 and #1047) [x] When converting a `MutableProposal` to an `ImmutableProposal`, don't actually allocate space, just create `SharedNode`s from the `Node`s. (Part 3: #1055 and this PR) [ ] Remove `NodeStoreHeader` from `NodeStore`. The header should move into the `RevisionManager`. [ ] Allocate new nodes from the recently-freed nodes from an expired revision, then from the freelist. This can be done by maintaining a local freelist from the nodes deleted in the expiring revision and falling back to the actual freelist. Deleted nodes that are not reused must still be pushed onto the freelist.
Introduces a new type,
MaybePersistedNode
, which is a node which is either a SharedNode or a LinearAddress. This new type will allow writes to occur while readers are still reading this revision using anArcSwap
.Note that this does not actually put any additional nodes in memory, it just sets things up so they could be in memory.
Additional changes needed for this feature to be complete are:
MutableProposal
to anImmutableProposal
, don't actually allocate space, just createSharedNode
s from theNode
s.NodeStoreHeader
fromNodeStore
. The header should move into theRevisionManager
.