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

Support watch/unwatch commands #1279

Merged
merged 15 commits into from
Mar 7, 2023
Merged

Conversation

PragmaTwice
Copy link
Member

@PragmaTwice PragmaTwice commented Feb 24, 2023

It closes #315.

As described in #315 (comment), we follow the "by command & key tracing" method instead of "by snapshots".

NOTE: key expire / rocksdb storage change monitoring has not been implemented

@git-hulk
Copy link
Member

git-hulk commented Feb 27, 2023

This PR is generally good for me, to see if other folks have comments. @torwig @ShooterIT @caipengbo

@PragmaTwice PragmaTwice marked this pull request as ready for review March 6, 2023 16:51
@git-hulk
Copy link
Member

git-hulk commented Mar 7, 2023

There's one corner case that may also modify the key as well:

so we should also update them if the key is modified, others are good to me.

@PragmaTwice PragmaTwice added the feature type new feature label Mar 7, 2023
@PragmaTwice
Copy link
Member Author

There's one corner case that may also modify the key as well:

so we should also update them if the key is modified, others are good to me.

Done.

@PragmaTwice
Copy link
Member Author

Thanks all. Merging...

Feel free to open an issue if there is anything you are concerning about this PR later.

@PragmaTwice PragmaTwice merged commit dfe5733 into apache:unstable Mar 7, 2023
Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

So, here it has:

Server:
watched shared lock
map: <key, connections>
watched_key_size_

Connection:
1. watch changed
2. watched key sets

All watched data is controlled by shared lock in Server, and only the function modify the Server maping would grab the write-lock. Am I right?

src/server/server.cc Show resolved Hide resolved
Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

Rest LGTM

src/commands/cmd_txn.cc Show resolved Hide resolved
@mapleFU
Copy link
Member

mapleFU commented Mar 7, 2023

Great work!

enjoy-binbin added a commit to enjoy-binbin/kvrocks that referenced this pull request 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 apache#1279
git-hulk pushed a commit that referenced this pull request Jul 11, 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
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 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
feature type new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Watch/Unwatch
3 participants