Skip to content

Commit

Permalink
Update the reset method and remove migrate
Browse files Browse the repository at this point in the history
Signed-off-by: gconnect <agatevureglory@gmail.com>
  • Loading branch information
gconnect committed Sep 30, 2024
1 parent 8a3d40c commit d23b3c4
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory.DEFAULT_MAX_QUEUE_SIZE;
import static tech.pegasys.teku.spec.config.Constants.STORAGE_QUERY_CHANNEL_PARALLELISM;

import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -84,25 +85,18 @@ protected SafeFuture<?> doStart() {
1,
DEFAULT_MAX_QUEUE_SIZE,
Thread.NORM_PRIORITY - 1);
VersionedDatabaseFactory dbFactory =
final VersionedDatabaseFactory dbFactory =
new VersionedDatabaseFactory(
serviceConfig.getMetricsSystem(),
serviceConfig.getDataDirLayout().getBeaconDataDirectory(),
config);

try {
database = dbFactory.createDatabase();
database.migrate();
} catch (EphemeryException e) {
try {
resetDatabaseDirectories(serviceConfig);
database = dbFactory.createDatabase();
database.migrate();
} catch (Exception ex) {
throw new RuntimeException("Failed to reset and recreate the database.", ex);
}
database = resetDatabaseAndCreate(serviceConfig, dbFactory);
;
}

final SettableLabelledGauge pruningTimingsLabelledGauge =
SettableLabelledGauge.create(
serviceConfig.getMetricsSystem(),
Expand Down Expand Up @@ -238,12 +232,21 @@ public ChainStorage getChainStorage() {
}

/** This method is called only on Ephemery network when reset is due. */
void resetDatabaseDirectories(final ServiceConfig serviceConfig) throws IOException {
final Path beaconDataDir = serviceConfig.getDataDirLayout().getBeaconDataDirectory();
final Path slashProtectionDir =
serviceConfig.getDataDirLayout().getValidatorDataDirectory().resolve("slashprotection");
deleteDirectoryRecursively(beaconDataDir);
deleteDirectoryRecursively(slashProtectionDir);
@VisibleForTesting
private Database resetDatabaseAndCreate(
final ServiceConfig serviceConfig, final VersionedDatabaseFactory dbFactory) {
try {
final Path beaconDataDir = serviceConfig.getDataDirLayout().getBeaconDataDirectory();
final Path slashProtectionDir =
serviceConfig.getDataDirLayout().getValidatorDataDirectory().resolve("slashprotection");
deleteDirectoryRecursively(beaconDataDir);
deleteDirectoryRecursively(slashProtectionDir);

return dbFactory.createDatabase();
} catch (final Exception ex) {
throw new InvalidConfigurationException(
"The existing ephemery database was old, and was unable to reset it.", ex);
}
}

private void deleteDirectoryRecursively(final Path path) throws IOException {
Expand Down

0 comments on commit d23b3c4

Please sign in to comment.