ifesdjeen commented on code in PR #144:
URL: https://github.com/apache/cassandra-accord/pull/144#discussion_r1861830004
##########
accord-core/src/main/java/accord/impl/InMemoryCommandStore.java:
##########
@@ -1377,99 +1375,86 @@ public void clearForTesting()
unsafeSetRejectBefore(new RejectBefore());
}
- public interface Loader
+ public Journal.Loader loader()
{
- void load(Command next);
- void apply(Command next);
+ return loader;
}
- public Loader loader()
+ private static class CommandLoader extends AbstractLoader
{
- return new Loader()
- {
- private PreLoadContext context(Command command, KeyHistory
keyHistory)
- {
- TxnId txnId = command.txnId();
- AbstractUnseekableKeys keys = null;
+ private final InMemoryCommandStore commandStore;
- if (CommandsForKey.manages(txnId))
- keys = (AbstractUnseekableKeys)
command.participants().hasTouched();
- else if (!CommandsForKey.managesExecution(txnId) &&
command.hasBeen(Status.Stable) && !command.hasBeen(Status.Truncated))
- keys = command.asCommitted().waitingOn.keys;
+ private CommandLoader(InMemoryCommandStore commandStore)
+ {
+ this.commandStore = commandStore;
+ }
- if (keys != null)
- {
- return PreLoadContext.contextFor(txnId, keys, keyHistory);
- }
+ private PreLoadContext context(Command command, KeyHistory keyHistory)
+ {
+ TxnId txnId = command.txnId();
+ AbstractUnseekableKeys keys = null;
- return PreLoadContext.contextFor(txnId);
- }
+ if (CommandsForKey.manages(txnId))
+ keys = (AbstractUnseekableKeys)
command.participants().hasTouched();
+ else if (!CommandsForKey.managesExecution(txnId) &&
command.hasBeen(Status.Stable) && !command.hasBeen(Status.Truncated))
+ keys = command.asCommitted().waitingOn.keys;
- public void load(Command command)
+ if (keys != null)
{
- TxnId txnId = command.txnId();
-
- executeInContext(InMemoryCommandStore.this,
- context(command, ASYNC),
- safeStore -> {
- Command local = command;
- if (local.status() != Truncated &&
local.status() != Invalidated)
- {
- Cleanup cleanup =
Cleanup.shouldCleanup(safeStore, local, local.participants());
- switch (cleanup)
- {
- case NO:
- break;
- case INVALIDATE:
- case TRUNCATE_WITH_OUTCOME:
- case TRUNCATE:
- case ERASE:
- local = Commands.purge(local,
local.participants(), cleanup);
- }
- }
-
- local =
safeStore.unsafeGet(txnId).update(safeStore, local);
- if (local.status() == Truncated)
-
safeStore.progressLog().clear(local.txnId());
- return local;
- });
+ return PreLoadContext.contextFor(txnId, keys, keyHistory);
+ }
+ return PreLoadContext.contextFor(txnId);
+ }
+ @Override
+ public void load(Command command, Journal.OnDone onDone)
+ {
+ try
+ {
+ commandStore.executeInContext(commandStore,
+ context(command, ASYNC),
+ safeStore ->
loadInternal(command, safeStore));
+ onDone.success();
Review Comment:
did that in both methods
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]