belliottsmith commented on code in PR #158:
URL: https://github.com/apache/cassandra-accord/pull/158#discussion_r1925871369
##########
accord-core/src/main/java/accord/impl/CommandChange.java:
##########
@@ -503,41 +523,48 @@ public static int getFlags(Command before, Command after)
flags = collectFlags(before, after, Command::participants, true,
PARTICIPANTS, flags);
flags = collectFlags(before, after, Command::partialTxn, false,
PARTIAL_TXN, flags);
flags = collectFlags(before, after, Command::partialDeps, false,
PARTIAL_DEPS, flags);
-
- // TODO: waitingOn vs WaitingOnWithExecutedAt?
- flags = collectFlags(before, after, CommandChange::getWaitingOn, true,
WAITING_ON, flags);
+ flags = collectFlags(before, after, Command::waitingOn,
WaitingOn::equalBitSets, true, WAITING_ON, flags);
flags = collectFlags(before, after, Command::writes, false, WRITES,
flags);
flags = collectFlags(before, after, Command::result, false, RESULT,
flags);
+ // make sure we have enough information to decide whether to expunge
timestamps (for unique ApplyAt HLC guarantees)
+ if (isChanged(EXECUTE_AT, flags) &&
after.saveStatus().known.is(ApplyAtKnown))
+ {
+ flags = setChanged(PARTICIPANTS, flags);
+ flags = setChanged(SAVE_STATUS, flags);
+ }
return flags;
}
private static <OBJ, VAL> int collectFlags(OBJ lo, OBJ ro, Function<OBJ,
VAL> convert, boolean allowClassMismatch, Field field, int flags)
+ {
+ return collectFlags(lo, ro, convert, Object::equals,
allowClassMismatch, field, flags);
+ }
+
+ private static <OBJ, VAL> int collectFlags(OBJ lo, OBJ ro, Function<OBJ,
VAL> convert, BiPredicate<VAL, VAL> equals, boolean allowClassMismatch, Field
field, int flags)
{
VAL l = null;
VAL r = null;
if (lo != null) l = convert.apply(lo);
if (ro != null) r = convert.apply(ro);
- if (l == r)
- return flags; // no change
-
- if (r == null)
- flags = setFieldIsNull(field, flags);
-
- if (l == null || r == null)
- return setFieldChanged(field, flags);
-
- assert allowClassMismatch || l.getClass() == r.getClass() :
String.format("%s != %s", l.getClass(), r.getClass());
-
- if (l.equals(r))
- return flags; // no change
+ if (l == r) return flags; // no change
+ if (r == null) return setFieldIsNullAndChanged(field, flags);
+ if (l == null) return setChanged(field, flags);
+ Invariants.checkState(allowClassMismatch || l.getClass() ==
r.getClass(), "%s != %s", l.getClass(), r.getClass());
+ if (equals.test(l, r)) return flags; // no change
+ return setChanged(field, flags);
+ }
- return setFieldChanged(field, flags);
+ private static <OBJ> int collectFlags(OBJ lo, OBJ ro, ToLongFunction<OBJ>
convert, Field field, int flags)
+ {
+ long l = 0, r = 0;
+ if (lo != null) l = convert.applyAsLong(lo);
+ if (ro != null) r = convert.applyAsLong(ro);
+ return l == r ? flags : r == 0 ? setFieldIsNullAndChanged(field,
flags) : setChanged(field, flags);
Review Comment:
I've opted to update the formatting. I'm not a huge fan of mixing return
types, particularly at this level of one of each kind. I would be OK with
switching to three return statements if you prefer though.
--
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]