prometheus: "unexpected full record" error cause WAL truncation in Compact failed and WAL num grow endlessly

What did you do?

When prometheus is starting, mem grows during WAL replay until exhaust mem of host, notice wal dir size and num is abnormal, about 800 wals taking 23GiB: image image

after add more mem to this host, prometheus start successfully, but after WAL replay, prometheus failed to create checkpoint, error log: image

and old wal never get truncated

What did you expect to see?

If wal get corrupted, consider skip this wal and delete it when creating checkpoint

What did you see instead? Under which circumstances?

Failed to create checkpoint, and old wal won’t be cleaned since then

System information

Linux 5.10.0-60.18.0.50.oe2203.aarch64 aarch64

Prometheus version

prometheus, version 2.37.5 (branch: OCTO-1289, revision: af2eb62dfefafa56beb94cf9edf91127eed06a5d)
  build user:       root@armdev
  build date:       20230426-07:43:46
  go version:       go1.19
  platform:         linux/arm64

Prometheus configuration file

No response

Alertmanager version

No response

Alertmanager configuration file

No response

Logs

ts=2023-11-15T11:07:48.347Z caller=main.go:480 level=warn deprecation_notice="'storage.tsdb.retention' flag is deprecated use 'storage.tsdb.retention.time' instead."
ts=2023-11-15T11:07:48.347Z caller=main.go:535 level=info msg="Starting Prometheus Server" mode=server version="(version=2.37.5, branch=OCTO-1289, revision=af2eb62dfefafa56beb94cf9edf91127eed06a5d)"
ts=2023-11-15T11:07:48.347Z caller=main.go:540 level=info build_context="(go=go1.19, user=root@armdev, date=20230426-07:43:46)"
ts=2023-11-15T11:07:48.347Z caller=main.go:541 level=info host_details="(Linux 5.10.0-60.18.0.50.oe2203.aarch64 #1 SMP Wed Mar 30 02:43:08 UTC 2022 aarch64 localhost.localdomain (none))"
ts=2023-11-15T11:07:48.347Z caller=main.go:542 level=info fd_limits="(soft=1048576, hard=1048576)"
ts=2023-11-15T11:07:48.347Z caller=main.go:543 level=info vm_limits="(soft=unlimited, hard=unlimited)"
ts=2023-11-15T11:07:48.375Z caller=web.go:553 level=info component=web msg="Start listening for connections" address=0.0.0.0:9090
ts=2023-11-15T11:07:48.377Z caller=main.go:972 level=info msg="Starting TSDB ..."
ts=2023-11-15T11:07:48.379Z caller=tls_config.go:231 level=info component=web msg="TLS is disabled." http2=false
ts=2023-11-15T11:07:48.380Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1693987246171 maxt=1695362400000 ulid=01HAY8S0R765TD9WAXMZDWTYDP
ts=2023-11-15T11:07:48.397Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1695362400015 maxt=1697112000000 ulid=01HCJDAKGM87HHM5M2MXWYMVW3
ts=2023-11-15T11:07:48.422Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1697112000015 maxt=1698861600000 ulid=01HE6HW2HA9015B73H0QD73EEN
ts=2023-11-15T11:07:48.423Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1698861600015 maxt=1699444800000 ulid=01HEQY1DFTJJRNZPTPYWEF84R9
ts=2023-11-15T11:07:48.424Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1699444800015 maxt=1699639200000 ulid=01HEXQDQHSR69ZQET50E3B3PK2
ts=2023-11-15T11:07:48.424Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1699639200015 maxt=1699833600000 ulid=01HF3GTD2GA1MHY80BQ2GZM6Y3
ts=2023-11-15T11:07:48.425Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1699833600015 maxt=1699898400000 ulid=01HF5EKSPZYMNZNF8KA6X3CGQR
ts=2023-11-15T11:07:48.426Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1699898400015 maxt=1699963200000 ulid=01HF7CDAHXCSDKFSSW7MA90WPV
ts=2023-11-15T11:07:48.426Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1699963200015 maxt=1699984800000 ulid=01HF810C1ZW1TXJEF92VVHZNVN
ts=2023-11-15T11:07:48.427Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1700006400015 maxt=1700013600000 ulid=01HF8EQQ39B8J5TCWKBVNXNP91
ts=2023-11-15T11:07:48.445Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1700013600015 maxt=1700020800000 ulid=01HF8NKEB7MTK4JJP5VG3VTA75
ts=2023-11-15T11:07:48.445Z caller=repair.go:56 level=info component=tsdb msg="Found healthy block" mint=1699984800015 maxt=1700006400000 ulid=01HF8NKJ6TX8VPSGTG3JM1CGR9
ts=2023-11-15T11:07:51.080Z caller=head.go:493 level=info component=tsdb msg="Replaying on-disk memory mappable chunks if any"
ts=2023-11-15T11:07:51.116Z caller=head.go:536 level=info component=tsdb msg="On-disk memory mappable chunks replay completed" duration=36.049975ms
ts=2023-11-15T11:07:51.116Z caller=head.go:542 level=info component=tsdb msg="Replaying WAL, this may take a while"
ts=2023-11-15T11:07:52.284Z caller=head.go:578 level=info component=tsdb msg="WAL checkpoint loaded"
ts=2023-11-15T11:07:52.458Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=29 maxSegment=833
ts=2023-11-15T11:07:52.461Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=30 maxSegment=833
ts=2023-11-15T11:07:54.497Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=31 maxSegment=833
ts=2023-11-15T11:07:55.242Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=32 maxSegment=833
ts=2023-11-15T11:07:56.563Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=33 maxSegment=833

