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

Emitting :key_deleted when key is purged #157

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lsxliron
Copy link

  • Now :key_deleted event is emitted when wither purging or deleting a key
  • Moved operations module attributes to KV module for better readability

Fixes #156

@lsxliron lsxliron marked this pull request as ready for review April 19, 2024 04:42
Copy link
Collaborator

@mmmries mmmries left a comment

Choose a reason for hiding this comment

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

Do you think there will ever be a case where someone cares about the difference between delete vs purge? I don't use the KV functionality much, so I'm not sure about the semantics of this API

@mmmries
Copy link
Collaborator

mmmries commented Apr 21, 2024

I don't know go very well, but I think this bit of the go-client is exposing purge events separately from delete events? https://github.com/nats-io/nats.go/blob/9d4b227179d60d6996c32b4b889d4e325ee06f78/kv.go#L982-L989

@lsxliron
Copy link
Author

lsxliron commented Apr 21, 2024

@mmmries i just started using the KV so I’m not an expert. The end result is the same, the key is removed from the bucket (history stays when using del and removed when using purge).

However, when the watcher process starts, you will still get historical events for a key that was deleted but not for a key that was purged.

Edit
It shouldn’t be hard to add a purge event if needed though

Comment on lines +271 to +275
headers
|> Enum.filter(fn {k, v} ->
k == @operation_header and (v == @operation_del or v == @operation_purge)
end)
|> length() > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
headers
|> Enum.filter(fn {k, v} ->
k == @operation_header and (v == @operation_del or v == @operation_purge)
end)
|> length() > 0
Enum.any?(headers, fn {k, v} ->
k == @operation_header and (v == @operation_del or v == @operation_purge)
end)

In practice this probably isn't a huge issue as written since the size of headers is probably small, but this is equivalent. At worst it makes a full pass once, at best it short-circuits early

Comment on lines +271 to +275
headers
|> Enum.filter(fn {k, v} ->
k == @operation_header and (v == @operation_del or v == @operation_purge)
end)
|> length() > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
headers
|> Enum.filter(fn {k, v} ->
k == @operation_header and (v == @operation_del or v == @operation_purge)
end)
|> length() > 0
Enum.any?(headers, fn {k, v} ->
k == @operation_header and (v == @operation_del or v == @operation_purge)
end)

In practice this probably isn't a huge issue as written since the size of headers is probably small, but this is equivalent. At worst it makes a full pass once, at best it short-circuits early

Comment on lines +269 to +270
@spec is_delete_operation?(headers :: Gnat.headers()) :: boolean()
def is_delete_operation?(headers) do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@spec is_delete_operation?(headers :: Gnat.headers()) :: boolean()
def is_delete_operation?(headers) do
@spec delete_operation?(headers :: Gnat.headers()) :: boolean()
def delete_operation?(headers) do

As an Elixir convention, using the ? is correct for a function that returns a boolean, but the is_ prefix is reserved for guards. See https://hexdocs.pm/elixir/naming-conventions.html#trailing-question-mark-foo

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.

KV watcher does not fire when key is purged
3 participants