mjsax commented on code in PR #22165:
URL: https://github.com/apache/kafka/pull/22165#discussion_r3653581797


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/InMemoryTimeOrderedKeyValueChangeBuffer.java:
##########
@@ -465,28 +513,165 @@ private byte[] internalPriorValueForBuffered(final Bytes 
key) {
         }
     }
 
+    // The legacy V0/V1 restore paths feed the currently-buffered prior value 
back in as plain value
+    // bytes, so unwrap it when the in-memory encoding is the headers-aware 
format.
+    private byte[] plainPriorValueForBuffered(final Bytes key) {
+        final byte[] priorValue = internalPriorValueForBuffered(key);
+        return storeHeaders ? unwrapHeadersFormatToPlainValue(priorValue) : 
priorValue;
+    }
+
+    // Normalizes a restored buffer value so its value parts match the 
encoding currently used
+    // in-memory (ValueTimestampHeaders blobs when header stores are enabled, 
plain values otherwise),
+    // regardless of the changelog version it was read from.
+    private BufferValue normalizeEncoding(final BufferValue value, final 
boolean restoredWithHeaders) {
+        if (storeHeaders == restoredWithHeaders) {
+            return value;
+        }
+        if (storeHeaders) {
+            // Plain -> ValueTimestampHeaders. The original headers/timestamp 
of legacy records are
+            // unknown, so we use empty headers and the record-context 
timestamp.
+            final long timestamp = value.context().timestamp();
+            return new BufferValue(
+                wrapPlainValueAsHeadersFormat(value.priorValue(), timestamp),
+                wrapPlainValueAsHeadersFormat(value.oldValue(), timestamp),
+                wrapPlainValueAsHeadersFormat(value.newValue(), timestamp),
+                value.context()
+            );
+        }
+        // ValueTimestampHeaders -> plain would drop the per-value 
headers/timestamps carried by a V4
+        // changelog. This only arises when a store that previously used a 
headers store format is
+        // restored without one, i.e. a store-format downgrade. Downgrades are 
not supported, so we
+        // fail fast here rather than silently discarding the stored header 
data.
+        throw new StreamsException(

Review Comment:
   We don't support rolling bounce downgrade, but a downgrade via app shutdown 
+ wipe local state directory + restart with old version. And for `suppress()` 
the "wipe local state directory" is jus a no-op.
   
   It seems, we would crash though with this exception if one tries this 
downgrade path that we do support? So why disallow it?



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