...

ts=2023-11-15T11:32:19.668Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=830 maxSegment=833
ts=2023-11-15T11:32:22.279Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=831 maxSegment=833
ts=2023-11-15T11:32:22.279Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=832 maxSegment=833
ts=2023-11-15T11:32:22.280Z caller=head.go:613 level=info component=tsdb msg="WAL segment loaded" segment=833 maxSegment=833
ts=2023-11-15T11:32:22.280Z caller=head.go:619 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=1.167429252s wal_replay_duration=24m29.995841333s total_replay_duration=24m31.199442354s
ts=2023-11-15T11:32:34.298Z caller=main.go:993 level=info fs_type=EXT4_SUPER_MAGIC
ts=2023-11-15T11:32:34.298Z caller=main.go:996 level=info msg="TSDB started"
ts=2023-11-15T11:32:34.298Z caller=main.go:1177 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
ts=2023-11-15T11:32:34.715Z caller=main.go:1214 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=416.305349ms db_storage=2.9µs remote_storage=2.28µs web_handler=850ns query_engine=1.74µs scrape=617.537µs scrape_sd=717.059µs notify=68.611µs notify_sd=23.63µs rules=402.596883ms tracing=69.19µs
ts=2023-11-15T11:32:34.715Z caller=main.go:957 level=info msg="Server is ready to receive web requests."
ts=2023-11-15T11:32:34.715Z caller=main.go:1177 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
ts=2023-11-15T11:32:34.715Z caller=manager.go:948 level=info component="rule manager" msg="Starting rule manager..."
ts=2023-11-15T11:32:35.185Z caller=main.go:1214 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=470.195661ms db_storage=1.95µs remote_storage=3.45µs web_handler=1.06µs query_engine=1.75µs scrape=228.903µs scrape_sd=566.207µs notify=26.52µs notify_sd=15.76µs rules=461.237032ms tracing=15.05µs
ts=2023-11-15T11:32:43.148Z caller=compact.go:533 level=info component=tsdb msg="write block" mint=1700020800000 maxt=1700028000000 ulid=01HF9C2EBZMFQZY5P4KC5JHEWQ duration=2.701857777s
ts=2023-11-15T11:32:43.623Z caller=head.go:842 level=info component=tsdb msg="Head GC completed" duration=469.597281ms
ts=2023-11-15T11:32:43.625Z caller=checkpoint.go:97 level=info component=tsdb msg="Creating checkpoint" from_segment=29 to_segment=564 mint=1700028000000
ts=2023-11-15T11:32:44.267Z caller=db.go:829 level=error component=tsdb msg="compaction failed" err="WAL truncation in Compact: create checkpoint: read segments: corruption in segment /mnt/data/prometheus/data/wal/00000030 at 188: unexpected full record"
ts=2023-11-15T11:33:02.351Z caller=main.go:1177 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
ts=2023-11-15T11:33:02.740Z caller=main.go:1214 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=389.04133ms db_storage=1.94µs remote_storage=3.24µs web_handler=880ns query_engine=1.87µs scrape=4.14121ms scrape_sd=555.227µs notify=31.65µs notify_sd=17.1µs rules=377.372289ms tracing=16.4µs

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 6
  • Comments: 23 (3 by maintainers)

