Skip to content

Commit 24ac9fc

Browse files
author
Remy Gwaramadze
committed
Add explanation
1 parent c22320a commit 24ac9fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

quixstreams/state/rocksdb/windowed/transaction.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,26 @@ def expire_all_windows(
403403
)
404404

405405
def _deserialize_prefix(self, prefix: bytes) -> Any:
406+
"""
407+
Attempt to deserialize a window prefix.
408+
409+
Window prefixes can be provided either as raw bytes or as other types
410+
(e.g., dict). The `as_state()` method conditionally serializes these
411+
prefixes to bytes only if they are not already bytes before storing.
412+
413+
When retrieving a prefix during partition-level windows expiration, we
414+
don't know its original type due to this conditional serialization.
415+
Therefore, we must first *try* to deserialize it using the configured
416+
`loads` function.
417+
418+
If deserialization succeeds, it means the prefix was originally a
419+
non-bytes type, and we return the deserialized object.
420+
If deserialization fails with a `StateSerializationError`, it indicates
421+
that the prefix was likely provided as raw bytes initially, so we
422+
return the original `prefix` bytes.
423+
424+
:param prefix: The prefix bytes retrieved from storage.
425+
"""
406426
try:
407427
return deserialize(prefix, loads=self._loads)
408428
except StateSerializationError:

0 commit comments

Comments
 (0)