bbejeck commented on code in PR #23144:
URL: https://github.com/apache/kafka/pull/23144#discussion_r3785906747
##########
streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java:
##########
@@ -1664,6 +1664,125 @@ public void
offsetColumnFamilyWritesShouldNotLeakIntoDataIteration() {
}
}
+ @Test
+ public void putAllShouldStageWritesUntilCommitWhenTransactional() {
+ rocksDBStore.close();
+ final InternalMockProcessorContext<?, ?> eosContext =
getTransactionalEOSProcessorContext(dir);
+ rocksDBStore = getRocksDBStore();
+ rocksDBStore.init(eosContext, rocksDBStore);
+
+ // An empty RocksDB WriteBatch already reports a fixed header size, so
the baseline is non-zero.
+ final long emptyBufferBytes =
rocksDBStore.approximateNumUncommittedBytes();
+
+ final Bytes k1 = new Bytes(stringSerializer.serialize(null, "k1"));
+ final Bytes k2 = new Bytes(stringSerializer.serialize(null, "k2"));
+ rocksDBStore.putAll(List.of(
+ KeyValue.pair(k1, stringSerializer.serialize(null, "v1")),
+ KeyValue.pair(k2, stringSerializer.serialize(null, "v2"))));
+
+ final ReadOnlyKeyValueStore<Bytes, byte[]> uncommitted =
rocksDBStore.readOnly(IsolationLevel.READ_UNCOMMITTED);
+ final ReadOnlyKeyValueStore<Bytes, byte[]> committed =
rocksDBStore.readOnly(IsolationLevel.READ_COMMITTED);
+
+ // the batch is staged rather than written: it counts towards the
uncommitted byte total ...
+ assertTrue(rocksDBStore.approximateNumUncommittedBytes() >
emptyBufferBytes);
+ // ... is visible to the owner and at READ_UNCOMMITTED ...
+ assertEquals("v1", stringDeserializer.deserialize(null,
rocksDBStore.get(k1)));
+ assertEquals("v2", stringDeserializer.deserialize(null,
uncommitted.get(k2)));
+ // ... and stays hidden at READ_COMMITTED until the store commits.
+ assertNull(committed.get(k1));
+ assertNull(committed.get(k2));
+
+ rocksDBStore.commit(Map.of());
+
+ assertEquals("v1", stringDeserializer.deserialize(null,
committed.get(k1)));
+ assertEquals("v2", stringDeserializer.deserialize(null,
committed.get(k2)));
+ }
+
+ @Test
+ public void putAllShouldBeDiscardedOnRollbackWhenTransactional() {
+ rocksDBStore.close();
+ final InternalMockProcessorContext<?, ?> eosContext =
getTransactionalEOSProcessorContext(dir);
+ rocksDBStore = getRocksDBStore();
+ rocksDBStore.init(eosContext, rocksDBStore);
+
+ final Bytes k1 = new Bytes(stringSerializer.serialize(null, "k1"));
+ final Bytes k2 = new Bytes(stringSerializer.serialize(null, "k2"));
+ rocksDBStore.put(k1, stringSerializer.serialize(null, "committed"));
+ rocksDBStore.commit(Map.of());
+
+ rocksDBStore.putAll(List.of(
+ KeyValue.pair(k1, stringSerializer.serialize(null, "rolled-back")),
+ KeyValue.pair(k2, stringSerializer.serialize(null,
"rolled-back"))));
+ rocksDBStore.dbAccessor.rollbackStagedWrites();
+
+ // an aborted batch must leave nothing behind: the committed value is
intact and the new key is gone
+ assertEquals("committed", stringDeserializer.deserialize(null,
rocksDBStore.get(k1)));
+ assertNull(rocksDBStore.get(k2));
+ assertEquals("committed", stringDeserializer.deserialize(null,
+ rocksDBStore.readOnly(IsolationLevel.READ_COMMITTED).get(k1)));
+
assertNull(rocksDBStore.readOnly(IsolationLevel.READ_COMMITTED).get(k2));
Review Comment:
updated the test
--
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]