Skip to content

Conversation

@codelipenghui
Copy link
Contributor

@codelipenghui codelipenghui commented Sep 11, 2025

Summary

This PR improves the inactive topic deletion behavior for persistent topics by allowing empty topics (no entries and no backlog) to be deleted even when retention policies are configured.

Motivation

Previously, any retention policy would prevent topic deletion, even for completely empty topics that have no data to retain. This caused several issues:

  1. Metadata bloat: Unused topics would accumulate despite meeting all other deletion criteria
  2. Inconsistent behavior: Non-persistent topics could be deleted while persistent topics with the same conditions could not
  3. Resource waste: Empty topics consuming memory and storage unnecessarily

Changes

  • Modified shouldTopicBeRetained(): Added check to bypass retention policies for empty topics (getNumberOfEntries() == 0)
  • Added comprehensive tests:
    • testDeleteEmptyTopicWithRetentionPolicy(): Verifies empty topics are deleted despite retention policies
    • testRetainTopicWithDataAndRetentionPolicy(): Ensures topics with data still respect retention policies
  • Maintains backward compatibility: Topics with actual data continue to follow retention policies as before

Behavior Changes

Before

Empty topic + Retention policy → Topic retained indefinitely
Topic with data + Retention policy → Topic retained according to policy

After

Empty topic + Retention policy → Topic deleted (new improvement)
Topic with data + Retention policy → Topic retained according to policy (unchanged)

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

…s of retention policy

This change improves the inactive topic deletion behavior for persistent topics by allowing
empty topics (no entries and no backlog) to be deleted even when retention policies are configured.

Previously, any retention policy would prevent topic deletion, even for completely empty topics
that have no data to retain. This caused metadata bloat as unused topics would accumulate.

Changes:
- Modified shouldTopicBeRetained() to bypass retention checks for empty topics
- Added comprehensive tests to verify both deletion of empty topics and retention of topics with data
- Maintains backward compatibility for topics that actually contain data

This addresses the issue where persistent topics with retention policies were not being
auto-deleted despite having no subscriptions, no data, and meeting all other deletion criteria.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codelipenghui codelipenghui self-assigned this Sep 11, 2025
@codelipenghui codelipenghui added this to the 4.2.0 milestone Sep 11, 2025
@codelipenghui codelipenghui added release/4.0.7 release/4.1.1 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages labels Sep 11, 2025
@codelipenghui
Copy link
Contributor Author

/pulsarbot run-failure-checks

@apache apache deleted a comment from github-actions bot Sep 11, 2025
@github-actions github-actions bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Sep 11, 2025
@Technoboy- Technoboy- merged commit 437d9f6 into apache:master Sep 17, 2025
50 of 51 checks passed
Technoboy- added a commit that referenced this pull request Sep 18, 2025
…s of retention policy (#24733)

Co-authored-by: Jiwe Guo <technoboy@apache.org>
lhotari pushed a commit that referenced this pull request Sep 18, 2025
…s of retention policy (#24733)

Co-authored-by: Jiwe Guo <technoboy@apache.org>
(cherry picked from commit 437d9f6)
ganesh-ctds pushed a commit to datastax/pulsar that referenced this pull request Sep 18, 2025
…s of retention policy (apache#24733)

Co-authored-by: Jiwe Guo <technoboy@apache.org>
(cherry picked from commit 437d9f6)
(cherry picked from commit 789468f)
srinath-ctds pushed a commit to datastax/pulsar that referenced this pull request Sep 18, 2025
…s of retention policy (apache#24733)

Co-authored-by: Jiwe Guo <technoboy@apache.org>
(cherry picked from commit 437d9f6)
(cherry picked from commit 789468f)
KannarFr pushed a commit to CleverCloud/pulsar that referenced this pull request Sep 22, 2025
…s of retention policy (apache#24733)

Co-authored-by: Jiwe Guo <technoboy@apache.org>
@codelipenghui codelipenghui deleted the improve-inactive-topic-deletion-with-retention branch September 23, 2025 04:17
walkinggo pushed a commit to walkinggo/pulsar that referenced this pull request Oct 8, 2025
…s of retention policy (apache#24733)

Co-authored-by: Jiwe Guo <technoboy@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.1 doc-not-needed Your PR changes do not impact docs ready-to-test release/4.0.7 release/4.1.1 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants