use of tech.pegasys.teku.cli.util.DatabaseMigraterError in project teku by ConsenSys.
the class MigrateDatabaseCommand method run.
// OVERVIEW
// teku folder has a 'beacon' folder
// If the user wants to change the type of database stored in 'beacon',
// they can run this command to accomplish that task.
// While running, a 'beacon.new' folder is created, and we copy data
// from 'beacon' to 'beacon.new'.
//
// If it completes successfully, we move:
// - 'beacon' -> 'beacon.old'
// - 'beacon.new' -> 'beacon'
// User is then advised to cleanup 'beacon.old' manually
//
// If the process fails to complete, may be left with 'beacon.new',
// and 'beacon' will have the previous working database in it, so the user
// could start teku again on the old working database.
@Override
public void run() {
// validate output format
final Optional<DatabaseVersion> maybeOutputVersion = DatabaseVersion.fromString(toDbVersion);
if (maybeOutputVersion.isEmpty()) {
SUB_COMMAND_LOG.exit(2, "Invalid database version specified: " + toDbVersion);
}
// and advice given to the user to cleanup 'beacon.old' manually.
if (Files.isDirectory(dataPath.resolve("beacon.old"))) {
SUB_COMMAND_LOG.exit(1, "There is an existing folder in " + dataPath.resolve("beacon.old").toFile() + ", review this folder and remove before continuing.");
}
dataDirLayout = DataDirLayout.createFrom(DataConfig.builder().dataBasePath(dataPath).beaconDataPath(dataBeaconPath).build());
// validate source database exists
final DatabaseVersion sourceDatabaseVersion = confirmAndCheckOriginalDb(maybeOutputVersion.get());
final DatabaseMigrater dbMigrater = DatabaseMigrater.builder().dataDirLayout(dataDirLayout).network(network).storageMode(dataStorageMode).batchSize(batchSize).statusUpdater(SUB_COMMAND_LOG::display).build();
try {
dbMigrater.migrateDatabase(sourceDatabaseVersion, maybeOutputVersion.get());
SUB_COMMAND_LOG.display("SUCCESS.");
SUB_COMMAND_LOG.display("The original database is stored in: " + dbMigrater.getMovedOldBeaconFolderPath());
SUB_COMMAND_LOG.display("This can be removed once you have confirmed the new database works.");
} catch (DatabaseMigraterError error) {
SUB_COMMAND_LOG.error("FAILED to migrate database: " + error.getMessage());
SUB_COMMAND_LOG.display("There is a partially created database at: " + dbMigrater.getNewBeaconFolderPath());
SUB_COMMAND_LOG.display("This is not in use and could be cleaned up.");
System.exit(1);
}
}
Aggregations