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

[redis_proxy] Add support for UNWATCH #37620

Merged
merged 11 commits into from
Dec 17, 2024
Merged

Conversation

dbarbosapn
Copy link
Contributor

@dbarbosapn dbarbosapn commented Dec 11, 2024

This PR adds support for the UNWATCH command in the Redis proxy.
Because of the lack of UNWATCH support, transactions are not well supported by clients such as StackExchange.Redis, since conditions require UNWATCH support.

The Challenge
The challenge with implementing UNWATCH in Envoy is knowing which server to send the UNWATCH command to.
This was solved in this PR by considering WATCH a Transaction Command. The behavior is explained below.

Expected Behavior

  1. WATCH as a transaction command.
    Making WATCH a transaction command means it will be handled by the transaction handler, not the simple request handler. There, we set the transaction key in advance, without starting the transaction. This means we will have state of the key where the latest WATCH was sent to.

  2. UNWATCH after WATCH
    If an UNWATCH is sent right after a WATCH, we send it to the server of the transaction key that was set. After that, we reset the key. Covered by test: ✅

  3. UNWATCH without key
    Sending an UNWATCH without previous key being set, will have a direct proxy response of +OK\r\n. Covered by test: ✅

  4. UNWATCH after MULTI (no key)
    Sending an UNWATCH without a key but within a transaction, will also be a no-op in the proxy. But the response this time is +QUEUED\r\n, to match Redis behavior. Covered by test: ✅

  5. UNWATCH with key
    Sending an UNWATCH with a transaction key set (either by WATCH or a simple command within an active transaction) will send the command to the server of such hash key. Covered by test: ✅

  6. MULTI after WATCH
    Since WATCH now sets the transaction key in advance, in this scenario we no longer queue the MULTI command, and we send it directly upstream, based on the key set by the WATCH command. Covered by test: ✅

  7. MULTI after UNWATCH
    If an UNWATCH is sent after a WATCH, the transaction key is reset, and the MULTI command is queued. This is the existing behavior in the proxy. Covered by test: ✅

Signed-off-by: Diogo Barbosa <[email protected]>
@dbarbosapn
Copy link
Contributor Author

dbarbosapn commented Dec 11, 2024

cc @mattklein123 @weisisea shorter one this time 😄

@dbarbosapn dbarbosapn changed the title Add support for UNWATCH [redis_proxy] Add support for UNWATCH Dec 11, 2024
Signed-off-by: Diogo Barbosa <[email protected]>
@mgravell
Copy link

@dbarbosapn if this is accepted, please make sure to let me know so I can update the client library's data

Signed-off-by: Diogo Barbosa <[email protected]>
Signed-off-by: Diogo Barbosa <[email protected]>
Signed-off-by: Diogo Barbosa <[email protected]>
mattklein123
mattklein123 previously approved these changes Dec 17, 2024
@mattklein123
Copy link
Member

Sorry needs main merge.

/wait

Signed-off-by: Diogo Barbosa <[email protected]>
@dbarbosapn
Copy link
Contributor Author

Sorry needs main merge.

/wait

Done! Thank you!! 🙇

@mattklein123 mattklein123 merged commit ac61d8e into envoyproxy:main Dec 17, 2024
24 checks passed
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