Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/main/java/com/uid2/admin/store/writer/SaltStoreWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -48,23 +48,27 @@ protected List<RotatingSaltProvider.SaltSnapshot> getSnapshots(RotatingSaltProvi
throw new IllegalStateException("Snapshots cannot be null");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
final Instant now = Instant.now();
List<RotatingSaltProvider.SaltSnapshot> currentSnapshots = Stream.concat(provider.getSnapshots().stream(), Stream.of(data))
List<RotatingSaltProvider.SaltSnapshot> currentSnapshots = provider.getSnapshots();
List<RotatingSaltProvider.SaltSnapshot> snapshots = null;
snapshots = Stream.concat(currentSnapshots.stream(), Stream.of(data))
.sorted(Comparator.comparing(RotatingSaltProvider.SaltSnapshot::getEffective))
.collect(Collectors.toList());
RotatingSaltProvider.SaltSnapshot newestEffectiveSnapshot = currentSnapshots.stream()
RotatingSaltProvider.SaltSnapshot newestEffectiveSnapshot = snapshots.stream()
.filter(snapshot -> snapshot.isEffective(now))
.reduce((a, b) -> b).orElse(null);
return Stream.concat(provider.getSnapshots().stream(), Stream.of(data))
.filter(snapshot -> {
boolean isValid = newestEffectiveSnapshot == null || snapshot == newestEffectiveSnapshot;
if (!isValid) {

List<RotatingSaltProvider.SaltSnapshot> filteredSnapshots = new ArrayList<>();

for (RotatingSaltProvider.SaltSnapshot snapshot : snapshots) {
if (newestEffectiveSnapshot != null && snapshot != newestEffectiveSnapshot) {
LOGGER.info("Skipping effective snapshot, effective=" + snapshot.getEffective() + ", expires=" + snapshot.getExpires()
+ " in favour of newer snapshot, effective=" + newestEffectiveSnapshot.getEffective() + ", expires=" + newestEffectiveSnapshot.getExpires());
}
return isValid;
})
.sorted(Comparator.comparing(RotatingSaltProvider.SaltSnapshot::getEffective))
.collect(Collectors.toList());
continue;
}
filteredSnapshots.add(snapshot);
newestEffectiveSnapshot = null;
}
return filteredSnapshots;
}

public void upload(RotatingSaltProvider.SaltSnapshot data) throws Exception {
Expand Down