Skip to content

Commit

Permalink
[Java] Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Aug 30, 2024
1 parent a36d85c commit a6f524d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
53 changes: 30 additions & 23 deletions aeron-cluster/src/main/java/io/aeron/cluster/ConsensusModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
import io.aeron.cluster.codecs.MessageHeaderDecoder;
import io.aeron.cluster.codecs.StandbySnapshotDecoder;
import io.aeron.cluster.codecs.mark.ClusterComponentType;
import io.aeron.cluster.service.*;
import io.aeron.cluster.service.ClusterMarkFile;
import io.aeron.cluster.service.ClusterCounters;
import io.aeron.cluster.service.ClusteredServiceContainer;
import io.aeron.cluster.service.ClusterClock;
import io.aeron.cluster.service.SnapshotDurationTracker;

import io.aeron.config.Config;
import io.aeron.config.DefaultType;
import io.aeron.driver.DutyCycleTracker;
Expand All @@ -50,6 +55,7 @@
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
Expand All @@ -64,8 +70,6 @@
import static io.aeron.cluster.ConsensusModule.Configuration.CLUSTER_NODE_ROLE_TYPE_ID;
import static io.aeron.cluster.ConsensusModule.Configuration.COMMIT_POSITION_TYPE_ID;
import static io.aeron.cluster.ConsensusModule.Configuration.*;
import static io.aeron.cluster.service.ClusteredServiceContainer.Configuration.*;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater;
import static org.agrona.BitUtil.findNextPositivePowerOfTwo;
import static org.agrona.SystemUtil.*;
Expand Down Expand Up @@ -254,10 +258,10 @@ public static void main(final String[] args)
}
catch (final Exception ex)
{
if (null != ctx.markFile)
if (null != ctx.clusterMarkFile())
{
ctx.markFile.signalFailedStart();
ctx.markFile.force();
ctx.clusterMarkFile().signalFailedStart();
ctx.clusterMarkFile().force();
}

CloseHelper.quietClose(ctx::close);
Expand Down Expand Up @@ -608,7 +612,7 @@ public static final class Configuration
/**
* Type id of a recovery state counter.
*/
public static final int RECOVERY_STATE_TYPE_ID = RecoveryState.RECOVERY_STATE_TYPE_ID;
public static final int RECOVERY_STATE_TYPE_ID = AeronCounters.CLUSTER_RECOVERY_STATE_TYPE_ID;

/**
* Counter type id for count of snapshots taken.
Expand Down Expand Up @@ -1074,7 +1078,8 @@ public static String memberEndpoints()
*/
public static String snapshotChannel()
{
return System.getProperty(SNAPSHOT_CHANNEL_PROP_NAME, SNAPSHOT_CHANNEL_DEFAULT);
return System.getProperty(
ClusteredServiceContainer.Configuration.SNAPSHOT_CHANNEL_PROP_NAME, SNAPSHOT_CHANNEL_DEFAULT);
}

/**
Expand All @@ -1086,7 +1091,8 @@ public static String snapshotChannel()
*/
public static int snapshotStreamId()
{
return Integer.getInteger(SNAPSHOT_STREAM_ID_PROP_NAME, SNAPSHOT_STREAM_ID_DEFAULT);
return Integer.getInteger(
ClusteredServiceContainer.Configuration.SNAPSHOT_STREAM_ID_PROP_NAME, SNAPSHOT_STREAM_ID_DEFAULT);
}

/**
Expand Down Expand Up @@ -1208,8 +1214,8 @@ public static long cycleThresholdNs()
*/
public static long totalSnapshotDurationThresholdNs()
{
return getDurationInNanos(TOTAL_SNAPSHOT_DURATION_THRESHOLD_PROP_NAME,
TOTAL_SNAPSHOT_DURATION_THRESHOLD_DEFAULT_NS);
return getDurationInNanos(
TOTAL_SNAPSHOT_DURATION_THRESHOLD_PROP_NAME, TOTAL_SNAPSHOT_DURATION_THRESHOLD_DEFAULT_NS);
}

/**
Expand Down Expand Up @@ -1689,7 +1695,7 @@ public void conclude()
ClusterComponentType.CONSENSUS_MODULE,
errorBufferLength,
epochClock,
LIVENESS_TIMEOUT_MS);
ClusteredServiceContainer.Configuration.LIVENESS_TIMEOUT_MS);
}

MarkFile.ensureMarkFileLink(
Expand Down Expand Up @@ -1717,7 +1723,7 @@ public void conclude()

if (null == errorLog)
{
errorLog = new DistinctErrorLog(markFile.errorBuffer(), epochClock, US_ASCII);
errorLog = new DistinctErrorLog(markFile.errorBuffer(), epochClock, StandardCharsets.US_ASCII);
}

errorHandler = CommonContext.setupErrorHandler(errorHandler, errorLog);
Expand Down Expand Up @@ -3586,7 +3592,7 @@ public Context moduleStateCounter(final Counter moduleState)
}

/**
* Get the counter for the current state of an election
* Get the counter for the current state of an election.
*
* @return the counter for the current state of an election.
* @see ElectionState
Expand Down Expand Up @@ -4423,16 +4429,17 @@ else if (PriorityHeapTimerServiceSupplier.class.getName().equals(timeServiceClas
private void validateLogChannel()
{
final ChannelUri logChannelUri = ChannelUri.parse(logChannel);
verifyNotPresent(logChannelUri, "logChannel", INITIAL_TERM_ID_PARAM_NAME);
verifyNotPresent(logChannelUri, "logChannel", TERM_ID_PARAM_NAME);
verifyNotPresent(logChannelUri, "logChannel", TERM_OFFSET_PARAM_NAME);
}

private static void verifyNotPresent(final ChannelUri channelUri, final String name, final String paramName)
{
if (channelUri.containsKey(paramName))
if (logChannelUri.containsKey(INITIAL_TERM_ID_PARAM_NAME))
{
throw new ConfigurationException("logChannel must not contain: " + INITIAL_TERM_ID_PARAM_NAME);
}
if (logChannelUri.containsKey(TERM_ID_PARAM_NAME))
{
throw new ConfigurationException("logChannel must not contain: " + TERM_ID_PARAM_NAME);
}
if (logChannelUri.containsKey(TERM_OFFSET_PARAM_NAME))
{
throw new ConfigurationException(name + " must not contain: " + paramName);
throw new ConfigurationException("logChannel must not contain: " + TERM_OFFSET_PARAM_NAME);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public final class ClusterMarkFile implements AutoCloseable
* Full semantic version.
*/
public static final int SEMANTIC_VERSION = SemanticVersion.compose(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);

/**
* Length of the {@code header} section.
*/
Expand All @@ -78,7 +77,6 @@ public final class ClusterMarkFile implements AutoCloseable
* Max allowed length for the error log buffer.
*/
public static final int ERROR_BUFFER_MAX_LENGTH = Integer.MAX_VALUE - HEADER_LENGTH;

/**
* File extension used by the mark file.
*/
Expand Down

0 comments on commit a6f524d

Please sign in to comment.