belliottsmith commented on code in PR #168:
URL: https://github.com/apache/cassandra-accord/pull/168#discussion_r1957105677
##########
accord-core/src/main/java/accord/impl/CommandChange.java:
##########
@@ -264,84 +271,53 @@ public Cleanup shouldCleanup(Input input, Agent agent,
RedundantBefore redundant
return cleanup;
}
- public Builder maybeCleanup(Cleanup cleanup)
+ public boolean maybeCleanup(Input input, Agent agent, RedundantBefore
redundantBefore, DurableBefore durableBefore)
{
- if (saveStatus == null)
- return this;
-
- switch (cleanup)
- {
- case EXPUNGE:
- case ERASE:
- return null;
-
- case VESTIGIAL:
- case INVALIDATE:
- return saveStatusOnly();
-
- case TRUNCATE_WITH_OUTCOME:
- case TRUNCATE:
- return expungePartial(cleanup, cleanup.appliesIfNot,
cleanup == TRUNCATE_WITH_OUTCOME);
-
- case NO:
- return this;
- default:
- throw new UnhandledEnum(cleanup);
- }
+ Cleanup cleanup = shouldCleanup(input, agent, redundantBefore,
durableBefore);
+ return maybeCleanup(cleanup);
}
- public Builder expungePartial(Cleanup cleanup, SaveStatus saveStatus,
boolean includeOutcome)
+ public boolean maybeCleanup(Cleanup cleanup)
{
- Invariants.require(txnId != null);
- Builder builder = new Builder(txnId, ALL);
+ if (saveStatus == null)
+ return false;
- builder.count++;
- builder.nextCalled = true;
+ cleanup = cleanup.filter(saveStatus);
+ if (cleanup == NO)
+ return false;
- Invariants.require(saveStatus != null);
- builder.flags = setChanged(SAVE_STATUS, builder.flags);
- builder.saveStatus = saveStatus;
- builder.flags = setChanged(CLEANUP, builder.flags);
- builder.cleanup = cleanup;
- if (executeAt != null)
- {
- builder.flags = setChanged(EXECUTE_AT, builder.flags);
- builder.executeAt = executeAt;
- }
- if (durability != null)
- {
- builder.flags = setChanged(DURABILITY, builder.flags);
- builder.durability = durability;
- }
- if (participants != null)
- {
- builder.flags = setChanged(PARTICIPANTS, builder.flags);
- builder.participants = participants;
- }
- if (includeOutcome && builder.writes != null)
- {
- builder.flags = setChanged(WRITES, builder.flags);
- builder.writes = writes;
- }
-
- return builder;
+ truncate(cleanup.appliesIfNot);
+ return true;
}
- public Builder saveStatusOnly()
+ protected void truncate(SaveStatus newSaveStatus)
{
- Invariants.require(txnId != null);
- Builder builder = new Builder(txnId, ALL);
-
- builder.count++;
- builder.nextCalled = true;
-
- if (saveStatus != null)
+ int mask = saveStatusMasks[newSaveStatus.ordinal()];
+ // low flag bits represent fields already nulled out, so no need
to visit them again
+ int iterable = toIterableSetFields(mask) & ~flags;
+ for (Field next = nextSetField(iterable); next != null; iterable =
unsetIterable(next, iterable), next = nextSetField(iterable))
{
- builder.flags = setChanged(SAVE_STATUS, builder.flags);
- builder.saveStatus = saveStatus;
+ switch (next)
+ {
+ default: throw new UnhandledEnum(next);
+ case PARTICIPANTS: participants = null;
break;
Review Comment:
I like the idea, but I think I would want to double check hotspot does the
sensible thing and collapses that into direct field updates, else we could do a
lot of wasted work.
--
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]