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

Fix EXEC / DISCARD without MULTI wrongly reset watch #1562

Merged
merged 6 commits into from
Jul 11, 2023

Conversation

enjoy-binbin
Copy link
Member

@enjoy-binbin enjoy-binbin commented Jul 7, 2023

The old code call ResetWatchedKeys before the error, and then
ResetWatchedKeys reset watched_keys_modified flag which cause
the following inconsistencies (with Redis).

kvrocks output:

127.0.0.1:6666> watch a
OK
127.0.0.1:6666> watch b     ->>> other client touch a
OK
127.0.0.1:6666> exec
(error) ERR EXEC without MULTI
127.0.0.1:6666> multi
OK
127.0.0.1:6666(TX)> ping
QUEUED
127.0.0.1:6666(TX)> exec
1) PONG

redis output:

127.0.0.1:6379> watch a
OK
127.0.0.1:6379> watch b     ->>> other client touch a
OK
127.0.0.1:6379> exec
(error) ERR EXEC without MULTI
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> ping
QUEUED
127.0.0.1:6379(TX)> exec
(nil)

Introduced in #1279

The old code call ResetWatchedKeys before the error, and then
ResetWatchedKeys reset watched_keys_modified flag which cause
the following inconsistencies (with Redis).

kvrocks output:
```
127.0.0.1:6666> watch a
OK
127.0.0.1:6666> watch b     ->>> other client touch a
OK
127.0.0.1:6666> exec
(error) ERR EXEC without MULTI
127.0.0.1:6666> multi
OK
127.0.0.1:6666(TX)> ping
QUEUED
127.0.0.1:6666(TX)> exec
1) PONG
```

redis output:
```
127.0.0.1:6379> watch a
OK
127.0.0.1:6379> watch b     ->>> other client touch a
OK
127.0.0.1:6379> exec
(error) ERR EXEC without MULTI
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> ping
QUEUED
127.0.0.1:6379(TX)> exec
(nil)
````

Introduced in apache#1279
git-hulk
git-hulk previously approved these changes Jul 7, 2023
@git-hulk git-hulk requested review from torwig and PragmaTwice July 7, 2023 11:26
@enjoy-binbin
Copy link
Member Author

enjoy-binbin commented Jul 7, 2023

ok now i see DISCARD also have the same problem, should I fix it together in this PR, or in a new PR?

@git-hulk
Copy link
Member

git-hulk commented Jul 7, 2023

ok now i see DISCARD also have the same problem, should I fix it together in this PR, or in a new PR?

It’s fine to append a new commit.☺️

@enjoy-binbin enjoy-binbin changed the title Fix EXEC without MULTI wrongly reset watch Fix EXEC / DISCARD without MULTI wrongly reset watch Jul 8, 2023
@enjoy-binbin
Copy link
Member Author

i see there is a flaky test:
https://github.com/apache/kvrocks/actions/runs/5495230368/jobs/10014556657?pr=1562#step:12:114

--- FAIL: TestString (46.13s)
    server.go:109: 
        	Error Trace:	/Users/runner/work/kvrocks/kvrocks/tests/gocase/unit/type/strings/server.go:109
        	            				/Users/runner/work/kvrocks/kvrocks/tests/gocase/unit/type/strings/server.go:112
        	            				/Users/runner/work/kvrocks/kvrocks/tests/gocase/unit/type/strings/server.go:101
        	            				/Users/runner/work/kvrocks/kvrocks/tests/gocase/unit/type/strings/strings_test.go:742
        	Error:      	An error is expected but got nil.
        	Test:       	TestString
FAIL
exit status 1

But from the error message, it seems that it is hard to see which case failed (or which line failed). or i am searching it wrong?

@PragmaTwice PragmaTwice added the fix label Jul 9, 2023
@PragmaTwice PragmaTwice added the A-transaction area transaction label Jul 10, 2023
@git-hulk git-hulk merged commit 2c3aed3 into apache:unstable Jul 11, 2023
@enjoy-binbin enjoy-binbin deleted the fix_exec_reset_watch branch July 11, 2023 14:06
git-hulk pushed a commit to git-hulk/kvrocks that referenced this pull request Jul 30, 2023
The old code called ResetWatchedKeys before the error, and then
ResetWatchedKeys reset the watched_keys_modified flag which causes
the following inconsistencies (with Redis).

kvrocks output:
```
127.0.0.1:6666> watch a
OK
127.0.0.1:6666> watch b     ->>> other client touch a
OK
127.0.0.1:6666> exec
(error) ERR EXEC without MULTI
127.0.0.1:6666> multi
OK
127.0.0.1:6666(TX)> ping
QUEUED
127.0.0.1:6666(TX)> exec
1) PONG
```

redis output:
```
127.0.0.1:6379> watch a
OK
127.0.0.1:6379> watch b     ->>> other client touch a
OK
127.0.0.1:6379> exec
(error) ERR EXEC without MULTI
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> ping
QUEUED
127.0.0.1:6379(TX)> exec
(nil)
````

Introduced in apache#1279
@git-hulk git-hulk mentioned this pull request Jul 31, 2023
git-hulk pushed a commit that referenced this pull request Aug 1, 2023
The old code called ResetWatchedKeys before the error, and then
ResetWatchedKeys reset the watched_keys_modified flag which causes
the following inconsistencies (with Redis).

kvrocks output:
```
127.0.0.1:6666> watch a
OK
127.0.0.1:6666> watch b     ->>> other client touch a
OK
127.0.0.1:6666> exec
(error) ERR EXEC without MULTI
127.0.0.1:6666> multi
OK
127.0.0.1:6666(TX)> ping
QUEUED
127.0.0.1:6666(TX)> exec
1) PONG
```

redis output:
```
127.0.0.1:6379> watch a
OK
127.0.0.1:6379> watch b     ->>> other client touch a
OK
127.0.0.1:6379> exec
(error) ERR EXEC without MULTI
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> ping
QUEUED
127.0.0.1:6379(TX)> exec
(nil)
````

Introduced in #1279
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transaction area transaction
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants