Ensure that the Provenance Repository doesn't delete the Active Event File
@@ -481,6 +481,10 @@ public class WriteAheadStorePartition implements EventStorePartition {
.forEach(this::delete);
}
+ private File getActiveEventFile() {
+ final RecordWriterLease lease = eventWriterLeaseRef.get();
+ return lease == null ? null : lease.getWriter().getFile();
+ }
@Override
public long purgeOldestEvents() {
@@ -489,8 +493,7 @@ public class WriteAheadStorePartition implements EventStorePartition {
return 0L;
}
- final RecordWriterLease lease = eventWriterLeaseRef.get();
- final File currentFile = lease == null ? null : lease.getWriter().getFile();
+ final File currentFile = getActiveEventFile();
for (final File eventFile : eventFiles) {
if (eventFile.equals(currentFile)) {
continue;
@@ -511,6 +514,12 @@ public class WriteAheadStorePartition implements EventStorePartition {
}
private boolean delete(final File file) {
+ final File activeEventFile = getActiveEventFile();
+ if (file.equals(activeEventFile)) {
+ logger.debug("Attempting to age off Active Event File {}. Will return without deleting the file.", file);
+ return false;
+ }
+
final long firstEventId = DirectoryUtils.getMinId(file);
synchronized (minEventIdToPathMap) {
minEventIdToPathMap.remove(firstEventId);
