hpoenixf commented on code in PR #24278:
URL: https://github.com/apache/kafka/pull/24278#discussion_r4609978102


##########
streams/src/test/java/org/apache/kafka/streams/state/internals/TimeOrderedCachingPersistentWindowStoreTest.java:
##########
@@ -131,6 +133,84 @@ public void closeStore() {
         cachingStore.close();
     }
 
+    @ParameterizedTest
+    @ValueSource(booleans = {true, false})
+    public void 
shouldHandleOversizedRawPayloadReleasedDuringFlushAndSameKeyUpdates(final 
boolean hasIndex) {
+        setUp(hasIndex);
+        final List<byte[]> forwarded = new ArrayList<>();
+        cachingStore.setFlushListener(record -> {
+            forwarded.add(record.value().newValue);
+            context.recordContext().freeRawRecord();
+        }, true);
+        final Bytes key = bytesKey("key");
+        for (int i = 1; i <= 2; i++) {
+            context.setRecordContext(new 
ProcessorRecordContext(DEFAULT_TIMESTAMP, i, 0, TOPIC,
+                new RecordHeaders(), new byte[7], new 
byte[MAX_CACHE_SIZE_BYTES * 4]));
+            cachingStore.put(key, bytesValue("v" + i), DEFAULT_TIMESTAMP);
+            assertArrayEquals(bytesValue("v" + i), cachingStore.fetch(key, 
DEFAULT_TIMESTAMP));
+            assertTrue(cache.sizeBytes() >= 0 && cache.sizeBytes() <= 
MAX_CACHE_SIZE_BYTES);
+        }
+        cachingStore.commit(Map.of());
+        assertArrayEquals(bytesValue("v2"), underlyingStore.fetch(key, 
DEFAULT_TIMESTAMP));
+        assertFalse(forwarded.isEmpty());
+        assertArrayEquals(bytesValue("v2"), forwarded.get(forwarded.size() - 
1));
+        context.setRecordContext(new ProcessorRecordContext(DEFAULT_TIMESTAMP, 
3L, 0, TOPIC,
+            new RecordHeaders(), new byte[7], new byte[MAX_CACHE_SIZE_BYTES * 
4]));
+        cachingStore.put(key, null, DEFAULT_TIMESTAMP);
+        cachingStore.commit(Map.of());
+        assertNull(cachingStore.fetch(key, DEFAULT_TIMESTAMP));
+        assertNull(underlyingStore.fetch(key, DEFAULT_TIMESTAMP));
+        assertNull(forwarded.get(forwarded.size() - 1));
+        assertTrue(cache.evicts() > 0);
+        cachingStore.close();
+        assertEquals(0L, cache.sizeBytes());
+        assertEquals(0L, cache.size());
+    }
+
+    @ParameterizedTest
+    @ValueSource(booleans = {true, false})
+    public void 
shouldPreserveWindowResultsWithRawSourceBytesUnderSmallCacheBudget(final 
boolean hasIndex) {
+        setUp(hasIndex);
+        for (int i = 0; i < 8; i++) {
+            context.setRecordContext(new 
ProcessorRecordContext(DEFAULT_TIMESTAMP, i, 0, TOPIC,
+                new RecordHeaders(), new byte[7], new byte[128]));
+            cachingStore.put(bytesKey("k" + i), bytesValue("v" + i), 
DEFAULT_TIMESTAMP);
+            if (i == 0 && hasIndex) {

Review Comment:
   Addressed in 7a2ae22. The index `emptyEntry` now receives `null` for both 
raw key and value; only the base entry retains them. Updated the regression to 
check this. Also guarded index insertion when inserting the base has already 
flushed it, with indexed/non-indexed coverage to ensure a subsequent commit 
does not forward that base again.



-- 
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]

Reply via email to