Search in sources :

Example 1 with DatabaseVersion

use of tech.pegasys.teku.storage.server.DatabaseVersion in project teku by ConsenSys.

the class StorageSystemArgumentsProvider method provideArguments.

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
    final Map<String, StorageSystemSupplier> storageSystems = new HashMap<>();
    for (StateStorageMode mode : StateStorageMode.values()) {
        for (Long storageFrequency : stateStorageFrequencyOptions) {
            for (DatabaseVersion databaseVersion : supportedDatabaseVersions()) {
                storageSystems.put(describeStorage(databaseVersion.name() + " (in-memory)", storageFrequency), (dataPath, spec) -> InMemoryStorageSystemBuilder.create().specProvider(spec).version(databaseVersion).storageMode(mode).stateStorageFrequency(storageFrequency).build());
                storageSystems.put(describeStorage(databaseVersion.name() + " (file-backed)", storageFrequency), (dataPath, spec) -> FileBackedStorageSystemBuilder.create().specProvider(spec).version(databaseVersion).dataDir(dataPath).storageMode(mode).stateStorageFrequency(storageFrequency).build());
            }
        }
    }
    return storageSystems.entrySet().stream().map((entry) -> Arguments.of("storage type: " + entry.getKey(), entry.getValue()));
}
Also used : HashMap(java.util.HashMap) StateStorageMode(tech.pegasys.teku.storage.server.StateStorageMode) DatabaseVersion(tech.pegasys.teku.storage.server.DatabaseVersion)

Example 2 with DatabaseVersion

use of tech.pegasys.teku.storage.server.DatabaseVersion in project teku by ConsenSys.

the class MigrateDatabaseCommand method validateSourceDatabase.

private DatabaseVersion validateSourceDatabase(final DatabaseVersion databaseVersion) {
    final File currentDatabasePath = dataDirLayout.getBeaconDataDirectory().toAbsolutePath().toFile();
    if (!currentDatabasePath.isDirectory()) {
        SUB_COMMAND_LOG.exit(1, "Could not locate the existing database to migrate from: " + currentDatabasePath);
    }
    try {
        final String versionValue = Files.readString(currentDatabasePath.toPath().resolve("db.version")).trim();
        final DatabaseVersion currentDatabaseVersion = DatabaseVersion.fromString(versionValue).orElseThrow(() -> new IOException("Could not read db.version file"));
        if (currentDatabaseVersion.equals(databaseVersion)) {
            SUB_COMMAND_LOG.exit(0, "The specified database is already the requested version");
        }
        return currentDatabaseVersion;
    } catch (IOException e) {
        SUB_COMMAND_LOG.exit(1, "Could not read db.version file");
        // NOT REACHED
        return DatabaseVersion.DEFAULT_VERSION;
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) DatabaseVersion(tech.pegasys.teku.storage.server.DatabaseVersion)

Example 3 with DatabaseVersion

use of tech.pegasys.teku.storage.server.DatabaseVersion in project teku by ConsenSys.

the class MigrateDatabaseCommand method confirmAndCheckOriginalDb.

private DatabaseVersion confirmAndCheckOriginalDb(final DatabaseVersion databaseVersion) {
    // validate source database exists
    final DatabaseVersion sourceDatabaseVersion = validateSourceDatabase(databaseVersion);
    displaySourceDatabaseDetails(sourceDatabaseVersion);
    SUB_COMMAND_LOG.display("Requested database version: " + databaseVersion);
    SUB_COMMAND_LOG.display("A beacon.new folder will be created with the new database");
    SUB_COMMAND_LOG.display("If the data is moved successfully: ");
    SUB_COMMAND_LOG.display(" - The existing beacon folder will become beacon.old");
    SUB_COMMAND_LOG.display(" - The beacon.new folder will become beacon (the active database)");
    SUB_COMMAND_LOG.display(" - Once you have confirmed the new database works, you can remove the old database");
    SUB_COMMAND_LOG.display("This operation will need to happen while teku is not running.");
    SUB_COMMAND_LOG.display("");
    if (!confirmYes("Proceed with database migration (yes/no)?")) {
        SUB_COMMAND_LOG.display("Operation cancelled.");
        System.exit(0);
    }
    return sourceDatabaseVersion;
}
Also used : DatabaseVersion(tech.pegasys.teku.storage.server.DatabaseVersion)

Example 4 with DatabaseVersion

use of tech.pegasys.teku.storage.server.DatabaseVersion 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);
    }
}
Also used : DatabaseMigraterError(tech.pegasys.teku.cli.util.DatabaseMigraterError) DatabaseVersion(tech.pegasys.teku.storage.server.DatabaseVersion) DatabaseMigrater(tech.pegasys.teku.cli.util.DatabaseMigrater)

Example 5 with DatabaseVersion

use of tech.pegasys.teku.storage.server.DatabaseVersion in project teku by ConsenSys.

the class DataOptionsTest method dataStorageCreateDbVersion_shouldDefault.

@Test
public void dataStorageCreateDbVersion_shouldDefault() {
    final StorageConfiguration config = getTekuConfigurationFromArguments().storageConfiguration();
    final DatabaseVersion expectedDefault = DatabaseVersion.isLevelDbSupported() ? DatabaseVersion.LEVELDB_TREE : DatabaseVersion.V5;
    assertThat(config.getDataStorageCreateDbVersion()).isEqualTo(expectedDefault);
}
Also used : StorageConfiguration(tech.pegasys.teku.services.chainstorage.StorageConfiguration) DatabaseVersion(tech.pegasys.teku.storage.server.DatabaseVersion) Test(org.junit.jupiter.api.Test) AbstractBeaconNodeCommandTest(tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)

Aggregations

DatabaseVersion (tech.pegasys.teku.storage.server.DatabaseVersion)5 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1 AbstractBeaconNodeCommandTest (tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)1 DatabaseMigrater (tech.pegasys.teku.cli.util.DatabaseMigrater)1 DatabaseMigraterError (tech.pegasys.teku.cli.util.DatabaseMigraterError)1 StorageConfiguration (tech.pegasys.teku.services.chainstorage.StorageConfiguration)1 StateStorageMode (tech.pegasys.teku.storage.server.StateStorageMode)1