Search in sources :

Example 11 with ClusterMarkFile

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();
    }
}
Also used : ClusterMarkFile(io.aeron.cluster.service.ClusterMarkFile)

Example 12 with ClusterMarkFile

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.");
    }
}
Also used : ClusterMarkFile(io.aeron.cluster.service.ClusterMarkFile) SystemEpochClock(org.agrona.concurrent.SystemEpochClock) EpochClock(org.agrona.concurrent.EpochClock) Date(java.util.Date)

Example 13 with ClusterMarkFile

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());
    }
}
Also used : ClusterMarkFile(io.aeron.cluster.service.ClusterMarkFile) ClusterNodeControlProperties(io.aeron.cluster.service.ClusterNodeControlProperties) CountersReader(org.agrona.concurrent.status.CountersReader) AtomicCounter(org.agrona.concurrent.status.AtomicCounter) File(java.io.File) ClusterMarkFile(io.aeron.cluster.service.ClusterMarkFile)

Example 14 with ClusterMarkFile

use of io.aeron.cluster.service.ClusterMarkFile in project Aeron by real-logic.

the class SystemTestWatcher method printClusterMarkFileErrors.

private void printClusterMarkFileErrors(final List<Path> paths, final String fileDescription) {
    for (final Path path : paths) {
        try (ClusterMarkFile clusterMarkFile = openClusterMarkFile(path)) {
            final AtomicBuffer buffer = clusterMarkFile.errorBuffer();
            System.out.printf("%n%n%s file %s%n", fileDescription, path);
            final int distinctErrorCount = ErrorLogReader.read(buffer, this::printObservationCallback);
            System.out.format("%d distinct errors observed.%n", distinctErrorCount);
        }
    }
}
Also used : Path(java.nio.file.Path) ClusterMarkFile(io.aeron.cluster.service.ClusterMarkFile) AtomicBuffer(org.agrona.concurrent.AtomicBuffer)

Example 15 with ClusterMarkFile

use of io.aeron.cluster.service.ClusterMarkFile in project Aeron by real-logic.

the class SystemTestWatcher method countClusterMarkFileErrors.

private int countClusterMarkFileErrors(final List<Path> paths, final Predicate<String> filter) {
    final MutableInteger errorCount = new MutableInteger();
    for (final Path path : paths) {
        try (ClusterMarkFile clusterMarkFile = openClusterMarkFile(path)) {
            final AtomicBuffer buffer = clusterMarkFile.errorBuffer();
            ErrorLogReader.read(buffer, (observationCount, firstObservationTimestamp, lastObservationTimestamp, encodedException) -> {
                if (filter.test(encodedException)) {
                    errorCount.set(errorCount.get() + observationCount);
                }
            });
        }
    }
    return errorCount.get();
}
Also used : Path(java.nio.file.Path) ClusterMarkFile(io.aeron.cluster.service.ClusterMarkFile) MutableInteger(org.agrona.collections.MutableInteger) AtomicBuffer(org.agrona.concurrent.AtomicBuffer)

Aggregations

ClusterMarkFile (io.aeron.cluster.service.ClusterMarkFile)20 Path (java.nio.file.Path)4 AtomicBuffer (org.agrona.concurrent.AtomicBuffer)4 ClusterNodeControlProperties (io.aeron.cluster.service.ClusterNodeControlProperties)2 File (java.io.File)2 Date (java.util.Date)2 MutableInteger (org.agrona.collections.MutableInteger)2 EpochClock (org.agrona.concurrent.EpochClock)2 SystemEpochClock (org.agrona.concurrent.SystemEpochClock)2 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)2 CountersReader (org.agrona.concurrent.status.CountersReader)2