Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion accord-core/src/main/java/accord/local/CommandStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ private static <T extends Timestamp> ImmutableSortedMap<T, Ranges> purgeAndInser
return ImmutableSortedMap.copyOf(build);
}

private static ImmutableSortedMap<Timestamp, Ranges> purgeHistory(NavigableMap<Timestamp, Ranges> in, Ranges remove)
protected static ImmutableSortedMap<Timestamp, Ranges> purgeHistory(NavigableMap<Timestamp, Ranges> in, Ranges remove)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be package private.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think setting it to package private means that we can't access it from CommandStores.

{
return ImmutableSortedMap.copyOf(purgeHistoryIterator(in, remove));
}
Expand Down
20 changes: 20 additions & 0 deletions accord-core/src/main/java/accord/local/CommandStores.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -82,6 +83,7 @@
import org.agrona.collections.Int2IntHashMap;
import org.agrona.collections.Int2ObjectHashMap;

import static accord.local.CommandStore.purgeHistory;
import static accord.topology.EpochReady.done;
import static accord.api.DataStore.FetchKind.Sync;
import static accord.local.CommandStores.BootstrapRangeAction.BOOTSTRAP_NOT_NEEDED;
Expand Down Expand Up @@ -1121,4 +1123,22 @@ protected Snapshot current()
{
return current;
}

public AsyncResult<List<Ranges>> getInUseRangesAndMarkRetiredRangesUnsafeToRead()
{
List<AsyncResult<Ranges>> results = new ArrayList<>();
Snapshot snapshot = current;
for (ShardHolder shard : snapshot.shards)
results.add(shard.store.submit((PreLoadContext.Empty) () -> "Get not retired ranges and mark retired ranges unsafe to read",
safeCommandStore -> {
Ranges notRetiredRanges = shard.ranges().notRetired(safeCommandStore);
Ranges retired = shard.ranges().all().without(notRetiredRanges);
NavigableMap<Timestamp, Ranges> safeToReadAt = safeCommandStore.safeToReadAt();
if (safeToReadAt.values().stream().anyMatch(r -> r.intersects(retired)))
safeCommandStore.setSafeToRead(purgeHistory(safeToReadAt, retired));
return notRetiredRanges;
}));

return AsyncResults.allOf(results);
}
}