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(string): reset the value of expired key for SETRANGE cmd #2686

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

weim0000
Copy link
Contributor

@weim0000 weim0000 commented Dec 2, 2024

reset the value of expired key to prevent the following parsing and calculation.
`127.0.0.1:6003> set k v
OK
127.0.0.1:6003> expire k 1
(integer) 1

after 2 seconds

127.0.0.1:6003> get k
(nil)
127.0.0.1:6003> setrange k 1 aa
(integer) 10
127.0.0.1:6003> get k
(nil)
127.0.0.1:6003> exists k
(integer) 0
127.0.0.1:6003>`

1 set value with expire time.
2 wait until the key expires
3 use setrange to this key. The cmd be successful, but get k return nil

What did you expect to see?

127.0.0.1:6003> set k v
OK
127.0.0.1:6003> expire k 1
(integer) 1
127.0.0.1:6003> get k
(nil)
127.0.0.1:6003> setrange k 0 aa
(integer) 10
127.0.0.1:6003> get k
aa
127.0.0.1:6003> exists k
(integer) 1
127.0.0.1:6003>

@git-hulk git-hulk changed the title fix(string):reset the value of expired key for setrange cmd fix(string): reset the value of expired key for SETRANGE cmd Dec 2, 2024
@git-hulk
Copy link
Member

git-hulk commented Dec 2, 2024

@weim0000 Thanks for your fix, would you mind adding a test case to cover this? https://github.com/apache/kvrocks/blob/unstable/tests/gocase/unit/type/strings/strings_test.go

@weim0000
Copy link
Contributor Author

weim0000 commented Dec 2, 2024

@weim0000 Thanks for your fix, would you mind adding a test case to cover this? https://github.com/apache/kvrocks/blob/unstable/tests/gocase/unit/type/strings/strings_test.go

Ok, no problem. I will add the test cases ASAP

@@ -297,6 +297,7 @@ rocksdb::Status String::SetRange(engine::Context &ctx, const std::string &user_k
}

Metadata metadata(kRedisString, false);
raw_value.clear();
Copy link
Member

@git-hulk git-hulk Dec 2, 2024

Choose a reason for hiding this comment

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

I think it'd be better to clear the raw_value inside getRawValue if the return status isn't ok. Because we call getRawValue many times and it's hard to keep having an eye on this. @torwig @PragmaTwice @mapleFU What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

@git-hulk Valid point. Since the value has expired, we should return "nothing" (empty) to the caller of getRawValue.

Copy link
Member

Choose a reason for hiding this comment

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

Good to me. Actually refactor them to StatusOr can solve the problem, but I don't have much time to do that.

Copy link

sonarcloud bot commented Dec 3, 2024

@git-hulk git-hulk merged commit 1ed45bc into apache:unstable Dec 3, 2024
33 checks passed
@git-hulk
Copy link
Member

git-hulk commented Dec 3, 2024

@weim0000 Thanks for your fix.

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.

4 participants