private static DatabaseMetadata tryReadAndMigrateV1(final File metadataFile) throws IOException {
    final V1 v1 = MAPPER.readValue(metadataFile, V1.class);
    // when migrating from v1, this version will automatically migrate the db to the variables
    // storage, so we use the `_WITH_VARIABLES` variants
    final VersionedStorageFormat versionedStorageFormat;
    versionedStorageFormat =
        switch (v1.version()) {
          case 1 -> BaseVersionedStorageFormat.FOREST_WITH_VARIABLES;
          case 2 -> BaseVersionedStorageFormat.BONSAI_WITH_VARIABLES;
          default -> throw new StorageException("Unsupported db version: " + v1.version());
        };

    final DatabaseMetadata metadataV2 = new DatabaseMetadata(versionedStorageFormat);
    // writing the metadata will migrate to v2
    metadataV2.writeToFile(metadataFile);
    return metadataV2;
  }
Write to directory.

@param dataDir the data dir
@throws IOException the io exception
plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/configuration/DatabaseMetadata.java