[minor] Improve message when existing database is different from the configuration (#6534)

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
pull/6539/head
Gabriel-Trintinalia 10 months ago committed by GitHub
parent c45a863280
commit 559fe71cf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/worldstate/DataStorageFormat.java
  2. 9
      plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBKeyValueStorageFactory.java
  3. 20
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBKeyValueStorageFactoryTest.java

@ -29,4 +29,13 @@ public enum DataStorageFormat {
public int getDatabaseVersion() {
return databaseVersion;
}
public static String getName(final int databaseVersion) {
for (DataStorageFormat format : DataStorageFormat.values()) {
if (format.getDatabaseVersion() == databaseVersion) {
return format.name();
}
}
return "Unknown";
}
}

@ -261,8 +261,13 @@ public class RocksDBKeyValueStorageFactory implements KeyValueStorageFactory {
if (databaseVersion != commonConfiguration.getDatabaseVersion()) {
String error =
String.format(
"Mismatch detected: Database at %s is version '%s', but configuration expects version '%s'.",
dataDir, databaseVersion, commonConfiguration.getDatabaseVersion());
"Mismatch: DB at %s is %s (Version %s) but config expects %s (Version %s). Please check your config.",
dataDir,
DataStorageFormat.getName(databaseVersion),
databaseVersion,
DataStorageFormat.getName(commonConfiguration.getDatabaseVersion()),
commonConfiguration.getDatabaseVersion());
throw new StorageException(error);
}
LOG.info(

@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.BesuConfiguration;
@ -152,8 +153,8 @@ public class RocksDBKeyValueStorageFactoryTest {
public void shouldThrowExceptionWhenExistingDatabaseVersionDifferentFromConfig()
throws Exception {
final int actualDatabaseVersion = 1;
final int expectedDatabaseVersion = 2;
final int actualDatabaseVersion = DataStorageFormat.FOREST.getDatabaseVersion();
final int expectedDatabaseVersion = DataStorageFormat.BONSAI.getDatabaseVersion();
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
@ -163,6 +164,16 @@ public class RocksDBKeyValueStorageFactoryTest {
when(commonConfiguration.getDatabaseVersion()).thenReturn(expectedDatabaseVersion);
new DatabaseMetadata(actualDatabaseVersion).writeToDirectory(tempDataDir);
String exceptionMessage =
String.format(
"Mismatch: DB at %s is %s (Version %s) but config expects %s (Version %s). Please check your config.",
tempDataDir.toAbsolutePath(),
DataStorageFormat.getName(actualDatabaseVersion),
actualDatabaseVersion,
DataStorageFormat.getName(expectedDatabaseVersion),
expectedDatabaseVersion);
assertThatThrownBy(
() ->
new RocksDBKeyValueStorageFactory(
@ -171,10 +182,7 @@ public class RocksDBKeyValueStorageFactoryTest {
RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS)
.create(segment, commonConfiguration, metricsSystem))
.isInstanceOf(StorageException.class)
.hasMessage(
String.format(
"Mismatch detected: Database at %s is version '%s', but configuration expects version '%s'.",
tempDataDir.toAbsolutePath(), actualDatabaseVersion, expectedDatabaseVersion));
.hasMessage(exceptionMessage);
}
@Test

Loading…
Cancel
Save