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

Copy the PCES into saved state directories. #9809

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Integer call() throws IOException, ExecutionException, InterruptedExcepti
.digestTreeAsync(reservedSignedState.get().getState())
.get();
System.out.printf("Writing modified state to %s %n", outputDir.toAbsolutePath());
writeSignedStateFilesToDirectory(NO_NODE_ID, outputDir, reservedSignedState.get(), configuration);
writeSignedStateFilesToDirectory(platformContext, NO_NODE_ID, outputDir, reservedSignedState.get());
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public PreconsensusEventFileManager(
* @return the directory where event files are stored
*/
@NonNull
private static Path getDatabaseDirectory(
public static Path getDatabaseDirectory(
@NonNull final PlatformContext platformContext, @NonNull final NodeId selfId) throws IOException {

final StateConfig stateConfig = platformContext.getConfiguration().getConfigData(StateConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
* Both. Use this with caution.
* @param databaseDirectory the directory where preconsensus events will be stored,
* relative to
* {@link com.swirlds.common.config.StateConfig#savedStateDirectory()}.
* {@link
* com.swirlds.common.config.StateConfig#savedStateDirectory()}.
* @param enableStorage if true, then stream preconsensus events to files on disk. If
* this is disabled then a network wide crash (perhaps due to a
* bug) can cause transactions that previously reached consensus
Expand All @@ -90,6 +91,10 @@
* @param replayQueueSize the size of the queue used for holding preconsensus events
* that are waiting to be replayed
* @param replayHashPoolSize the number of threads used for hashing events during replay
* @param copyRecentStreamToStateSnapshots if true, then copy recent PCES files into the saved state
* snapshot directories every time we take a state snapshot. The
* files copied are guaranteed to contain all non-ancient events
* w.r.t. the state snapshot.
*/
@ConfigData("event.preconsensus")
public record PreconsensusEventStreamConfig(
Expand All @@ -106,4 +111,5 @@ public record PreconsensusEventStreamConfig(
@ConfigProperty(defaultValue = "true") boolean enableStorage,
@ConfigProperty(defaultValue = "true") boolean enableReplay,
@ConfigProperty(defaultValue = "1024") int replayQueueSize,
@ConfigProperty(defaultValue = "8") int replayHashPoolSize) {}
@ConfigProperty(defaultValue = "8") int replayHashPoolSize,
@ConfigProperty(defaultValue = "true") boolean copyRecentStreamToStateSnapshots) {}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ public static void recoverState(
resultingStateDirectory);

SignedStateFileWriter.writeSignedStateFilesToDirectory(
selfId, resultingStateDirectory, recoveredState.state().get(), platformContext.getConfiguration());
platformContext,
selfId,
resultingStateDirectory,
recoveredState.state().get());
final StateConfig stateConfig = platformContext.getConfiguration().getConfigData(StateConfig.class);
updateEmergencyRecoveryFile(
stateConfig, resultingStateDirectory, initialState.get().getConsensusTimestamp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import static com.swirlds.platform.state.signed.SignedStateFileWriter.writeSignedStateFilesToDirectory;

import com.swirlds.cli.utility.SubcommandOf;
import com.swirlds.common.context.DefaultPlatformContext;
import com.swirlds.common.context.PlatformContext;
import com.swirlds.common.crypto.CryptographyHolder;
import com.swirlds.common.merkle.crypto.MerkleCryptoFactory;
import com.swirlds.common.metrics.noop.NoOpMetrics;
import com.swirlds.config.api.Configuration;
import com.swirlds.logging.legacy.LogMarker;
import com.swirlds.platform.config.DefaultConfiguration;
Expand Down Expand Up @@ -69,8 +73,12 @@ public void run() {
}

final Configuration configuration = DefaultConfiguration.buildBasicConfiguration();

final PlatformContext platformContext =
new DefaultPlatformContext(configuration, new NoOpMetrics(), CryptographyHolder.get());

try (final ReservedSignedState signedState = getStateEditor().getSignedStateCopy()) {
writeSignedStateFilesToDirectory(NO_NODE_ID, directory, signedState.get(), configuration);
writeSignedStateFilesToDirectory(platformContext, NO_NODE_ID, directory, signedState.get());
}

} catch (final IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class SignedStateFileManager implements Startable {
private final SignedStateMetrics metrics;

private final Configuration configuration;
private final PlatformContext platformContext;

/**
* Provides system time
Expand Down Expand Up @@ -162,6 +163,7 @@ public SignedStateFileManager(
this.mainClassName = mainClassName;
this.swirldName = swirldName;
this.stateToDiskAttemptConsumer = stateToDiskAttemptConsumer;
this.platformContext = Objects.requireNonNull(context);
this.configuration = Objects.requireNonNull(context).getConfiguration();
this.minimumGenerationNonAncientConsumer = Objects.requireNonNull(
minimumGenerationNonAncientConsumer, "minimumGenerationNonAncientConsumer must not be null");
Expand Down Expand Up @@ -288,7 +290,7 @@ private void saveStateTask(
if (outOfBand) {
// states requested to be written out-of-band are always written to disk
SignedStateFileWriter.writeSignedStateToDisk(
selfId, directory, reservedSignedState.get(), reason, configuration);
platformContext, selfId, directory, reservedSignedState.get(), reason);

success = true;
} else {
Expand All @@ -303,7 +305,7 @@ private void saveStateTask(
}

SignedStateFileWriter.writeSignedStateToDisk(
selfId, directory, reservedSignedState.get(), reason, configuration);
platformContext, selfId, directory, reservedSignedState.get(), reason);
stateWrittenToDiskInBand(reservedSignedState.get(), directory, start);

success = true;
Expand Down Expand Up @@ -408,8 +410,8 @@ public boolean saveSignedStateToDisk(@NonNull final SignedState signedState, fin
* Dump a state to disk out-of-band.
* <p>
* Writing a state "out-of-band" means the state is being written for the sake of a human, whether for debug
* purposes, or because of a fault. States written out-of-band will not be read automatically by the platform,
* and will not be used as an initial state at boot time.
* purposes, or because of a fault. States written out-of-band will not be read automatically by the platform, and
* will not be used as an initial state at boot time.
* <p>
* A dumped state will be saved in a subdirectory of the signed states base directory, with the subdirectory being
* named after the reason the state is being written out-of-band.
Expand Down