Skip to content

Commit

Permalink
parse rocksdb error for unprintable column family id's
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Aug 30, 2023
1 parent e3b0112 commit 8274fe3
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import static java.util.stream.Collectors.toUnmodifiableSet;

import com.google.common.base.Splitter;
import com.google.common.collect.Streams;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.metrics.OperationTimer;
Expand All @@ -31,6 +34,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -161,7 +165,42 @@ public RocksDBColumnarKeyValueStorage(
txOptions = new TransactionDBOptions();
columnHandles = new ArrayList<>(columnDescriptors.size());
} catch (RocksDBException e) {
throw new StorageException(e);
List<SegmentIdentifier> knownSegments = Streams.concat(
defaultSegments.stream(),
ignorableSegments.stream())
.distinct()
.toList();
throw parseRocksDBException(e, knownSegments);
}
}

private static StorageException parseRocksDBException(
final RocksDBException ex,
final List<SegmentIdentifier> knownSegments) {
String message = ex.getMessage();

// parse out unprintable segment names for a more useful exception:
String columnExceptionMessagePrefix = "Column families not opened: ";
if (message.contains(columnExceptionMessagePrefix)) {
String substring = message.substring(message.indexOf(": ") + 2);

List<String> unHandledSegments = new ArrayList<>();
Splitter.on(", ").splitToStream(substring)
.forEach(part -> {
byte[] bytes = part.getBytes(StandardCharsets.UTF_8);
unHandledSegments.add(
knownSegments.stream().filter(seg -> Arrays.equals(seg.getId(), bytes))
.findFirst()
.map(SegmentIdentifier::getName)
.orElse("unknown segment:{" + Bytes.of(bytes).toHexString() + "}"));

});

return new StorageException(
"RocksDBException: Unhandled column families: [" +
unHandledSegments.stream().collect(Collectors.joining(", ")) + "]");
} else {
return new StorageException(ex);
}
}

Expand Down

0 comments on commit 8274fe3

Please sign in to comment.