use of io.aeron.cluster.service.ClusterMarkFile in project aeron by real-logic.
the class ClusterTool method nextBackupQuery.
/**
* Set the time of the next backup query for the cluster backup.
*
* @param out to print the output to.
* @param clusterDir where the cluster is running.
* @param delayMs from the current time for the next backup query.
*/
public static void nextBackupQuery(final PrintStream out, final File clusterDir, final long delayMs) {
if (markFileExists(clusterDir) || TIMEOUT_MS > 0) {
try (ClusterMarkFile markFile = openMarkFile(clusterDir, System.out::println)) {
if (markFile.decoder().componentType() != ClusterComponentType.BACKUP) {
out.println("not a cluster backup node");
} else {
final EpochClock epochClock = SystemEpochClock.INSTANCE;
nextBackupQueryDeadlineMs(markFile, epochClock.time() + delayMs);
out.format("%2$tF %1$tH:%1$tM:%1$tS setting next: %2$tF %2$tH:%2$tM:%2$tS%n", new Date(), new Date(nextBackupQueryDeadlineMs(markFile)));
}
}
} else {
out.println(ClusterMarkFile.FILENAME + " does not exist.");
}
}
use of io.aeron.cluster.service.ClusterMarkFile in project aeron by real-logic.
the class ClusterTool method toggleClusterState.
@SuppressWarnings("MethodLength")
private static boolean toggleClusterState(final PrintStream out, final File clusterDir, final ConsensusModule.State expectedState, final ClusterControl.ToggleState toggleState, final boolean waitForToggleToComplete, final long defaultTimeoutMs) {
if (!markFileExists(clusterDir) && TIMEOUT_MS <= 0) {
out.println(ClusterMarkFile.FILENAME + " does not exist.");
return false;
}
final int clusterId;
final ClusterNodeControlProperties clusterNodeControlProperties;
try (ClusterMarkFile markFile = openMarkFile(clusterDir, out::println)) {
clusterId = markFile.clusterId();
clusterNodeControlProperties = markFile.loadControlProperties();
}
final ClusterMembership clusterMembership = new ClusterMembership();
final long queryTimeoutMs = Math.max(TimeUnit.SECONDS.toMillis(1), TIMEOUT_MS);
if (!queryClusterMembers(clusterNodeControlProperties, queryTimeoutMs, clusterMembership)) {
out.println("Timed out querying cluster.");
return false;
}
final String prefix = "Member [" + clusterMembership.memberId + "]: ";
if (clusterMembership.leaderMemberId != clusterMembership.memberId) {
out.println(prefix + "Current node is not the leader (leaderMemberId = " + clusterMembership.leaderMemberId + "), unable to " + toggleState);
return false;
}
final File cncFile = new File(clusterNodeControlProperties.aeronDirectoryName, CncFileDescriptor.CNC_FILE);
if (!cncFile.exists()) {
out.println(prefix + "Unable to locate media driver. C`n`C file [" + cncFile.getAbsolutePath() + "] does not exist.");
return false;
}
final CountersReader countersReader = ClusterControl.mapCounters(cncFile);
try {
final ConsensusModule.State moduleState = ConsensusModule.State.find(countersReader, clusterId);
if (null == moduleState) {
out.println(prefix + "Unable to resolve state of consensus module.");
return false;
}
if (expectedState != moduleState) {
out.println(prefix + "Unable to " + toggleState + " as the state of the consensus module is " + moduleState + ", but needs to be " + expectedState);
return false;
}
final AtomicCounter controlToggle = ClusterControl.findControlToggle(countersReader, clusterId);
if (null == controlToggle) {
out.println(prefix + "Failed to find control toggle");
return false;
}
if (!toggleState.toggle(controlToggle)) {
out.println(prefix + "Failed to apply " + toggleState + ", current toggle value = " + ClusterControl.ToggleState.get(controlToggle));
return false;
}
if (waitForToggleToComplete) {
final long toggleTimeoutMs = Math.max(defaultTimeoutMs, TIMEOUT_MS);
final long startTime = System.currentTimeMillis();
ClusterControl.ToggleState currentState = null;
do {
Thread.yield();
if ((System.currentTimeMillis() - startTime) > toggleTimeoutMs) {
break;
}
currentState = ClusterControl.ToggleState.get(controlToggle);
} while (currentState != ClusterControl.ToggleState.NEUTRAL);
if (currentState != ClusterControl.ToggleState.NEUTRAL) {
out.println(prefix + "Timed out after " + toggleTimeoutMs + "ms waiting for " + toggleState + " to complete.");
}
}
out.println(prefix + toggleState + " applied successfully");
return true;
} finally {
IoUtil.unmap(countersReader.valuesBuffer().byteBuffer());
}
}
use of io.aeron.cluster.service.ClusterMarkFile in project aeron by real-logic.
the class ClusterTool method errors.
/**
* Print out the errors in the error logs for the cluster components.
*
* @param out to print the output to.
* @param serviceMarkFiles to query.
*/
public static void errors(final PrintStream out, final ClusterMarkFile[] serviceMarkFiles) {
for (final ClusterMarkFile serviceMarkFile : serviceMarkFiles) {
printTypeAndActivityTimestamp(out, serviceMarkFile);
printErrors(out, serviceMarkFile);
serviceMarkFile.close();
}
}
use of io.aeron.cluster.service.ClusterMarkFile in project aeron by real-logic.
the class ClusterTool method describe.
/**
* Print out the descriptors in the {@link ClusterMarkFile}s.
*
* @param out to print the output to.
* @param clusterDir where the cluster is running.
*/
public static void describe(final PrintStream out, final File clusterDir) {
if (markFileExists(clusterDir) || TIMEOUT_MS > 0) {
try (ClusterMarkFile markFile = openMarkFile(clusterDir, out::println)) {
printTypeAndActivityTimestamp(out, markFile);
out.println(markFile.decoder());
}
} else {
out.println(ClusterMarkFile.FILENAME + " does not exist.");
}
final ClusterMarkFile[] serviceMarkFiles = openServiceMarkFiles(clusterDir, out::println);
describe(out, serviceMarkFiles);
}
use of io.aeron.cluster.service.ClusterMarkFile in project Aeron by real-logic.
the class ClusterTool method describe.
/**
* Print out the descriptors in the {@link ClusterMarkFile}s.
*
* @param out to print the output to.
* @param clusterDir where the cluster is running.
*/
public static void describe(final PrintStream out, final File clusterDir) {
if (markFileExists(clusterDir) || TIMEOUT_MS > 0) {
try (ClusterMarkFile markFile = openMarkFile(clusterDir, out::println)) {
printTypeAndActivityTimestamp(out, markFile);
out.println(markFile.decoder());
}
} else {
out.println(ClusterMarkFile.FILENAME + " does not exist.");
}
final ClusterMarkFile[] serviceMarkFiles = openServiceMarkFiles(clusterDir, out::println);
describe(out, serviceMarkFiles);
}
Aggregations