Skip to content
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

refactor: extract some Shadowgraph related classes to gossip module #16084

Draft
wants to merge 4 commits into
base: 15651-extraction-gossip-module-2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package com.swirlds.platform.gossip.shadowgraph;
package com.hedera.service.gossip.impl.shadowgraph;

/**
* A status representing the ability of the {@link Shadowgraph} to insert an event.
* A status representing the ability of the {Shadowgraph} to insert an event.
*/
public enum InsertableStatus {
/** The event can be inserted into the shadow graph. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package com.swirlds.platform.gossip.shadowgraph;
package com.hedera.service.gossip.impl.shadowgraph;

/**
* An exception thrown by {@link Shadowgraph} when an event cannot be added to the shadow graph.
* An exception thrown by {Shadowgraph} when an event cannot be added to the shadow graph.
*/
public class ShadowgraphInsertionException extends RuntimeException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

package com.swirlds.platform.gossip.shadowgraph;
package com.hedera.service.gossip.impl.shadowgraph;

import java.util.concurrent.atomic.AtomicInteger;

/**
* Represents zero or more reservations for an ancient indicator (i.e. a generation or a birth round, depending on
* current {@link com.swirlds.platform.event.AncientMode andient mode}). It is used to determine when it is safe to
* expire events in a given ancient indicator. Reservations are made by gossip threads inside {@link Shadowgraph}.
* current {ancient mode}). It is used to determine when it is safe to
* expire events in a given ancient indicator. Reservations are made by gossip threads inside {Shadowgraph}.
* Ancient indicators that have at least one reservation may not have any of its events expired.
*/
public final class ShadowgraphReservation implements AutoCloseable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

package com.swirlds.platform.gossip.shadowgraph;
package com.hedera.service.gossip.impl.shadowgraph;

import com.swirlds.common.platform.NodeId;

/**
* Information about a successful sync that just occurred
* Information about a successful sync that just occurred.
*/
public class SyncResult {
private final boolean caller;
Expand All @@ -28,14 +28,16 @@ public class SyncResult {
private final int eventsWritten;

/**
* Constructs a new SyncResult.
*
* @param caller
* true if this node initiated the sync, false otherwise
* true if this node initiated the sync, false otherwise
* @param otherId
* the ID of the node we synced with
* the ID of the node we synced with
* @param eventsRead
* the number of events read during the sync
* the number of events read during the sync
* @param eventsWritten
* the number of events written during the sync
* the number of events written during the sync
*/
public SyncResult(final boolean caller, final NodeId otherId, final int eventsRead, final int eventsWritten) {
this.caller = caller;
Expand All @@ -45,27 +47,35 @@ public SyncResult(final boolean caller, final NodeId otherId, final int eventsRe
}

/**
* Returns whether this node initiated the sync.
*
* @return true if this node initiated the sync, false otherwise
*/
public boolean isCaller() {
return caller;
}

/**
* Returns the ID of the node synced with.
*
* @return the ID of the node we synced with
*/
public NodeId getOtherId() {
return otherId;
}

/**
* Returns the number of events read during the sync.
*
* @return the number of events read during the sync
*/
public int getEventsRead() {
return eventsRead;
}

/**
* Returns the number of events written during the sync.
*
* @return the number of events written during the sync
*/
public int getEventsWritten() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.swirlds.platform.gossip.shadowgraph;
package com.hedera.service.gossip.impl.shadowgraph;

/**
* A type to record the points for gossip steps. At the end of a gossip session,
Expand All @@ -23,58 +23,58 @@
*/
public class SyncTiming {
/**
* number of time points to record = {number of time intervals} + 1
* Number of time points to record = {number of time intervals} + 1.
*/
private static final int NUM_TIME_POINTS = 6;

/**
* JVM time points, in nanoseconds
* JVM time points, in nanoseconds.
*/
private final long[] t = new long[NUM_TIME_POINTS];
private final long[] timePoints = new long[NUM_TIME_POINTS];

/**
* Set the 0th time point
* Set the 0th time point.
*/
public void start() {
t[0] = now();
timePoints[0] = now();
}

/**
* Record the ith time point
* Record the ith time point.
*
* @param i
* the ith time point to record
* @param index
* the ith time point to record
*/
public void setTimePoint(final int i) {
t[i] = now();
public void setTimePoint(final int index) {
timePoints[index] = now();
}

/**
* Get the ith time point
* Get the ith time point.
*
* @param i
* the index of the time point
* @param index
* the index of the time point
* @return the ith recorded time point
*/
public long getTimePoint(final int i) {
return t[i];
public long getTimePoint(final int index) {
return timePoints[index];
}

/**
* Get the difference between two time points
* Get the difference between two time points.
*
* @param end
* the ending point
* the ending point
* @param start
* the starting point
* the starting point
* @return the difference
*/
public long getPointDiff(final int end, final int start) {
return t[end] - t[start];
return timePoints[end] - timePoints[start];
}

/**
* Get the current system time value in ns
* Get the current system time value in ns.
*
* @return current time in ns
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module com.hedera.consensus.gossip.impl {
exports com.hedera.service.gossip.impl;
exports com.hedera.service.gossip.impl.shadowgraph;

requires transitive com.swirlds.common;
requires transitive com.hedera.service.gossip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.swirlds.platform.gossip.shadowgraph;

import com.hedera.service.gossip.impl.shadowgraph.ShadowgraphReservation;
import com.swirlds.platform.consensus.EventWindow;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import static com.swirlds.logging.legacy.LogMarker.SYNC_INFO;

import com.hedera.service.gossip.IntakeEventCounter;
import com.hedera.service.gossip.impl.shadowgraph.InsertableStatus;
import com.hedera.service.gossip.impl.shadowgraph.ShadowgraphInsertionException;
import com.hedera.service.gossip.impl.shadowgraph.ShadowgraphReservation;
import com.swirlds.common.AddressBook;
import com.swirlds.common.context.PlatformContext;
import com.swirlds.common.crypto.Hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import com.hedera.service.gossip.FallenBehindManager;
import com.hedera.service.gossip.IntakeEventCounter;
import com.hedera.service.gossip.impl.shadowgraph.SyncResult;
import com.hedera.service.gossip.impl.shadowgraph.SyncTiming;
import com.swirlds.base.time.Time;
import com.swirlds.common.context.PlatformContext;
import com.swirlds.common.platform.NodeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import static com.swirlds.metrics.api.Metrics.INTERNAL_CATEGORY;
import static com.swirlds.metrics.api.Metrics.PLATFORM_CATEGORY;

import com.hedera.service.gossip.impl.shadowgraph.SyncResult;
import com.hedera.service.gossip.impl.shadowgraph.SyncTiming;
import com.swirlds.base.units.UnitConstants;
import com.swirlds.common.metrics.RunningAverageMetric;
import com.swirlds.common.metrics.extensions.CountPerSecond;
import com.swirlds.metrics.api.Metrics;
import com.swirlds.platform.consensus.EventWindow;
import com.swirlds.platform.gossip.shadowgraph.ShadowgraphSynchronizer;
import com.swirlds.platform.gossip.shadowgraph.SyncResult;
import com.swirlds.platform.gossip.shadowgraph.SyncTiming;
import com.swirlds.platform.network.Connection;
import com.swirlds.platform.stats.AverageAndMax;
import com.swirlds.platform.stats.AverageAndMaxTimeStat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.mockito.Mockito.mock;

import com.hedera.service.gossip.impl.NoOpIntakeEventCounter;
import com.hedera.service.gossip.impl.shadowgraph.ShadowgraphInsertionException;
import com.swirlds.common.AddressBook;
import com.swirlds.common.context.PlatformContext;
import com.swirlds.common.crypto.Hash;
Expand All @@ -39,7 +40,6 @@
import com.swirlds.platform.gossip.shadowgraph.ReservedEventWindow;
import com.swirlds.platform.gossip.shadowgraph.ShadowEvent;
import com.swirlds.platform.gossip.shadowgraph.Shadowgraph;
import com.swirlds.platform.gossip.shadowgraph.ShadowgraphInsertionException;
import com.swirlds.platform.internal.EventImpl;
import com.swirlds.platform.system.events.EventDescriptorWrapper;
import com.swirlds.platform.test.event.emitter.EventEmitterFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.mockito.Mockito.mock;

import com.hedera.service.gossip.impl.NoOpIntakeEventCounter;
import com.hedera.service.gossip.impl.shadowgraph.ShadowgraphInsertionException;
import com.swirlds.common.AddressBook;
import com.swirlds.common.context.PlatformContext;
import com.swirlds.common.crypto.Hash;
Expand All @@ -42,7 +43,6 @@
import com.swirlds.platform.gossip.shadowgraph.ReservedEventWindow;
import com.swirlds.platform.gossip.shadowgraph.ShadowEvent;
import com.swirlds.platform.gossip.shadowgraph.Shadowgraph;
import com.swirlds.platform.gossip.shadowgraph.ShadowgraphInsertionException;
import com.swirlds.platform.internal.EventImpl;
import com.swirlds.platform.system.events.EventDescriptorWrapper;
import com.swirlds.platform.test.event.emitter.EventEmitterFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.hedera.service.gossip.IntakeEventCounter;
import com.hedera.service.gossip.impl.NoOpIntakeEventCounter;
import com.hedera.service.gossip.impl.shadowgraph.ShadowgraphInsertionException;
import com.swirlds.common.AddressBook;
import com.swirlds.common.context.PlatformContext;
import com.swirlds.common.platform.NodeId;
Expand All @@ -37,7 +38,6 @@
import com.swirlds.platform.event.hashing.EventHasher;
import com.swirlds.platform.eventhandling.EventConfig_;
import com.swirlds.platform.gossip.shadowgraph.Shadowgraph;
import com.swirlds.platform.gossip.shadowgraph.ShadowgraphInsertionException;
import com.swirlds.platform.gossip.shadowgraph.ShadowgraphSynchronizer;
import com.swirlds.platform.gossip.sync.config.SyncConfig_;
import com.swirlds.platform.internal.EventImpl;
Expand Down
Loading