Most upvoted comments

We are affected by this issue now as well, I see the linked PR has some merge conflicts. Is it possible to expedite the PR approval?

I can rebase my pr and retest it today, but the discretion is up to the reviewer @HontoNoRoger

cascading problems

Not mentioned so far is the impact of this issue due to a cascade of problematic error handling, when it’s not treated on short notice.

disclaimer

  • Yes, I’m running an old version (2.31.2, shipped with ubuntu 22), but I’m fairly sure the behaviors also apply to recent versions.
  • Of course the issue is partially on us for not handling increase(prometheus_tsdb_wal_corruptions_total[121m]) > 0 in time, but this highlights resilience issues in the persistence layer.

  1. (discussed so far) Prometheus is unable to resume WAL playback after a bad WAL block (err="opening storage failed: get segment range: segments are not sequential"). this means all data after the corrupted block is effectively lost, as there is no way for prometheus to recover it as of now.

  2. WAL taking up increasing amounts of space (which is accounted for in the --storage.tsdb.retention.size parameter) causes the properly persisted blocks to use less and less space after each head compaction event, which means that over time (duration depends on number of active series, retention-size-limit), historical data is removed until almost none is kept. It’s good that WAL / retention of recent data is prioritized over historical data. However, forcing deletion of the WAL after the corrupted segment effectively means, that no data is left after a restart.

  3. Large storage requirements of WAL increase risk of disk quota exceeded issues, triggering subsequent corrupted WAL segments and failed TSDB head compactions (compaction failed). I believe this compaction is not transactional, causing those to-be-compacted chunks to be lost as well – but i’m not sure about this.

  4. On startup, prometheus deletes out-of-sequence WAL files after checkpoints, eg when one segment file was manually deleted in an attempt to fix the unexpected full record issue, or any other future persistence issue. automated deletion of persisted data is a very questionable default. (rationale explained in https://github.com/prometheus/prometheus/issues/7530#issuecomment-880548633)

  5. for a large WAL, memory usage spikes during replay, causing a crash loop if tight memory limits are set.

suggestions for making tsdb more error tolerant

  • during operation, allow replay of WAL segments after a corrupted segment, or fixing of a corrupted segment – automatically or through a promtool invocation. if both are infeasible, discard the corrupted segment + all following segments (ideally whenever appending a new WAL segment, at the latest when compacting to tsdb chunks / Head GC)
  • consider WAL size properly in --storage.tsdb.retention.size, so that disk quota exceeded problems are unlikely to happen if set appropriately (https://github.com/prometheus/prometheus/issues/12882)
  • during startup avoid automated deletion out-of-sequence WAL segment files. instead inform the user about their manual options.

collection of related issues and PRs targeting WAL resilience

I just updated to latest available docker image and still 15500 WAL to replay and they don’t get consolidated… Will tell you the exact version once it manages to start…

Can anyone reproduce with the latest Prometheus? (If you said +1, what version of Prometheus are you running?). We fixed some issues in the past causing similar behaviour.