Alex Petrov created CASSANDRA-21352:
---------------------------------------

             Summary: TCM: AtomicLongBackedProcessor sort inversion
                 Key: CASSANDRA-21352
                 URL: https://issues.apache.org/jira/browse/CASSANDRA-21352
             Project: Apache Cassandra
          Issue Type: Bug
            Reporter: Alex Petrov


{{needsSorting = entry.epoch.isDirectlyAfter(last)}} is inverted. It sets 
{{needsSorting=true}}¬ when entries are already in order (directly after = no 
sort needed) and leaves {{needsSorting=false}} when they arrive out of order. 
In-memory log produces non-deterministic epoch ordering in tests.

Repro:

{code}
/**
 * Epochs arrive out of order: 1, 3, 2.
 * With the bug, needsSorting is false for both 3 (not directly after 1) and 2 
(not directly after 3),
 * so no sort ever fires and the list stays [1, 3, 2].
 * After the fix (!isDirectlyAfter), both trigger a sort and the list becomes 
[1, 2, 3].
 */
@Test
public void outOfOrderAppendsAreSorted()
{
    InMemoryStorage storage = new InMemoryStorage();
    storage.append(entry(1));
    storage.append(entry(3)); // out of order — gap between 1 and 3
    storage.append(entry(2)); // fills the gap, but storage already has [1,3] 
unsorted by bug

    List<Entry> entries = storage.getLogState(Epoch.EMPTY).entries;
    assertEquals(3, entries.size());
    assertEquals("epoch 1 must be first",  Epoch.create(1), 
entries.get(0).epoch);
    assertEquals("epoch 2 must be second", Epoch.create(2), 
entries.get(1).epoch);
    assertEquals("epoch 3 must be third",  Epoch.create(3), 
entries.get(2).epoch);
}
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to