apache / apache/pulsar

[Bug] Compacted topic retains keys indefinitely without respecting message TTL or retention policy

Open
#24,791 1 comment 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before reporting

- [x] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Read release policy

- [x] I understand that [unsupported versions](https://pulsar.apache.org/contribute/release-policy/#supported-versions) don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

### User environment

java
pulsar 3.3.6

### Issue Description

The current topic compaction mechanism does not respect topic-level data expiration policies (Message TTL and Retention). Once a key is written to the compacted ledger, it persists forever, even if its latest message should have been expired and deleted by the configured TTL/retention rules.

1. During compaction, the latest value for each key is copied into a new, persistent `compactedLedger`.
2. This `compactedLedger` is treated as a separate entity and is not cleaned up by the standard expiration processes that act on regular ledgers.
3. As a result, a key's latest value remains in storage indefinitely after compaction, regardless of TTL or retention settings.

### Error messages

```text

```

### Reproducing the issue

1. send k,v message to a topic(retention 5min, ttl 5min)
2. trigger compact
3. we can read the key after 5min.

### Additional information

_No response_

### Are you willing to submit a PR?

- [x] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

No source files or tests are named. Reproduce the issue with a compacted topic configured with five-minute retention and message TTL, then trace the topic-compaction path alongside the regular ledger expiration and retention processes. Done means a compacted key is no longer readable after the configured expiration period.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.