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

Nested MULTI or WATCH in MULTI now will abort the transaction #723

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

enjoy-binbin
Copy link
Member

@enjoy-binbin enjoy-binbin commented Jul 1, 2024

Currently, for nested MULTI or executing WATCH in MULTI, we will return
an error but we will not abort the transaction.

127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> multi
(error) ERR MULTI calls can not be nested
127.0.0.1:6379(TX)> set key value
QUEUED
127.0.0.1:6379(TX)> exec
1) OK

127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> watch key
(error) ERR WATCH inside MULTI is not allowed
127.0.0.1:6379(TX)> set key value
QUEUED
127.0.0.1:6379(TX)> exec
1) OK

This is an unexpected behavior that should abort the transaction.
The number of elements returned by EXEC also doesn't match the number
of commands in MULTI.
Add the NO_MULTI flag to them so that they will
be rejected in processCommand and rejectCommand will abort the transaction.

So there are two visible changes:

  • Different words in the error messages. (Command not allowed inside a transaction)
  • Exec returns error.

Currently, for nested multi or executing watch in multi, we will return
an error but we will not abort the transaction.
```
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> multi
(error) ERR MULTI calls can not be nested127.0.0.1:6379(TX)> set key value
QUEUED
127.0.0.1:6379(TX)> exec
1) OK

127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> watch key
(error) ERR WATCH inside MULTI is not allowed
127.0.0.1:6379(TX)> set key value
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
```

In theory, this is also a syntax error, an unexpected behavior should
abort the transaction. Add the NO_MULTI flag to them so that they will
be rejected in processCommand and rejectCommand will abort the transaction.

Signed-off-by: Binbin <[email protected]>
@enjoy-binbin enjoy-binbin requested a review from zuiderkwast July 1, 2024 11:32
Copy link

codecov bot commented Jul 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.12%. Comparing base (2420881) to head (5a75d7e).
Report is 3 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable     #723      +/-   ##
============================================
- Coverage     70.25%   70.12%   -0.14%     
============================================
  Files           111      111              
  Lines         60242    60236       -6     
============================================
- Hits          42326    42240      -86     
- Misses        17916    17996      +80     
Files Coverage Δ
src/commands.def 100.00% <ø> (ø)
src/multi.c 97.03% <ø> (-0.08%) ⬇️

... and 11 files with indirect coverage changes

Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

I agree.

So there are two visible changes:

  • Different words in the error messages
  • Exec returns error

@zuiderkwast zuiderkwast added the breaking-change Indicates a possible backwards incompatible change label Jul 1, 2024
@zuiderkwast
Copy link
Contributor

@madolson Let's merge it?

@enjoy-binbin Can you edit the title to focus on the visible difference for the users?

@zuiderkwast zuiderkwast added the release-notes This issue should get a line item in the release notes label Jul 1, 2024
@madolson
Copy link
Member

madolson commented Jul 1, 2024

I'm ok merging it.

@enjoy-binbin enjoy-binbin changed the title Add NO_MULTI flag to MULTI / WATCH to make them abort transactions Nested MULTI or executing WATCH in MULTI now will abort the transaction Jul 2, 2024
@enjoy-binbin
Copy link
Member Author

@enjoy-binbin Can you edit the title to focus on the visible difference for the users?

@zuiderkwast please take a look, you can fix it if necessary (i am not really good at it.)

@zuiderkwast
Copy link
Contributor

@enjoy-binbin Can you edit the title to focus on the visible difference for the users?

@zuiderkwast please take a look, you can fix it if necessary (i am not really good at it.)

Hehe, it's good! 😄

@zuiderkwast zuiderkwast changed the title Nested MULTI or executing WATCH in MULTI now will abort the transaction Nested MULTI or WATCH in MULTI now will abort the transaction Jul 3, 2024
@zuiderkwast zuiderkwast merged commit 6bf1d02 into valkey-io:unstable Jul 3, 2024
20 checks passed
@enjoy-binbin enjoy-binbin deleted the multi_watch branch July 4, 2024 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a possible backwards incompatible change release-notes This issue should get a line item in the release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants