Skip to content

rabbit_khepri: Optimize cleanup in topic binding projection#15214

Merged
dumbbell merged 1 commit intomainfrom
optimize-topic-bindings-deletion
Jan 9, 2026
Merged

rabbit_khepri: Optimize cleanup in topic binding projection#15214
dumbbell merged 1 commit intomainfrom
optimize-topic-bindings-deletion

Conversation

@dumbbell
Copy link
Copy Markdown
Collaborator

@dumbbell dumbbell commented Jan 6, 2026

Why

Before this patch, the projection function that managed the topic bindings graph only kept track of "topic word -> topic word" = "this node ID". Reading and updating this graph was efficient.

However, deleting a node in this graph was expensive because it used ets:match/3 to determine if an edge was pointing to nothing and could be reclaimed. ets:match() does a full scan of the table. On my laptop, this scan took 20 ms with 100k topic bindings, thus >30 minutes to delete all of them.

How

The new projection function tracks the number of children a target node has as well. This way, it knows that if this counter reaches 0, the edge can be reclaimed.

The same test with 100k topic bindings takes 3.5 seconds to delete them.

@dumbbell dumbbell requested a review from mkuratczyk January 6, 2026 09:03
@dumbbell dumbbell self-assigned this Jan 6, 2026
@dumbbell
Copy link
Copy Markdown
Collaborator Author

dumbbell commented Jan 6, 2026

This not ready for review or testing at all, my understanding of the problem is incorrect.

@dumbbell dumbbell removed the request for review from mkuratczyk January 6, 2026 11:39
@dumbbell dumbbell force-pushed the optimize-topic-bindings-deletion branch from fefa84a to 66a5ba5 Compare January 6, 2026 15:19
@mergify mergify bot added the make label Jan 6, 2026
@dumbbell dumbbell force-pushed the optimize-topic-bindings-deletion branch 6 times, most recently from cb5836c to ca182d1 Compare January 8, 2026 14:23
@dumbbell dumbbell requested a review from mkuratczyk January 8, 2026 14:53
@dumbbell dumbbell force-pushed the optimize-topic-bindings-deletion branch from ca182d1 to 7f0976a Compare January 8, 2026 14:59
@mkuratczyk
Copy link
Copy Markdown
Contributor

mkuratczyk commented Jan 8, 2026

I thnik we need to bump Horus or remove this dep_horus:
https://github.com/rabbitmq/rabbitmq-server/blob/optimize-topic-bindings-deletion/deps/rabbit/Makefile#L136

As it is, Horus 0.3.1 is used on this branch, causing a known/fixed issue.

@dumbbell
Copy link
Copy Markdown
Collaborator Author

dumbbell commented Jan 8, 2026

Good catch, I forgot about this old temporary change.

@dumbbell dumbbell marked this pull request as ready for review January 8, 2026 17:44
@michaelklishin michaelklishin added this to the 4.3.0 milestone Jan 8, 2026
[Why]
Before this patch, the projection function that managed the topic bindings
graph only kept track of "topic word -> topic word" = "this node ID".
Reading and updating this graph was efficient.

However, deleting a node in this graph was expensive because it used
`ets:match/3` to determine if an edge was pointing to nothing and could
be reclaimed. `ets:match()` does a full scan of the table.

On my laptop, this scan took 20 ms with 100k topic bindings, thus >30
minutes to delete all of them.

[How]
The new projection function tracks the number of children a target node
has as well. This way, it knows that if this counter reaches 0, the edge
can be reclaimed.

The same test with 100k topic bindings takes 3.5 seconds to delete them.
@dumbbell dumbbell force-pushed the optimize-topic-bindings-deletion branch from 7f0976a to 612d93d Compare January 8, 2026 22:47
@dumbbell
Copy link
Copy Markdown
Collaborator Author

dumbbell commented Jan 9, 2026

I thnik we need to bump Horus or remove this dep_horus: https://github.com/rabbitmq/rabbitmq-server/blob/optimize-topic-bindings-deletion/deps/rabbit/Makefile#L136

As it is, Horus 0.3.1 is used on this branch, causing a known/fixed issue.

This was fixed in #15230.

Copy link
Copy Markdown
Contributor

@mkuratczyk mkuratczyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I can still make this behave poorly as we need one more change (fix for exchange serials) but this part is good and the serials fix is coming soon. thanks!

@dumbbell
Copy link
Copy Markdown
Collaborator Author

dumbbell commented Jan 9, 2026

The mentionned fix to exchange serials is now submitted serapately in #15236.

@dumbbell dumbbell merged commit d563c07 into main Jan 9, 2026
576 of 577 checks passed
@dumbbell dumbbell deleted the optimize-topic-bindings-deletion branch January 9, 2026 08:43
dumbbell added a commit that referenced this pull request Jan 9, 2026
rabbit_khepri: Optimize cleanup in topic binding projection (backport #15214)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants