Skip to content

Commit

Permalink
fixes handling of errors inside Futures
Browse files Browse the repository at this point in the history
  • Loading branch information
awildturtok committed Sep 5, 2023
1 parent 94b1ca4 commit 2286fe8
Showing 1 changed file with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ private static void dumpToFile(byte[] gzippedObj, @NonNull String keyOfDump, Exc
}

if (!dumpfile.getParentFile().exists() && !dumpfile.getParentFile().mkdirs()) {
//TODO this seems to occur sometimes, is it maybe just a race condition?
throw new IllegalStateException("Could not create `%s`.".formatted(dumpfile.getParentFile()));
}

Expand Down Expand Up @@ -412,24 +413,28 @@ public IterationStatistic forEach(StoreEntryConsumer<KEY, VALUE> consumer) {
}

private ByteIterable handle(StoreEntryConsumer<KEY, VALUE> consumer, IterationStatistic result, ByteIterable keyRaw, ByteIterable valueRaw) {
result.incrTotalProcessed();

// Try to read the key first
final KEY
key =
getDeserializedAndDumpFailed(keyRaw, SerializingStore.this::readKey, () -> new String(keyRaw.getBytesUnsafe()), valueRaw, "Could not parse key [{}]");
if (key == null) {
result.incrFailedKeys();
return keyRaw;
}
final KEY key;
final VALUE value;

// Try to read the value
final VALUE
value =
getDeserializedAndDumpFailed(valueRaw, SerializingStore.this::readValue, key::toString, valueRaw, "Could not parse value for key [{}]");
try {
result.incrTotalProcessed();

if (value == null) {
result.incrFailedValues();
// Try to read the key first
key = getDeserializedAndDumpFailed(keyRaw, SerializingStore.this::readKey, () -> new String(keyRaw.getBytesUnsafe()), valueRaw, "Could not parse key [{}]");
if (key == null) {
result.incrFailedKeys();
return keyRaw;
}

// Try to read the value
value = getDeserializedAndDumpFailed(valueRaw, SerializingStore.this::readValue, key::toString, valueRaw, "Could not parse value for key [{}]");

if (value == null) {
result.incrFailedValues();
return keyRaw;
}
}catch(Exception e){
log.error("Failed processing key/value", e);
return keyRaw;
}

Expand Down

0 comments on commit 2286fe8

Please sign in to comment.