Skip to content

Commit

Permalink
merge: #12666
Browse files Browse the repository at this point in the history
12666: [Backport stable/8.2] refactor(snapshots): Replace `Stream.toList` and the for each cycle to `Stream.forEachOrdered` r=deepthidevaki a=backport-action

# Description
Backport of #12576 to `stable/8.2`.

relates to #12575

Co-authored-by: Alexey Vinogradov <vinogradov.a.i.93@gmail.com>
  • Loading branch information
zeebe-bors-camunda[bot] and aivinog1 committed May 4, 2023
2 parents 8528306 + b26c2a9 commit 7b117ad
Showing 1 changed file with 12 additions and 6 deletions.
Expand Up @@ -9,9 +9,10 @@

import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;

final class SnapshotChecksum {

Expand All @@ -38,7 +39,7 @@ public static SfvChecksum read(final Path checksumPath) throws IOException {
public static SfvChecksum calculate(final Path snapshotDirectory) throws IOException {
try (final var fileStream =
Files.list(snapshotDirectory).filter(SnapshotChecksum::isNotMetadataFile).sorted()) {
final SfvChecksum sfvChecksum = createCombinedChecksum(fileStream.toList());
final SfvChecksum sfvChecksum = createCombinedChecksum(fileStream);

// While persisting transient snapshot, the checksum of metadata file is added at the end.
// Hence when we recalculate the checksum, we must follow the same order. Otherwise base on
Expand Down Expand Up @@ -70,11 +71,16 @@ public static void persist(final Path checksumPath, final SfvChecksum checksum)
*
* @return the SfvChecksum object
*/
private static SfvChecksum createCombinedChecksum(final List<Path> files) throws IOException {
private static SfvChecksum createCombinedChecksum(final Stream<Path> files) {
final SfvChecksum checksum = new SfvChecksum();
for (final var f : files) {
checksum.updateFromFile(f);
}
files.forEachOrdered(
path -> {
try {
checksum.updateFromFile(path);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
return checksum;
}
}

0 comments on commit 7b117ad

Please sign in to comment.