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

Merge branch 'main' into main

d9f5eaf
Select commit
Loading
Failed to load commit list.
Merged

[redis_proxy] Add support for UNWATCH #37620

Merge branch 'main' into main
d9f5eaf
Select commit
Loading
Failed to load commit list.
CI (Envoy) / Mobile/iOS tests skipped Dec 17, 2024 in 0s

Check was skipped

This check was not triggered in this CI run

Details

Request (pr/37620/main@d9f5eaf)

dbarbosapn @dbarbosapn d9f5eaf #37620 merge main@5cccef9

[redis_proxy] Add support for UNWATCH

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: ✅

Environment

Request variables

Key Value
ref e84bbc4
sha d9f5eaf
pr 37620
base-sha 5cccef9
actor dbarbosapn @dbarbosapn
message [redis_proxy] Add support for UNWATCH...
started 1734453535.08544
target-branch main
trusted false
Build image

Container image/s (as used in this CI run)

Key Value
default envoyproxy/envoy-build-ubuntu:246094216be818bc56f1f7f30d3c08b5209ab125
mobile envoyproxy/envoy-build-ubuntu:mobile-246094216be818bc56f1f7f30d3c08b5209ab125
Version

Envoy version (as used in this CI run)

Key Value
major 1
minor 33
patch 0
dev true