From 49484ce6721cd140d0d8785cd7574b1fca62ae8d Mon Sep 17 00:00:00 2001 From: "Ameziane H." Date: Tue, 17 Dec 2024 15:11:50 +0100 Subject: [PATCH] Handle exception when options file is not found Signed-off-by: Ameziane H. --- .../RocksDBColumnarKeyValueStorage.java | 67 +++++++++---------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorage.java b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorage.java index 6142d76716b..aa508f085c1 100644 --- a/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorage.java +++ b/plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorage.java @@ -163,14 +163,7 @@ public RocksDBColumnarKeyValueStorage( .forEach(trimmedSegments::remove); columnDescriptors = trimmedSegments.stream() - .map( - segment -> { - try { - return createColumnDescriptor(segment, configuration); - } catch (RocksDBException e) { - throw new RuntimeException(e); - } - }) + .map(segment -> createColumnDescriptor(segment, configuration)) .collect(Collectors.toList()); setGlobalOptions(configuration, stats); @@ -191,37 +184,39 @@ public RocksDBColumnarKeyValueStorage( * @return a column family descriptor */ private ColumnFamilyDescriptor createColumnDescriptor( - final SegmentIdentifier segment, final RocksDBConfiguration configuration) - throws RocksDBException { - - ConfigOptions configOptions = new ConfigOptions(); - DBOptions dbOptions = new DBOptions(); - List cfDescriptors = new ArrayList<>(); - - String latestOptionsFileName = - OptionsUtil.getLatestOptionsFileName( - configuration.getDatabaseDir().toString(), Env.getDefault()); - LOG.trace("Latest OPTIONS file detected: " + latestOptionsFileName); - - String optionsFilePath = - configuration.getDatabaseDir().toString() + "/" + latestOptionsFileName; - OptionsUtil.loadOptionsFromFile(configOptions, optionsFilePath, dbOptions, cfDescriptors); - - LOG.trace("RocksDB options loaded successfully from: " + optionsFilePath); - + final SegmentIdentifier segment, final RocksDBConfiguration configuration) { boolean dynamicLevelBytes = true; - if (!cfDescriptors.isEmpty()) { - Optional matchedCfOptions = Optional.empty(); - for (ColumnFamilyDescriptor descriptor : cfDescriptors) { - if (Arrays.equals(descriptor.getName(), segment.getId())) { - matchedCfOptions = Optional.of(descriptor.getOptions()); - break; + try { + ConfigOptions configOptions = new ConfigOptions(); + DBOptions dbOptions = new DBOptions(); + List cfDescriptors = new ArrayList<>(); + + String latestOptionsFileName = + OptionsUtil.getLatestOptionsFileName( + configuration.getDatabaseDir().toString(), Env.getDefault()); + LOG.trace("Latest OPTIONS file detected: " + latestOptionsFileName); + + String optionsFilePath = + configuration.getDatabaseDir().toString() + "/" + latestOptionsFileName; + OptionsUtil.loadOptionsFromFile(configOptions, optionsFilePath, dbOptions, cfDescriptors); + + LOG.trace("RocksDB options loaded successfully from: " + optionsFilePath); + + if (!cfDescriptors.isEmpty()) { + Optional matchedCfOptions = Optional.empty(); + for (ColumnFamilyDescriptor descriptor : cfDescriptors) { + if (Arrays.equals(descriptor.getName(), segment.getId())) { + matchedCfOptions = Optional.of(descriptor.getOptions()); + break; + } + } + if (matchedCfOptions.isPresent()) { + dynamicLevelBytes = matchedCfOptions.get().levelCompactionDynamicLevelBytes(); + LOG.trace("dynamicLevelBytes is set to an existing value : " + dynamicLevelBytes); } } - if (matchedCfOptions.isPresent()) { - dynamicLevelBytes = matchedCfOptions.get().levelCompactionDynamicLevelBytes(); - LOG.trace("dynamicLevelBytes is set to an existing value : " + dynamicLevelBytes); - } + } catch (RocksDBException ex) { + // Options file is not found in the database } BlockBasedTableConfig basedTableConfig = createBlockBasedTableConfig(segment, configuration);