belliottsmith commented on code in PR #176:
URL: https://github.com/apache/cassandra-accord/pull/176#discussion_r1977161427


##########
accord-core/src/test/java/accord/impl/basic/InMemoryJournal.java:
##########
@@ -308,29 +325,77 @@ public void purge(CommandStores commandStores)
             {
                 List<Diff> diffs = e2.getValue();
                 if (diffs.isEmpty()) continue;
+                if (isPartialCompaction)
+                {
+                    List<Diff> copy = new ArrayList<>();
+                    int tmp1 = random.nextInt(diffs.size());
+                    int tmp2 = random.nextInt(diffs.size());
+                    int min = Math.min(tmp1, tmp2);
+                    int max = Math.max(tmp1, tmp2);
+                    for (int i = min; i < max; i++)
+                        copy.add(diffs.get(i));
+
+                    if (copy.isEmpty())
+                        continue;
+                    diffs = copy;
+                }
                 InMemoryJournal.Builder builder = reconstruct(diffs, ALL);
+                if (builder.saveStatus() == null)
+                    continue; // Partial compaction, no save status present
+
                 if (builder.saveStatus().status == Truncated || 
builder.saveStatus().status == Invalidated)
                     continue; // Already truncated
 
-                Command command = 
builder.construct(store.unsafeGetRedundantBefore());
-                Cleanup cleanup = Cleanup.shouldCleanup(FULL, store.agent(), 
command, store.unsafeGetRedundantBefore(), store.durableBefore());
-                switch (cleanup)
+                Input input = isPartialCompaction ? PARTIAL : FULL;
+                Cleanup cleanup = shouldCleanup(input,
+                                                store.agent(),
+                                                builder.txnId(),
+                                                builder.executeAt(),
+                                                builder.saveStatus(),
+                                                builder.durability(),
+                                                builder.participants(),
+                                                
store.unsafeGetRedundantBefore(),
+                                                store.durableBefore());
+
+                if (builder.maybeCleanup(input, cleanup))
                 {
-                    case NO:
-                        break;
-                    case INVALIDATE:
-                    case TRUNCATE_WITH_OUTCOME:
-                    case TRUNCATE:
-                    case ERASE:
-                        command = Commands.purgeUnsafe(store, command, 
cleanup);
-                        Invariants.require(command.saveStatus() != 
SaveStatus.Uninitialised);
-                        Diff diff = toDiff(new CommandUpdate(null, command));
-                        e2.setValue(cleanup == Cleanup.ERASE ? new 
ErasedList(diff) : new TruncatedList(diff));
-                        break;
-
-                    case EXPUNGE:
-                        e2.setValue(new PurgedList(e2.getValue()));
-                        break;
+                    Invariants.require(cleanup != NO);
+                    if (cleanup == EXPUNGE)
+                        e2.setValue(new PurgedList());
+                    else
+                    {
+                        int flags = 
CommandChange.flagsForPurge(cleanup.appliesIfNot);
+                        EnumMap<Field, Object> values = new 
EnumMap<>(Field.class);
+                        for (Field field : Field.values())

Review Comment:
   ```suggestion
                           int iterator = toIterableSetFields(~flags);
                           for (Field field = nextSetField(iterator); field != 
null; iterator = unsetIterable(field, iterator), field = nextSetField(iterator))
                           {
                               if (field == CLEANUP || field == SAVE_STATUS)
                                   continue;
   ```



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to