dcapwell commented on code in PR #3494:
URL: https://github.com/apache/cassandra/pull/3494#discussion_r1735213450
##########
src/java/org/apache/cassandra/service/accord/SavedCommand.java:
##########
@@ -73,536 +71,422 @@ private enum HasFields
LISTENERS
}
- public final TxnId txnId;
-
- public final Timestamp executeAt;
- public final SaveStatus saveStatus;
- public final Status.Durability durability;
-
- public final Ballot acceptedOrCommitted;
- public final Ballot promised;
-
- public final Route<?> route;
- public final PartialTxn partialTxn;
- public final PartialDeps partialDeps;
- public final Seekables<?, ?> additionalKeysOrRanges;
-
- public final Writes writes;
- public final Listeners.Immutable<Command.DurableAndIdempotentListener>
listeners;
+ public interface Writer<K> extends Journal.Writer
+ {
+ void write(DataOutputPlus out, int userVersion) throws IOException;
+ K key();
+ }
- public SavedCommand(TxnId txnId,
- Timestamp executeAt,
- SaveStatus saveStatus,
- Status.Durability durability,
+ public static class DiffWriter implements Writer<TxnId>
+ {
+ private final Command before;
+ private final Command after;
+ private final TxnId txnId;
- Ballot acceptedOrCommitted,
- Ballot promised,
+ public DiffWriter(Command before, Command after)
+ {
+ this(after.txnId(), before, after);
+ }
- Route<?> route,
- PartialTxn partialTxn,
- PartialDeps partialDeps,
- Seekables<?, ?> additionalKeysOrRanges,
+ public DiffWriter(TxnId txnId, Command before, Command after)
+ {
+ this.txnId = txnId;
+ this.before = before;
+ this.after = after;
+ }
- Writes writes,
-
Listeners.Immutable<Command.DurableAndIdempotentListener> listeners)
- {
- this.txnId = txnId;
- this.executeAt = executeAt;
- this.saveStatus = saveStatus;
- this.durability = durability;
+ @VisibleForTesting
+ public Command before()
+ {
+ return before;
+ }
- this.acceptedOrCommitted = acceptedOrCommitted;
- this.promised = promised;
+ @VisibleForTesting
+ public Command after()
+ {
+ return after;
+ }
- this.route = route;
- this.partialTxn = partialTxn;
- this.partialDeps = partialDeps;
- this.additionalKeysOrRanges = additionalKeysOrRanges;
+ public void write(DataOutputPlus out, int userVersion) throws
IOException
+ {
+ serialize(before, after, out, userVersion);
+ }
- this.writes = writes;
- this.listeners = listeners;
+ public TxnId key()
+ {
+ return txnId;
+ }
}
- public static SavedDiff diff(Command before, Command after)
- {
- if (before == after)
- return null;
- // TODO: we do not need to save `waitingOn` _every_ time.
- Command.WaitingOn waitingOn = getWaitingOn(after);
- return new SavedDiff(after.txnId(),
- ifNotEqual(before, after, Command::executeAt,
true),
- ifNotEqual(before, after, Command::saveStatus,
false),
- ifNotEqual(before, after, Command::durability,
false),
-
- ifNotEqual(before, after,
Command::acceptedOrCommitted, false),
- ifNotEqual(before, after, Command::promised,
false),
-
- ifNotEqual(before, after, Command::route, true),
- ifNotEqual(before, after, Command::partialTxn,
false),
- ifNotEqual(before, after, Command::partialDeps,
false),
- ifNotEqual(before, after,
Command::additionalKeysOrRanges, false),
-
- waitingOn,
- ifNotEqual(before, after, Command::writes, false),
- ifNotEqual(before, after,
Command::durableListeners, true));
- }
-
- static Command reconstructFromDiff(List<LoadedDiff> diffs)
+ public static Writer<TxnId> diffWriter(Command before, Command after)
{
- return reconstructFromDiff(diffs, CommandSerializers.APPLIED);
+ return new DiffWriter(before, after);
}
- /**
- * @param result is exposed because we are _not_ persisting result, since
during loading or replay
- * we do not expect we will have to send a result to the
client, and data results
- * can potentially contain a large number of entries, so
it's best if they are not
- * written into the log.
- */
- @VisibleForTesting
- static Command reconstructFromDiff(List<LoadedDiff> diffs, Result result)
+ public static void serialize(Command before, Command after, DataOutputPlus
out, int userVersion) throws IOException
{
- TxnId txnId = null;
-
- Timestamp executeAt = null;
- SaveStatus saveStatus = null;
- Status.Durability durability = null;
+ int flags = 0;
- Ballot acceptedOrCommitted = Ballot.ZERO;
- Ballot promised = null;
+ flags = collectFlags(before, after, Command::txnId, true,
Fields.TXN_ID, flags);
+ flags = collectFlags(before, after, Command::executeAt, true,
Fields.EXECUTE_AT, flags);
+ flags = collectFlags(before, after, Command::saveStatus, false,
Fields.SAVE_STATUS, flags);
+ flags = collectFlags(before, after, Command::durability, false,
Fields.DURABILITY, flags);
- Route<?> route = null;
- PartialTxn partialTxn = null;
- PartialDeps partialDeps = null;
- Seekables<?, ?> additionalKeysOrRanges = null;
+ flags = collectFlags(before, after, Command::acceptedOrCommitted,
false, Fields.ACCEPTED, flags);
+ flags = collectFlags(before, after, Command::promised, false,
Fields.PROMISED, flags);
- WaitingOnProvider waitingOnProvider = null;
- Writes writes = null;
- Listeners.Immutable listeners = null;
+ flags = collectFlags(before, after, Command::route, true,
Fields.ROUTE, flags);
+ flags = collectFlags(before, after, Command::partialTxn, false,
Fields.PARTIAL_TXN, flags);
+ flags = collectFlags(before, after, Command::partialDeps, false,
Fields.PARTIAL_DEPS, flags);
+ flags = collectFlags(before, after, Command::additionalKeysOrRanges,
false, Fields.ADDITIONAL_KEYS, flags);
- for (LoadedDiff diff : diffs)
+ Command.WaitingOn waitingOn = getWaitingOn(after);
+ if (waitingOn == null)
+ flags = setFieldIsNull(Fields.WAITING_ON, flags);
+ else
+ flags = setFieldChanged(Fields.WAITING_ON, flags);
Review Comment:
why not stay consistent and do `flags = collectFlags(before, after,
SavedCommand::getWaitingOn, false, Fields.WAITING_ON, flags);`?
--
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]