Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont write all binds to defs #570

Merged
merged 5 commits into from
Sep 8, 2023
Merged

Conversation

spuun
Copy link
Member

@spuun spuun commented Sep 1, 2023

WHAT is this pull request doing?

definitions.amqp can grow indefinitely because we write all bind and unbind frames to it. This will add guard against that behavior.

HOW can this pull request be tested?

Add the same binding multiple times and verify it's not written to definitions.amqp. If log level is debug it will be logged if written to file.

@spuun
Copy link
Member Author

spuun commented Sep 4, 2023

We should probably add some kind of occasional compactation during runtime. Count "deletes" and trigger compaction after X deletions or something, so prevent the file from growing on e.g. high queue churn.

@spuun spuun marked this pull request as ready for review September 4, 2023 11:06
@viktorerlingsson
Copy link
Member

We should probably add some kind of occasional compactation during runtime. Count "deletes" and trigger compaction after X deletions or something, so prevent the file from growing on e.g. high queue churn.

Sounds good!

src/lavinmq/exchange/default.cr Outdated Show resolved Hide resolved
src/lavinmq/vhost.cr Outdated Show resolved Hide resolved
@spuun spuun requested a review from carlhoerberg September 5, 2023 09:19
Comment on lines +10 to +12
ret = @queue_bindings[{routing_key, nil}].add? destination
after_bind(destination, routing_key, headers)
ret
Copy link
Member

Choose a reason for hiding this comment

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

Should after_bind be executed even if the binding was already there?

Suggested change
ret = @queue_bindings[{routing_key, nil}].add? destination
after_bind(destination, routing_key, headers)
ret
if @queue_bindings[{routing_key, nil}].add? destination
after_bind(destination, routing_key, headers)
true
end

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe, I just didn't want to change the behavior. Seems to be federation link that listens for bind/unbind events to forward them to the upstream.

Comment on lines 303 to 304
return false unless src.bind(dst, f.routing_key, f.arguments.to_h)
store_definition(f) if !loading && src.durable && dst.durable
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't false indicate that the client will get a PreconditionFailed back? as in the case above if the exchange is missing? Should we just not store the defintion instead?

Suggested change
return false unless src.bind(dst, f.routing_key, f.arguments.to_h)
store_definition(f) if !loading && src.durable && dst.durable
if src.bind(dst, f.routing_key, f.arguments.to_h)
store_definition(f) if !loading && src.durable && dst.durable
end

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe :) It wasn't obvious on what the return value meant (or how it's used). At least not used in Client. Maybe we should use enums or symbols here and there instead to get more descriptive return values?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think i chose to return false because we did so for Queue::Declare if the queue already existed.

- No need to add an existing binding
- No need to unbind a non-existing binding

Without this guard the definitions.amqp file grows indefinitely
Verify that bind/unbind frames aren't written to definition files unless
needed.
Instead of adding `has_binding?` which adds some unecessary `.to_h`
`bind`/`unbind` will return a boolean indicatin whether the binding has
been added/deleted or not.
@carlhoerberg carlhoerberg force-pushed the dont-write-all-binds-to-defs branch from f9d3ae7 to 75ecbbd Compare September 8, 2023 12:44
@carlhoerberg carlhoerberg merged commit 72c5501 into main Sep 8, 2023
14 of 18 checks passed
@carlhoerberg carlhoerberg deleted the dont-write-all-binds-to-defs branch September 8, 2023 12:44
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.

3 participants