-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add vertex store size limit; cleanup vertex store events #854
base: develop
Are you sure you want to change the base?
Changes from 2 commits
501a3bf
783d36f
a79c14b
b707db8
1ad56a4
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 |
---|---|---|
|
@@ -64,9 +64,18 @@ | |
|
||
package com.radixdlt.consensus.bft; | ||
|
||
import com.radixdlt.consensus.event.LocalEvent; | ||
import com.radixdlt.consensus.vertexstore.ExecutedVertex; | ||
import com.radixdlt.utils.WrappedByteArray; | ||
|
||
/** An event emitted after a vertex has been inserted into the vertex store. */ | ||
public record BFTInsertUpdate( | ||
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. We've lost the nice 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. Otherwise we could end up with a massive log of the serialized vertex state in hex. |
||
ExecutedVertex insertedVertex, WrappedByteArray serializedVertexStoreState) {} | ||
ExecutedVertex insertedVertex, WrappedByteArray serializedVertexStoreState) | ||
implements LocalEvent { | ||
@Override | ||
public String toString() { | ||
return String.format( | ||
"%s[insertedVertex=%s serializedVertexStoreStateSize=%s]", | ||
getClass().getSimpleName(), insertedVertex(), serializedVertexStoreState.size()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,4 +70,13 @@ | |
|
||
/** An even emitted when the vertex store has been rebuilt. */ | ||
public record BFTRebuildUpdate( | ||
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. We've lost the nice 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. Otherwise we could end up with a massive log of the serialized vertex state in hex. |
||
VertexStoreState vertexStoreState, WrappedByteArray serializedVertexStoreState) {} | ||
VertexStoreState vertexStoreState, WrappedByteArray serializedVertexStoreState) | ||
implements LocalEvent { | ||
|
||
@Override | ||
public String toString() { | ||
return String.format( | ||
"%s[serializedVertexStoreStateSize=%s]", | ||
getClass().getSimpleName(), serializedVertexStoreState.size()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ | |
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Multimap; | ||
import com.google.common.hash.HashCode; | ||
import com.radixdlt.consensus.BFTHeader; | ||
|
@@ -425,7 +426,10 @@ private void removeVertexAndPruneInternal(HashCode vertexId, Optional<HashCode> | |
return; | ||
} | ||
|
||
final var children = vertexChildren.removeAll(vertexId); | ||
// Note that we need a copy of the children list here (.stream().toList()) - that is because | ||
// we're removing the items in the loop (otherwise, this could lead to | ||
// ConcurrentModificationException) | ||
final var children = vertexChildren.get(vertexId).stream().toList(); | ||
for (HashCode child : children) { | ||
if (!Optional.of(child).equals(skip)) { | ||
removeVertexAndPruneInternal(child, Optional.empty()); | ||
|
@@ -468,13 +472,13 @@ public boolean containsVertex(HashCode vertexId) { | |
|
||
private VertexStoreState getState() { | ||
// TODO: store list dynamically rather than recomputing | ||
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. It's not that expensive, so it's not a big deal... Although I wonder why we can't just do |
||
ImmutableList.Builder<VertexWithHash> verticesBuilder = ImmutableList.builder(); | ||
ImmutableSet.Builder<VertexWithHash> verticesBuilder = ImmutableSet.builder(); | ||
getChildrenVerticesList(this.rootVertex, verticesBuilder); | ||
return VertexStoreState.create(this.highQC(), this.rootVertex, verticesBuilder.build(), hasher); | ||
} | ||
|
||
private void getChildrenVerticesList( | ||
VertexWithHash parent, ImmutableList.Builder<VertexWithHash> builder) { | ||
VertexWithHash parent, ImmutableSet.Builder<VertexWithHash> builder) { | ||
for (HashCode child : this.vertexChildren.get(parent.hash())) { | ||
final var v = vertices.get(child); | ||
builder.add(v); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ | |
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.hash.HashCode; | ||
import com.radixdlt.consensus.*; | ||
import com.radixdlt.consensus.bft.Round; | ||
|
@@ -94,10 +95,10 @@ public final class VertexStoreState { | |
|
||
private final VertexWithHash root; | ||
private final HighQC highQC; | ||
private final ImmutableList<VertexWithHash> vertices; | ||
private final ImmutableSet<VertexWithHash> vertices; | ||
|
||
private VertexStoreState( | ||
HighQC highQC, VertexWithHash root, ImmutableList<VertexWithHash> vertices) { | ||
HighQC highQC, VertexWithHash root, ImmutableSet<VertexWithHash> vertices) { | ||
this.highQC = highQC; | ||
this.root = root; | ||
this.vertices = vertices; | ||
|
@@ -123,11 +124,11 @@ public static VertexStoreState createNewForNextEpoch( | |
} | ||
|
||
public static VertexStoreState create(HighQC highQC, VertexWithHash root, Hasher hasher) { | ||
return create(highQC, root, ImmutableList.of(), hasher); | ||
return create(highQC, root, ImmutableSet.of(), hasher); | ||
} | ||
|
||
public static VertexStoreState create( | ||
HighQC highQC, VertexWithHash root, ImmutableList<VertexWithHash> vertices, Hasher hasher) { | ||
HighQC highQC, VertexWithHash root, ImmutableSet<VertexWithHash> vertices, Hasher hasher) { | ||
final var processedQcCommit = | ||
highQC | ||
.highestCommittedQC() | ||
|
@@ -216,7 +217,7 @@ public VertexStoreState withVertex(VertexWithHash vertex) { | |
return new VertexStoreState( | ||
this.highQC, | ||
this.root, | ||
ImmutableList.<VertexWithHash>builder().addAll(this.vertices).add(vertex).build()); | ||
ImmutableSet.<VertexWithHash>builder().addAll(this.vertices).add(vertex).build()); | ||
} | ||
|
||
public SerializedVertexStoreState toSerialized() { | ||
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. Hmm should we call this 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. Also I wonder if we should just make this |
||
|
@@ -236,7 +237,7 @@ public VertexWithHash getRoot() { | |
return root; | ||
} | ||
|
||
public ImmutableList<VertexWithHash> getVertices() { | ||
public ImmutableSet<VertexWithHash> getVertices() { | ||
return vertices; | ||
} | ||
|
||
|
@@ -309,7 +310,7 @@ public VertexStoreState toVertexStoreState(Hasher hasher) { | |
var rootWithHash = root.withId(hasher); | ||
|
||
var verticesWithHash = | ||
vertices.stream().map(v -> v.withId(hasher)).collect(ImmutableList.toImmutableList()); | ||
vertices.stream().map(v -> v.withId(hasher)).collect(ImmutableSet.toImmutableSet()); | ||
|
||
return VertexStoreState.create(highQC, rootWithHash, verticesWithHash, hasher); | ||
} | ||
|
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.
We've lost the nice
toString
here - perhaps we should override it?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.
Otherwise we could end up with a massive log of the serialized vertex state in hex.