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

Adding an Optional DeleteWithPrefix Method for State Stores to Allow Deletion of Actor State #3262

Open
1 of 5 tasks
RyanLettieri opened this issue Dec 11, 2023 · 6 comments
Labels
P1 pinned Issue does not get stale
Milestone

Comments

@RyanLettieri
Copy link
Contributor

RyanLettieri commented Dec 11, 2023

Describe the proposal

This proposal stems from the following feature request inside dapr runimte: dapr/dapr#6992
After a discussion with various members of the project, the following solution was proposed: dapr/dapr#6992 (comment)

By adding in an optional interface called 'DeleteWithPrefix', we will allow users to delete an actor's state. The interface is optional since some databases will not be able to implement it as highlighted by ItalyPaleAle, an active contributor for dapr here: dapr/dapr#7223 (comment)

Looking at sqlite as an example, a second migration will be added in order to generate a virtual "prefix" column. This column will contain all the information from the actor state entry up to but not including the key. For example, if the key entry is as follows: app-id||actor-type||actor-id||key the new virtual prefix column will contain app-id||actor-type||actor-id

New request that would be included in state/requests.go:

type DeleteWithPrefixRequest struct {
	Prefix string `json:"prefix"`
}

New interface that would be included in state/store.go:

type DeleteWithPrefix interface {
	DeleteWithPrefix(ctx context.Context, req DeleteWithPrefixRequest) (DeleteWithPrefixResponse, error)
}

List of components that are compatible with this optional method:

@berndverst
Copy link
Member

Please include the actual interface method you propose adding. Without that this proposal is not meaningful.

@berndverst
Copy link
Member

berndverst commented Dec 11, 2023

I want to know what the new request object will be called and what it will look like, and what the new method is called.

https://github.com/dapr/components-contrib/blob/main/state/store.go#L38
https://github.com/dapr/components-contrib/blob/main/state/requests.go#L43

@RyanLettieri
Copy link
Contributor Author

@berndverst updated the proposal to include both suggestions

@berndverst
Copy link
Member

@berndverst updated the proposal to include both suggestions

LGTM

And for say Postgres this will eventually be translated to DELETE FROM my_tbl WHERE ID LIKE '$1%' where $1 is the prefix? Is that the goal?

In other words delete every entry where the ID begins with prefix.

@ItalyPaleAle
Copy link
Contributor

And for say Postgres this will eventually be translated to DELETE FROM my_tbl WHERE ID LIKE '$1%' where $1 is the prefix? Is that the goal?

The goal is that, and the query is "like" that (see what I did there? :) )

More of an implementation detail, but I've guided @RyanLettieri to avoid the use of LIKE because that normally cannot leverage indexes, so it resorts to a full-table scans. Instead, I've recommended something along the lines of creating a virtual column on the table called key_prefix (or similar) which is generated by taking the prefix from the key column. Because you can add an index to virtual columns, then that is a lot more efficient.

Also worth noting that if the key doesn't have a prefix (which is possible in Dapr, such as foo), then it should never be deleted by DeleteWithPrefix.

Copy link

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 21, 2024
@ItalyPaleAle ItalyPaleAle added pinned Issue does not get stale and removed stale labels Jan 22, 2024
@ItalyPaleAle ItalyPaleAle modified the milestones: v1.13, v1.14 Feb 26, 2024
@berndverst berndverst modified the milestones: v1.14, v1.15 Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 pinned Issue does not get stale
Projects
None yet
Development

No branches or pull requests

3 participants