[
https://issues.apache.org/jira/browse/FLINK-23886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18154481#comment-18154481
]
Charlotta Westberg commented on FLINK-23886:
--------------------------------------------
We hit this in a dev environment on Flink 1.14.6 (FRocksDB
6.20.3-ververica-1.0, incremental checkpoints, RocksDB timers) and analysed the
corrupt checkpoint offline. Our working theory is a RocksDB block-cache key
collision, [rocksdb#7405|https://github.com/facebook/rocksdb/issues/7405],
fixed in RocksDB 6.28 ([#9126|https://github.com/facebook/rocksdb/pull/9126])
but still present in the FRocksDB shipped with Flink 1.x (up to 1.20).
{noformat}
org.apache.flink.util.FlinkRuntimeException: Error while deserializing the
element.
at
org.apache.flink.contrib.streaming.state.RocksDBCachingPriorityQueueSet.deserializeElement(RocksDBCachingPriorityQueueSet.java:388)
at
org.apache.flink.contrib.streaming.state.RocksDBCachingPriorityQueueSet.peek(RocksDBCachingPriorityQueueSet.java:145)
...
at
org.apache.flink.streaming.runtime.operators.windowing.WindowOperator.open(WindowOperator.java:225)
...
Caused by: java.io.EOFException
at
org.apache.flink.core.memory.DataInputDeserializer.readUnsignedByte(DataInputDeserializer.java:329)
at org.apache.flink.types.StringValue.readString(StringValue.java:781)
at
org.apache.flink.api.common.typeutils.base.StringSerializer.deserialize(StringSerializer.java:73)
at
org.apache.flink.streaming.api.operators.TimerSerializer.deserialize(TimerSerializer.java:161)
at
org.apache.flink.contrib.streaming.state.RocksDBCachingPriorityQueueSet.deserializeElement(RocksDBCachingPriorityQueueSet.java:386)
{noformat}
*Mechanism*
* Before RocksDB 6.28 a block's cache key comes from the file's (device, inode,
inode generation)
([io_posix.cc|https://github.com/ververica/frocksdb/blob/FRocksDB-6.20.3/env/io_posix.cc#L325-L350]).
On Linux (XFS, and ext4 on current kernels) the generation of a new inode is
random 32-bit, and inode numbers of deleted files are reused immediately. So a
new SST can, rarely, get the key of a deleted SST whose blocks are still
cached, and RocksDB silently serves the old blocks (no checksum check on cache
hits). Compactions also read through the cache, so a stale block can be written
into a new file, across column families.
* Flink makes it more likely: every incremental checkpoint flushes tiny SSTs
that are compacted away seconds later (~720 files/hour per DB for us), and with
a small state the cache never fills, so stale blocks stay. Our rough estimate
is about one collision per DB per month if the cache is not filled; with a full
cache, much less.
*Evidence from the checkpoint* (we parsed {{_metadata}}, all SSTs and the
MANIFEST)
* The timer CF contained a window-contents record from ~3 hours earlier (read
as a timer it gives exactly this EOFException, and it sorts first, so every
restore hits it) and an expired timer that should have been deleted.
* Across ~120k MANIFEST edits in all 10 RocksDB instances, exactly one
compaction produced output outside the key range of its inputs: a timer-CF
compaction whose output starts with that old window-contents key, and which
also lost the timer's delete. That fits one input block being replaced by a
cached block of a deleted window-contents file, and nothing else we checked.
*Reproduction of the mechanism*: an {{LD_PRELOAD}} library that makes
{{ioctl(FS_IOC_GETVERSION)}} return a constant generation (so every inode reuse
collides). Against frocksdbjni 6.20.3 with an LRU block cache, 99 % of 800,000
reads silently returned the previous round's values; with
{{setNoBlockCache(true)}}, 0.
*Workaround* (our state is small): RocksDB without block cache, via an options
factory with {{setNoBlockCache(true)}} and
{{state.backend.rocksdb.memory.managed: false}}. In a load test with production
data it works for us, but I cannot guarantee the same for everyone else. We
chose to do this although we haven't seen the error in production, where the
block cache is full and a collision is much less likely: a failed restore is
the visible case, but most collisions would be silent, and there is no way to
tell whether the data served from the block cache is correct. Flink 2.x
(FRocksDB 8.10, FLINK-35573) has the RocksDB fix.
The real fix should be to get a rocksdb version > 6.28 for flink, but I'm not
sure what other issues that could bring. We are already planning to upgrade to
1.20, but were going to wait with going to 2.x
Caveat: that this incident was a collision is inferred from the evidence, we
cannot be 100% certain, but everything fits.
> An exception is thrown out when recover job timers from checkpoint file
> -----------------------------------------------------------------------
>
> Key: FLINK-23886
> URL: https://issues.apache.org/jira/browse/FLINK-23886
> Project: Flink
> Issue Type: Bug
> Components: Runtime / State Backends
> Affects Versions: 1.10.0, 1.11.3, 1.12.2, 1.13.2, 1.13.5, 1.14.4
> Reporter: Jing Zhang
> Assignee: Natea Eshetu Beshada
> Priority: Major
> Labels: pull-request-available
> Attachments: image-2021-08-25-16-38-04-023.png,
> image-2021-08-25-16-38-12-308.png, image-2021-08-25-17-06-29-806.png,
> image-2021-08-25-17-07-38-327.png, image-2024-07-08-16-55-53-243.png,
> segment-drop-corrupted-timer-state.diff
>
>
> A user report the bug in the [mailist.
> |http://mail-archives.apache.org/mod_mbox/flink-user/202108.mbox/%3ccakmsf43j14nkjmgjuy4dh5qn2vbjtw4tfh4pmmuyvcvfhgf...@mail.gmail.com%3E]I
> paste the content here.
> Setup Specifics:
> Version: 1.6.2
> RocksDB Map State
> Timers stored in rocksdb
>
> When we have this job running for long periods of time like > 30 days, if for
> some reason the job restarts, we encounter "Error while deserializing the
> element". Is this a known issue fixed in later versions? I see some changes
> to code for FLINK-10175, but we don't use any queryable state
>
> Below is the stack trace
>
> org.apache.flink.util.FlinkRuntimeException: Error while deserializing the
> element.
> at
> org.apache.flink.contrib.streaming.state.RocksDBCachingPriorityQueueSet.deserializeElement(RocksDBCachingPriorityQueueSet.java:389)
> at
> org.apache.flink.contrib.streaming.state.RocksDBCachingPriorityQueueSet.peek(RocksDBCachingPriorityQueueSet.java:146)
> at
> org.apache.flink.contrib.streaming.state.RocksDBCachingPriorityQueueSet.peek(RocksDBCachingPriorityQueueSet.java:56)
> at
> org.apache.flink.runtime.state.heap.KeyGroupPartitionedPriorityQueue$InternalPriorityQueueComparator.comparePriority(KeyGroupPartitionedPriorityQueue.java:274)
> at
> org.apache.flink.runtime.state.heap.KeyGroupPartitionedPriorityQueue$InternalPriorityQueueComparator.comparePriority(KeyGroupPartitionedPriorityQueue.java:261)
> at
> org.apache.flink.runtime.state.heap.HeapPriorityQueue.isElementPriorityLessThen(HeapPriorityQueue.java:164)
> at
> org.apache.flink.runtime.state.heap.HeapPriorityQueue.siftUp(HeapPriorityQueue.java:121)
> at
> org.apache.flink.runtime.state.heap.HeapPriorityQueue.addInternal(HeapPriorityQueue.java:85)
> at
> org.apache.flink.runtime.state.heap.AbstractHeapPriorityQueue.add(AbstractHeapPriorityQueue.java:73)
> at
> org.apache.flink.runtime.state.heap.KeyGroupPartitionedPriorityQueue.<init>(KeyGroupPartitionedPriorityQueue.java:89)
> at
> org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend$RocksDBPriorityQueueSetFactory.create(RocksDBKeyedStateBackend.java:2792)
> at
> org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend.create(RocksDBKeyedStateBackend.java:450)
> at
> org.apache.flink.streaming.api.operators.InternalTimeServiceManager.createTimerPriorityQueue(InternalTimeServiceManager.java:121)
> at
> org.apache.flink.streaming.api.operators.InternalTimeServiceManager.registerOrGetTimerService(InternalTimeServiceManager.java:106)
> at
> org.apache.flink.streaming.api.operators.InternalTimeServiceManager.getInternalTimerService(InternalTimeServiceManager.java:87)
> at
> org.apache.flink.streaming.api.operators.AbstractStreamOperator.getInternalTimerService(AbstractStreamOperator.java:764)
> at
> org.apache.flink.streaming.api.operators.KeyedProcessOperator.open(KeyedProcessOperator.java:61)
> at
> org.apache.flink.streaming.runtime.tasks.StreamTask.openAllOperators(StreamTask.java:424)
> at
> org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:290)
> at org.apache.flink.runtime.taskmanager.Task.run(Task.java:711)
> at java.lang.Thread.run(Thread.java:748)
> Caused by: java.io.EOFException
> at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)
> at org.apache.flink.types.StringValue.readString(StringValue.java:769)
> at
> org.apache.flink.api.common.typeutils.base.StringSerializer.deserialize(StringSerializer.java:69)
> at
> org.apache.flink.api.common.typeutils.base.StringSerializer.deserialize(StringSerializer.java:28)
> at
> org.apache.flink.api.java.typeutils.runtime.RowSerializer.deserialize(RowSerializer.java:179)
> at
> org.apache.flink.api.java.typeutils.runtime.RowSerializer.deserialize(RowSerializer.java:46)
> at
> org.apache.flink.streaming.api.operators.TimerSerializer.deserialize(TimerSerializer.java:168)
> at
> org.apache.flink.streaming.api.operators.TimerSerializer.deserialize(TimerSerializer.java:45)
> at
> org.apache.flink.contrib.streaming.state.RocksDBCachingPriorityQueueSet.deserializeElement(RocksDBCachingPriorityQueueSet.java:387)
> ... 20 more
>
>
>
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)