-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: client tracking optout #3158
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,7 +466,8 @@ void ClientTracking(CmdArgList args, ConnectionContext* cntx) { | |
return cntx->SendError(kSyntaxErr); | ||
|
||
bool is_on = false; | ||
bool optin = false; | ||
using Tracking = ConnectionState::ClientTracking; | ||
Tracking::Options option = Tracking::NONE; | ||
if (parser.Check("ON").IgnoreCase()) { | ||
is_on = true; | ||
} else if (!parser.Check("OFF").IgnoreCase()) { | ||
|
@@ -475,7 +476,9 @@ void ClientTracking(CmdArgList args, ConnectionContext* cntx) { | |
|
||
if (parser.HasNext()) { | ||
if (parser.Check("OPTIN").IgnoreCase()) { | ||
optin = true; | ||
option = Tracking::OPTIN; | ||
} else if (parser.Check("OPTOUT").IgnoreCase()) { | ||
option = Tracking::OPTOUT; | ||
} else { | ||
return cntx->SendError(kSyntaxErr); | ||
} | ||
|
@@ -485,7 +488,7 @@ void ClientTracking(CmdArgList args, ConnectionContext* cntx) { | |
++cntx->subscriptions; | ||
} | ||
cntx->conn_state.tracking_info_.SetClientTracking(is_on); | ||
cntx->conn_state.tracking_info_.SetOptin(optin); | ||
cntx->conn_state.tracking_info_.SetOption(option); | ||
return cntx->SendOk(); | ||
} | ||
|
||
|
@@ -499,16 +502,26 @@ void ClientCaching(CmdArgList args, ConnectionContext* cntx) { | |
return cntx->SendError(kSyntaxErr); | ||
} | ||
|
||
using Tracking = ConnectionState::ClientTracking; | ||
CmdArgParser parser{args}; | ||
if (parser.Check("YES").IgnoreCase()) { | ||
bool is_multi = cntx->transaction && cntx->transaction->IsMulti(); | ||
cntx->conn_state.tracking_info_.SetCachingSequenceNumber(is_multi); | ||
if (!cntx->conn_state.tracking_info_.HasOption(Tracking::OPTIN)) { | ||
return cntx->SendError( | ||
"ERR CLIENT CACHING YES is only valid when tracking is enabled in OPTIN mode"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compatibility! We previously allowed this! |
||
} | ||
} else if (parser.Check("NO").IgnoreCase()) { | ||
if (!cntx->conn_state.tracking_info_.HasOption(Tracking::OPTOUT)) { | ||
return cntx->SendError( | ||
"ERR CLIENT CACHING NO is only valid when tracking is enabled in OPTOUT mode"); | ||
} | ||
cntx->conn_state.tracking_info_.ResetCachingSequenceNumber(); | ||
} else { | ||
return cntx->SendError(kSyntaxErr); | ||
} | ||
|
||
bool is_multi = cntx->transaction && cntx->transaction->IsMulti(); | ||
cntx->conn_state.tracking_info_.SetCachingSequenceNumber(is_multi); | ||
|
||
cntx->SendOk(); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,6 +211,14 @@ TEST_F(ServerFamilyTest, ClientTrackingOnAndOff) { | |
resp = Run({"CLIENT", "TRACKING", "ON"}); | ||
EXPECT_THAT(resp.GetString(), "OK"); | ||
|
||
resp = Run({"CLIENT", "CACHING", "YES"}); | ||
EXPECT_THAT( | ||
resp, ErrArg("ERR CLIENT CACHING YES is only valid when tracking is enabled in OPTIN mode")); | ||
|
||
resp = Run({"CLIENT", "CACHING", "NO"}); | ||
EXPECT_THAT( | ||
resp, ErrArg("ERR CLIENT CACHING NO is only valid when tracking is enabled in OPTOUT mode")); | ||
|
||
// case 3. turn off client tracking | ||
resp = Run({"CLIENT", "TRACKING", "OFF"}); | ||
EXPECT_THAT(resp.GetString(), "OK"); | ||
|
@@ -347,7 +355,6 @@ TEST_F(ServerFamilyTest, ClientTrackingMultiOptin) { | |
Run({"SET", "TMP", "10"}); | ||
Run({"CLIENT", "CACHING", "YES"}); | ||
Run({"GET", "FOO"}); | ||
Run({"CLIENT", "CACHING", "NO"}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was a bug! It should have been rejected! |
||
Run({"GET", "BAR"}); | ||
Run({"EXEC"}); | ||
|
||
|
@@ -357,7 +364,51 @@ TEST_F(ServerFamilyTest, ClientTrackingMultiOptin) { | |
EXPECT_EQ(InvalidationMessagesLen("IO0"), 5); | ||
Run({"SET", "BAR", "10"}); | ||
Run({"GET", "BAR"}); | ||
EXPECT_EQ(InvalidationMessagesLen("IO0"), 5); | ||
EXPECT_EQ(InvalidationMessagesLen("IO0"), 6); | ||
} | ||
|
||
TEST_F(ServerFamilyTest, ClientTrackingOptout) { | ||
Run({"HELLO", "3"}); | ||
// Check stickiness | ||
Run({"CLIENT", "TRACKING", "ON", "OPTOUT"}); | ||
Run({"GET", "FOO"}); | ||
Run({"SET", "FOO", "BAR"}); | ||
Run({"GET", "BAR"}); | ||
Run({"SET", "BAR", "FOO"}); | ||
EXPECT_EQ(InvalidationMessagesLen("IO0"), 2); | ||
|
||
// Switch off tracking for a single command | ||
Run({"CLIENT", "CACHING", "NO"}); | ||
Run({"GET", "FOO"}); | ||
Run({"SET", "FOO", "BAR"}); | ||
EXPECT_EQ(InvalidationMessagesLen("IO0"), 2); | ||
} | ||
|
||
TEST_F(ServerFamilyTest, ClientTrackingMultiOptout) { | ||
Run({"HELLO", "3"}); | ||
// Check stickiness | ||
Run({"CLIENT", "TRACKING", "ON", "OPTOUT"}); | ||
|
||
Run({"MULTI"}); | ||
Run({"GET", "FOO"}); | ||
Run({"SET", "TMP", "10"}); | ||
Run({"GET", "FOOBAR"}); | ||
Run({"EXEC"}); | ||
|
||
Run({"SET", "FOO", "10"}); | ||
Run({"SET", "FOOBAR", "10"}); | ||
EXPECT_EQ(InvalidationMessagesLen("IO0"), 2); | ||
|
||
// CACHING enclosed in MULTI | ||
Run({"MULTI"}); | ||
Run({"CLIENT", "CACHING", "NO"}); | ||
Run({"GET", "TMP"}); | ||
Run({"GET", "TMP_TMP"}); | ||
Run({"SET", "TMP", "10"}); | ||
Run({"SET", "TMP_TMP", "10"}); | ||
Run({"EXEC"}); | ||
|
||
EXPECT_EQ(InvalidationMessagesLen("IO0"), 2); | ||
} | ||
|
||
TEST_F(ServerFamilyTest, ClientTrackingUpdateKey) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so by default we always track keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes when tracking is on