Skip to content

Remove deleted vhost files from the replication index - #2335

Merged
jage merged 2 commits into
mainfrom
fix/vhost-delete-replicated-files
Oct 6, 2026
Merged

jage merged 2 commits into
mainfrom
fix/vhost-delete-replicated-files

Conversation

@jage

@jage jage commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

What does this pull request do?

Fixes #2334. With clustering enabled, VHost#delete closed the vhost and removed its data dir, but never told the replicator. The leader kept a file index entry (some holding an MFile) for every file of every deleted vhost, and followers kept the files on disk with an open fd and a SHA1 digest each. Repeated vhost create/delete grew memory without bound, also on a single node with clustering enabled and no followers.

It also keeps deleted vhosts from coming back after a failover. A follower kept the deleted vhost's dir, which is named after the SHA1 of the vhost name, so once that follower was promoted, creating a vhost with the same name loaded the old queues, messages and definitions.

This adds Replicator#delete_dir, which drops every index entry under a dir and sends a file delete for each of them to the followers. VHost#delete calls it after close and before removing the dir. Working from the index rather than walking the dir covers exactly what was replicated, also entries whose files are already gone. Followers need no protocol change: they already handle per-file deletes and prune empty parent dirs.

How can it be tested?

New spec in spec/clustering_spec.cr: create a vhost with a durable queue and a published message, wait for the follower to catch up, delete the vhost, and expect the vhost dir to be gone on the follower. It fails without the change. The clustering, vhost, message store and definitions replication specs pass, and make lint is clean.

@claude

claude Bot commented Oct 5, 2026

Copy link
Copy Markdown

No issues found.

@jage
jage force-pushed the fix/vhost-delete-replicated-files branch from f693e93 to 87794f4 Compare October 5, 2026 11:30
@kickster97 kickster97 added this to the 2.11.0 milestone Oct 5, 2026
jage added 2 commits October 6, 2026 14:07
VHost#delete only removed the data dir, so with clustering enabled the
leader kept an index entry for every file of every deleted vhost, and
followers kept the files on disk along with an open fd and digest for
each. Repeated vhost create/delete grew memory without bound, also on a
single node with clustering enabled.

Add Replicator#delete_dir, which drops every index entry under a dir
and tells followers to delete those files, and call it from
VHost#delete before the dir is removed.

Close #2334
@jage
jage force-pushed the fix/vhost-delete-replicated-files branch from 87794f4 to b953ec5 Compare October 6, 2026 16:05
@jage
jage merged commit ec9571b into main Oct 6, 2026
24 checks passed
@jage
jage deleted the fix/vhost-delete-replicated-files branch October 6, 2026 16:25
jage added a commit that referenced this pull request Oct 7, 2026
Fixes #2334. With clustering enabled, `VHost#delete` closed the vhost and
removed its data dir, but never told the replicator. The leader kept a
file index entry (some holding an `MFile`) for every file of every deleted
vhost, and followers kept the files on disk with an open fd and a SHA1
digest each. Repeated vhost create/delete grew memory without bound, also
on a single node with clustering enabled and no followers.

It also keeps deleted vhosts from coming back after a failover. A follower
kept the deleted vhost's dir, which is named after the SHA1 of the vhost
name, so once that follower was promoted, creating a vhost with the same
name loaded the old queues, messages and definitions.

This adds `Replicator#delete_dir`, which drops every index entry under a
dir and sends a file delete for each of them to the followers.
`VHost#delete` calls it after `close` and before removing the dir. Working
from the index rather than walking the dir covers exactly what was
replicated, also entries whose files are already gone. Followers need no
protocol change: they already handle per-file deletes and prune empty
parent dirs.

Covered by a regression spec in `spec/clustering_spec.cr`.

(cherry picked from commit ec9571b)
jage added a commit that referenced this pull request Oct 7, 2026
Fixes #2334. With clustering enabled, `VHost#delete` closed the vhost and
removed its data dir, but never told the replicator. The leader kept a
file index entry (some holding an `MFile`) for every file of every deleted
vhost, and followers kept the files on disk with an open fd and a SHA1
digest each. Repeated vhost create/delete grew memory without bound, also
on a single node with clustering enabled and no followers.

It also keeps deleted vhosts from coming back after a failover. A follower
kept the deleted vhost's dir, which is named after the SHA1 of the vhost
name, so once that follower was promoted, creating a vhost with the same
name loaded the old queues, messages and definitions.

This adds `Replicator#delete_dir`, which drops every index entry under a
dir and sends a file delete for each of them to the followers.
`VHost#delete` calls it after `close` and before removing the dir. Working
from the index rather than walking the dir covers exactly what was
replicated, also entries whose files are already gone. Followers need no
protocol change: they already handle per-file deletes and prune empty
parent dirs.

Covered by a regression spec in `spec/clustering_spec.cr`.

(cherry picked from commit ec9571b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory grows with vhost create/delete when clustering is enabled

3 participants