Skip to content

Commit

Permalink
Merge pull request #3342 from ingef/fix/storage-dump
Browse files Browse the repository at this point in the history
Use java.nio.file.Files::createDirectories to create the dumpfile parent
  • Loading branch information
awildturtok authored Mar 12, 2024
2 parents 378ff5c + 36247df commit ebb55a8
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
Expand Down Expand Up @@ -276,7 +277,7 @@ private VALUE readValue(ByteIterable value) {
}

/**
* Dumps the content of an unreadable value to a file as a json (it tries to parse it as an object and than tries to dump it as a json).
* Dumps the content of an unreadable value to a file as a json (it tries to parse it as an object and then tries to dump it as a json).
*
* @param gzippedObj The object to dump.
* @param keyOfDump The key under which the unreadable value is accessible. It is used for the file name.
Expand All @@ -294,9 +295,17 @@ private static void dumpToFile(byte[] gzippedObj, @NonNull String keyOfDump, Exc
return;
}

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()));
try {
// This will create all necessary parent directories.
Files.createDirectories(dumpfile.toPath().getParent());

// Should be a redundant check, due to the above reasoning
if (!dumpfile.getParentFile().exists()) {
throw new IllegalStateException("Could not create `%s`.".formatted(dumpfile.getParentFile()));
}
}
catch (IOException e) {
log.warn("Could not create `{}`", dumpfile.getParentFile(), e);
}

// Write json
Expand Down Expand Up @@ -351,7 +360,7 @@ private static byte[] debugUnGzip(byte[] bytes) throws IOException {

/**
* Iterates a given consumer over the entries of this store.
* Depending on the {@link XodusStoreFactory} corrupt entries may be dump to a file and/or removed from the store.
* Depending on the {@link XodusStoreFactory} corrupt entries may be dumped to a file and/or removed from the store.
* These entries are not submitted to the consumer.
*
* @implNote This method is concurrent!
Expand Down Expand Up @@ -420,7 +429,8 @@ private ByteIterable handle(StoreEntryConsumer<KEY, VALUE> consumer, IterationSt
result.incrTotalProcessed();

// Try to read the key first
key = getDeserializedAndDumpFailed(keyRaw, SerializingStore.this::readKey, () -> new String(keyRaw.getBytesUnsafe()), valueRaw, "Could not parse key [{}]");
key =
getDeserializedAndDumpFailed(keyRaw, SerializingStore.this::readKey, () -> new String(keyRaw.getBytesUnsafe()), valueRaw, "Could not parse key [{}]");
if (key == null) {
result.incrFailedKeys();
return keyRaw;
Expand All @@ -433,7 +443,8 @@ private ByteIterable handle(StoreEntryConsumer<KEY, VALUE> consumer, IterationSt
result.incrFailedValues();
return keyRaw;
}
}catch(Exception e){
}
catch (Exception e) {
log.error("Failed processing key/value", e);
return keyRaw;
}
Expand Down

0 comments on commit ebb55a8

Please sign in to comment.