-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
test: fix multi bug and compatible ACL test #2815
test: fix multi bug and compatible ACL test #2815
Conversation
WalkthroughThe recent updates to the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
include/pika_client_conn.h (1)
102-102
: Update documentation for the new method signature.The method
SetTxnFailedIfKeyExists(const std::string target_db_name = "")
has replacedSetAllTxnFailed()
andSetTxnFailedFromDBs(std::string db_name)
. Ensure that the documentation reflects this change and explains the new functionality clearly./** * Set the transaction as failed if the specified key exists in the target database. * @param target_db_name The name of the target database. If empty, checks the current database. */ void SetTxnFailedIfKeyExists(const std::string target_db_name = "");
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- include/pika_client_conn.h (1 hunks)
- pikatests.sh (1 hunks)
- src/pika_client_conn.cc (2 hunks)
- src/pika_transaction.cc (2 hunks)
- tests/assets/default.conf (4 hunks)
- tests/conf/pika.conf (13 hunks)
- tests/test_helper.tcl (4 hunks)
- tests/unit/type/multi.tcl (1 hunks)
Additional comments not posted (35)
pikatests.sh (1)
48-48
: Ensure the new configuration path is correct.The configuration file path has been updated to
tests/conf/pika.conf
. Make sure this path is correct and the file exists at this location.Verification successful
The new configuration path is correct.
The configuration file
tests/conf/pika.conf
exists at the specified location.
tests/conf/pika.conf
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence of the new configuration file path. # Test: Check if the configuration file exists at the new path. if [ ! -f tests/conf/pika.conf ]; then echo "Configuration file not found at tests/conf/pika.conf" exit 1 fi echo "Configuration file exists at tests/conf/pika.conf"Length of output: 146
src/pika_transaction.cc (3)
60-60
: Conditional transaction failure handling.The method
SetTxnFailedIfKeyExists()
conditionally sets the transaction state based on the existence of a key, which is a more efficient approach than the previousSetAllTxnFailed()
.
67-67
: Ensure correct database name is used.The method
SetTxnFailedIfKeyExists(each_cmd_info.db_->GetDBName())
ensures that the transaction failure is set based on the existence of a key in the specified database. Verify thateach_cmd_info.db_->GetDBName()
returns the correct database name.
261-261
: Update key format in WatchCmd.The key format in
WatchCmd::DoInitial()
has been updated to concatenate an underscore with the database name and the key. Ensure that this change is consistent with the rest of the codebase and does not break any functionality.Verification successful
Update key format in WatchCmd verified.
The key format in
WatchCmd::DoInitial()
has been updated correctly, and no inconsistencies or broken functionalities were found in the codebase.
- The new key format is only present in
WatchCmd::DoInitial()
.- No instances of the old key format were found.
WatchCmd::DoInitial()
is not used elsewhere in the codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the consistency of the new key format in the codebase. # Test: Search for instances of the old and new key formats to ensure consistency. rg --type cpp -A 5 $'db_name() + "_" +'Length of output: 40
Script:
#!/bin/bash # Description: Verify the consistency of the new key format in the codebase. # Search for instances of the new key format. echo "Searching for the new key format:" rg --type cpp 'db_name() + "_" +' # Search for instances of the old key format. echo "Searching for the old key format:" rg --type cpp 'db_name() + argv_['Length of output: 323
Script:
#!/bin/bash # Description: Verify the consistency of the new key format in the codebase. # Search for instances of the new key format. echo "Searching for the new key format:" rg --type cpp 'db_name() + "_" +' # Search for instances of the old key format. echo "Searching for the old key format:" rg --type cpp 'db_name() \+ argv_\['Length of output: 228
Script:
#!/bin/bash # Description: Verify the consistency of the new key format in the codebase and check for usage of the WatchCmd::DoInitial() method. # Search for variations of the new key format. echo "Searching for variations of the new key format:" rg --type cpp 'db_name\(\)\s*\+\s*"_"\s*\+\s*argv_' # Search for variations of the old key format. echo "Searching for variations of the old key format:" rg --type cpp 'db_name\(\)\s*\+\s*argv_' # Check for usage of the WatchCmd::DoInitial() method. echo "Checking for usage of the WatchCmd::DoInitial() method:" rg --type cpp 'WatchCmd::DoInitial'Length of output: 595
tests/test_helper.tcl (3)
34-34
: Reorganization of test cases.The
unit/type/multi
test case has been reintroduced to the::all_tests
set, indicating a reorganization rather than a removal.
82-82
: New global variable::tls
added.The global variable
::tls
has been introduced and initialized to0
, likely indicating a configuration related to TLS support in the Redis client connection.
182-200
: New procedureredis_client
added.The
redis_client
procedure facilitates the creation of a Redis client, managing the connection to the Redis server and handling database selection or server pinging based on the::singledb
flag.src/pika_client_conn.cc (3)
190-190
: Command name logging added before execution.Logging the command names before execution enhances traceability of command execution.
193-195
: Updated handling ofFlushdb
andFlushall
commands.The
Flushdb
andFlushall
commands now useSetTxnFailedIfKeyExists
, ensuring that transaction failures are set based on the existence of keys in the target database.
397-425
: New methodSetTxnFailedIfKeyExists
added.The method checks if a key exists in the target database before setting the transaction failure state, enhancing control flow by ensuring failures are set judiciously.
tests/assets/default.conf (3)
41-46
: Revised comments forsync-binlog-thread-num
.The comments now emphasize the importance of aligning
sync-binlog-thread-num
with the number of databases for optimal performance.
320-323
: New parametermax-total-wal-size
added.The
max-total-wal-size
parameter specifies the maximum size of Write-Ahead Log (WAL) files, helping manage the flushing behavior of RocksDB during operation.
487-490
: New parameterrsync-timeout-ms
added.The
rsync-timeout-ms
parameter outlines the timeout settings for Rsync during the full sync stage and includes instructions for dynamic modification.tests/conf/pika.conf (12)
10-10
: LGTM!The
db-instance-num
parameter is correctly set to 3.
11-11
: LGTM!The
rocksdb-ttl-second
parameter is correctly set to86400 * 7
(7 days).
12-12
: LGTM!The
rocksdb-periodic-second
parameter is correctly set to86400 * 3
(3 days).
46-46
: LGTM!The
sync-binlog-thread-num
parameter is correctly set to 1.
113-113
: LGTM!The
databases
parameter is correctly updated to 3.
241-241
: LGTM!The
disable_auto_compactions
parameter is correctly set to false.
244-244
: LGTM!The
max-subcompactions
parameter is correctly set to 1.
380-380
: LGTM!The
slotmigrate-thread-num
parameter is correctly set to 1.
383-383
: LGTM!The
thread-migrate-keys-num
parameter is correctly set to 64.
490-490
: LGTM!The
rsync-timeout-ms
parameter is correctly set to 1000 ms.
507-507
: LGTM!The
cache-type
parameter is correctly updated to includebit
.
485-485
: LGTM!The
throttle-bytes-per-second
parameter is correctly set to 207200000.tests/unit/type/multi.tcl (10)
1-9
: LGTM!The
wait_for_dbsize
procedure is correctly implemented and useful for ensuring database size consistency during tests.
12-23
: LGTM!The
MULTI / EXEC basics
test case is correctly implemented and covers essential operations.
24-35
: LGTM!The
DISCARD
test case is correctly implemented and covers essential operations.
36-43
: LGTM!The
Nested MULTI are not allowed
test case is correctly implemented and ensures that nested MULTI commands are rejected.
44-50
: LGTM!The
MULTI where commands alter argc/argv
test case is correctly implemented and covers essential operations.
51-58
: LGTM!The
WATCH inside MULTI is not allowed
test case is correctly implemented and ensures that WATCH commands are rejected within a MULTI block.
59-68
: LGTM!The
EXEC fails if there are errors while queueing commands #1
test case is correctly implemented and ensures that EXEC fails in the presence of errors.
88-97
: LGTM!The
If EXEC aborts, the client MULTI state is cleared
test case is correctly implemented and ensures that the client MULTI state is cleared if EXEC aborts.
99-105
: LGTM!The
EXEC works on WATCHed key not modified
test case is correctly implemented and ensures that EXEC works correctly on unmodified WATCHed keys.
107-114
: LGTM!The
EXEC fail on WATCHed key modified (1 key of 1 watched)
test case is correctly implemented and ensures that EXEC fails correctly on modified WATCHed 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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- include/pika_client_conn.h (1 hunks)
- pikatests.sh (1 hunks)
- src/pika_client_conn.cc (3 hunks)
- src/pika_transaction.cc (2 hunks)
- tests/assets/default.conf (4 hunks)
- tests/conf/pika.conf (13 hunks)
- tests/test_helper.tcl (4 hunks)
- tests/unit/type/multi.tcl (1 hunks)
Additional comments not posted (58)
pikatests.sh (1)
48-48
: Verify the existence of the new configuration file path.The configuration file path has been updated from
conf/pika.conf
totests/conf/pika.conf
. Ensure that the new path is correct and the configuration file exists in the specified location.Verification successful
The new configuration file path exists.
The configuration file
tests/conf/pika.conf
is present in the specified location.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence of the new configuration file path. # Test: Check if the new configuration file exists. if [ ! -f "tests/conf/pika.conf" ]; then echo "Configuration file tests/conf/pika.conf not found." exit 1 fiLength of output: 37
include/pika_client_conn.h (1)
102-102
: Ensure the new methodSetTxnFailedIfKeyExists
is implemented correctly.The method signature has been updated to
SetTxnFailedIfKeyExists(const std::string target_db_name = "")
. Ensure that the implementation of this method is consistent with the new functionality.Verification successful
The method
SetTxnFailedIfKeyExists
is implemented correctly.The implementation of
SetTxnFailedIfKeyExists
insrc/pika_client_conn.cc
aligns with the new functionality specified in the method signature. The method dynamically casts the server thread to aDispatchThread
, retrieves all transactions, and iterates through them to check if any watched keys exist in the specified database. If a key exists, it sets the transaction watch state to failed.
- Implementation Location:
src/pika_client_conn.cc
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of the new method `SetTxnFailedIfKeyExists`. # Test: Search for the implementation of the new method. rg --type cpp --type c++ --type c -A 10 $'void PikaClientConn::SetTxnFailedIfKeyExists'Length of output: 116
Script:
#!/bin/bash # Description: Verify the implementation of the new method `SetTxnFailedIfKeyExists`. # Test: Search for the implementation of the new method. rg --type cpp --type c -A 10 $'void PikaClientConn::SetTxnFailedIfKeyExists'Length of output: 762
Script:
#!/bin/bash # Description: Extract the full implementation of the `SetTxnFailedIfKeyExists` method. # Test: Search for the full implementation of the method. rg --type cpp --type c -A 50 $'void PikaClientConn::SetTxnFailedIfKeyExists' src/pika_client_conn.ccLength of output: 1704
src/pika_transaction.cc (3)
67-67
: Ensure the new transaction failure handling logic is correct forFlushdb
.The method call has been updated to
client_conn->SetTxnFailedIfKeyExists(each_cmd_info.db_->GetDBName())
for theFlushdb
command. Ensure that the new logic is correctly implemented and consistent with the overall functionality.Verification successful
Ensure the new transaction failure handling logic is correct for
Flushdb
.The
SetTxnFailedIfKeyExists
method is implemented insrc/pika_client_conn.cc
and is used in the context of theFlushdb
command. The method checks for existing transactions and sets a failure state if necessary. Based on the gathered information, the logic appears to be correctly implemented and consistent with the overall functionality.
src/pika_transaction.cc
: CallsSetTxnFailedIfKeyExists
for theFlushdb
command.src/pika_client_conn.cc
: Contains the implementation ofSetTxnFailedIfKeyExists
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new transaction failure handling logic for the `Flushdb` command. # Test: Search for the usage of `SetTxnFailedIfKeyExists` in the `ExecCmd::Do()` method. rg --type cpp --type c++ --type c -A 10 $'ExecCmd::Do' | rg 'SetTxnFailedIfKeyExists'Length of output: 110
Script:
#!/bin/bash # Description: Verify the new transaction failure handling logic for the `Flushdb` command. # Test: Search for the usage of `SetTxnFailedIfKeyExists` in the `ExecCmd::Do()` method. rg --type cpp -A 10 $'ExecCmd::Do' | rg 'SetTxnFailedIfKeyExists'Length of output: 62
Script:
#!/bin/bash # Description: Verify the new transaction failure handling logic for the `Flushdb` command. # Test: Search for all occurrences of `SetTxnFailedIfKeyExists` in the codebase to understand its usage context. rg 'SetTxnFailedIfKeyExists' --type cpp -A 10Length of output: 3184
261-261
: Ensure the new key formatting logic is correct.The key formatting has been updated to
db_name() + "_" + argv_[pos++]
. Ensure that the new logic is correctly implemented and consistent with the overall functionality.Verification successful
New key formatting logic is correctly implemented.
The key formatting logic
db_name() + "_" + argv_[pos++]
is correctly used in theWatchCmd::DoInitial
method.
- Location:
src/pika_transaction.cc
, line 261Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new key formatting logic. # Test: Search for the usage of `db_name() + "_" + argv_[pos++]` in the `WatchCmd::DoInitial()` method. rg --type cpp --type c++ --type c -A 10 $'WatchCmd::DoInitial' | rg 'db_name() + "_" + argv_'Length of output: 120
Script:
#!/bin/bash # Description: Verify the new key formatting logic. # Test: Search for the usage of `db_name() + "_" + argv_[pos++]` in the `WatchCmd::DoInitial()` method. rg --type cpp -A 10 $'WatchCmd::DoInitial' | rg 'db_name() + "_" + argv_'Length of output: 72
Script:
#!/bin/bash # Description: Verify the new key formatting logic by searching for `db_keys_` and `DoInitial` method. # Search for the definition and usage of `db_keys_` rg --type cpp 'db_keys_' -A 5 # Search for the implementation of `DoInitial` method rg --type cpp 'DoInitial' -A 10Length of output: 210976
60-60
: Ensure the new transaction failure handling logic is correct.The method call has been updated to
client_conn->SetTxnFailedIfKeyExists()
for theFlushall
command. Ensure that the new logic is correctly implemented and consistent with the overall functionality.Verification successful
The new transaction failure handling logic for the
Flushall
command is correctly implemented.The method
SetTxnFailedIfKeyExists
is properly defined and used within the context of transaction-related commands, includingFlushall
. The logic ensures that transactions are marked as failed when necessary.
Implementation of
SetTxnFailedIfKeyExists
:
- Located in
src/pika_client_conn.cc
.- Checks for active transactions and marks them as failed if certain conditions are met.
Usage in
pika_transaction.cc
:
- Called for
Flushall
andFlushdb
commands to handle transaction failures appropriately.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the new transaction failure handling logic for the `Flushall` command. # Test: Search for the usage of `SetTxnFailedIfKeyExists` in the `ExecCmd::Do()` method. rg --type cpp --type c++ --type c -A 10 $'ExecCmd::Do' | rg 'SetTxnFailedIfKeyExists'Length of output: 110
Script:
#!/bin/bash # Description: Verify the new transaction failure handling logic for the `Flushall` command. # Test: Search for the usage of `SetTxnFailedIfKeyExists` in the `ExecCmd::Do()` method. rg --type cpp -A 10 $'ExecCmd::Do' | rg 'SetTxnFailedIfKeyExists'Length of output: 62
Script:
#!/bin/bash # Description: Verify the new transaction failure handling logic for the `Flushall` command. # Test: Search for the usage of `SetTxnFailedIfKeyExists` across the entire codebase. rg --type cpp 'SetTxnFailedIfKeyExists'Length of output: 545
Script:
#!/bin/bash # Extract the implementation of `SetTxnFailedIfKeyExists` from `pika_client_conn.cc` rg --type cpp -A 10 'void PikaClientConn::SetTxnFailedIfKeyExists' src/pika_client_conn.cc # Extract the surrounding context of `SetTxnFailedIfKeyExists` calls in `pika_transaction.cc` rg --type cpp -A 10 'SetTxnFailedIfKeyExists' src/pika_transaction.ccLength of output: 1236
tests/test_helper.tcl (3)
82-82
: Verify the usage of the new global variable::tls
.Ensure that the new global variable
::tls
is used correctly in the code and does not cause any issues.Verification successful
The global variable
::tls
is not currently used in theredis
function implementation.
tests/test_helper.tcl
(initialization and usage)tests/instances.tcl
(usage)tests/support/redis.tcl
(function definition)Based on the current implementation, the
::tls
parameter does not impact theredis
function.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of the new global variable `::tls`. # Test: Search for the usage of the `::tls` variable in the codebase. rg --type tcl '::tls'Length of output: 213
Script:
#!/bin/bash # Description: Locate the definition and usage of the `redis` function to ensure it correctly handles the `::tls` parameter. # Test: Search for the definition of the `redis` function in the codebase. rg --type tcl 'proc redis'Length of output: 276
Script:
#!/bin/bash # Description: Extract the implementation of the `redis` function from `tests/support/redis.tcl`. # Test: Extract the `redis` function implementation. rg --type tcl -A 20 'proc redis' tests/support/redis.tclLength of output: 1006
182-200
: Verify the functionality of the newredis_client
procedure.Ensure that the new procedure works correctly and handles all edge cases, including the use of the
::tls
and::singledb
variables.Verification successful
The functionality of the new
redis_client
procedure has been verified.The
redis_client
procedure and the associated::tls
and::singledb
variables are used correctly within the test files. The procedure works as intended to create Redis clients for testing purposes.
tests/unit/type/multi.tcl
: Verified the usage ofredis_client
.tests/test_helper.tcl
: Verified the usage of::tls
and::singledb
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the functionality of the new `redis_client` procedure. # Test: Check if the procedure works correctly by creating a Redis client connection. tclsh <<EOF source tests/test_helper.tcl set ::singledb 1 set client [redis_client] puts "Client created: $client" EOFLength of output: 80
Script:
#!/bin/bash # Search for the definition and usage of the `redis_client` procedure in the codebase. ast-grep --lang tcl --pattern $'proc redis_client {$$$} { $$$ }' # Search for the usage of the `redis_client` procedure in the codebase. rg 'redis_client' # Search for the usage of the `::tls` variable in the codebase. rg '::tls' # Search for the usage of the `::singledb` variable in the codebase. rg '::singledb'Length of output: 1325
Script:
#!/bin/bash # Extract relevant code segments from `tests/unit/type/multi.tcl` to verify the usage of the `redis_client` procedure. rg -A 10 'redis_client' tests/unit/type/multi.tcl # Extract relevant code segments from `tests/test_helper.tcl` to verify the usage of the `::tls` and `::singledb` variables. rg -A 10 '::tls' tests/test_helper.tcl rg -A 10 '::singledb' tests/test_helper.tclLength of output: 4044
34-34
: Verify the impact of reintroducingunit/type/multi
test case.Ensure that the reintroduction of this test case does not cause any issues or conflicts with other tests.
Verification successful
The reintroduction of the
unit/type/multi
test case does not cause any issues or conflicts.
- The test case is isolated and only referenced in
tests/test_helper.tcl
.- Recent commit indicates that the test case has been fixed.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the impact of reintroducing `unit/type/multi` test case. # Test: Check if the test case runs successfully without any issues. tclsh tests/test_helper.tcl --single unit/type/multiLength of output: 127
Script:
#!/bin/bash # Find all references to the `unit/type/multi` test case in the codebase rg 'unit/type/multi' -A 5 # List all test files to identify where `unit/type/multi` might be defined or referenced fd -e tcl # Check for recent changes related to `unit/type/multi` in the commit history git log -p -G 'unit/type/multi'Length of output: 3890
Script:
#!/bin/bash # Search for dependencies and references to `unit/type/multi` within the test files rg 'unit/type/multi' tests/Length of output: 69
src/pika_client_conn.cc (4)
190-190
: Verify the impact of logging command names.Ensure that the logging of command names does not introduce any performance issues.
397-425
: Verify the functionality of the new logic inSetTxnFailedIfKeyExists
.Ensure that the new logic works correctly and handles all edge cases, including the iteration through watched database keys and the existence check in the specified target database.
193-195
: Verify the functionality of theSetTxnFailedIfKeyExists
function.Ensure that the modified function works correctly and handles all edge cases, including the new
target_db_name
parameter.Verification successful
The
SetTxnFailedIfKeyExists
function works correctly and handles thetarget_db_name
parameter as intended.
- The function correctly iterates through involved connections and sets the transaction to a failed state if the key exists in the specified target database.
- The calls to this function in
src/pika_transaction.cc
andsrc/pika_client_conn.cc
handle the parameter correctly.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the functionality of the `SetTxnFailedIfKeyExists` function. # Test: Check if the function works correctly by simulating various scenarios. # Note: This is a placeholder command. Replace with actual test commands if available. echo "Testing required for SetTxnFailedIfKeyExists function."Length of output: 118
Script:
#!/bin/bash # Find the definition of the `SetTxnFailedIfKeyExists` function. ast-grep --lang cpp --pattern 'void SetTxnFailedIfKeyExists(std::string target_db_name) { $$$ }' # Find all calls to the `SetTxnFailedIfKeyExists` function. rg 'SetTxnFailedIfKeyExists'Length of output: 633
Script:
#!/bin/bash # Extract the implementation of the `SetTxnFailedIfKeyExists` function from `src/pika_client_conn.cc`. ast-grep --lang cpp --pattern 'void PikaClientConn::SetTxnFailedIfKeyExists(std::string target_db_name) { $$$ }' src/pika_client_conn.cc # Extract the surrounding context of the `SetTxnFailedIfKeyExists` function calls in `src/pika_transaction.cc`. rg -A 5 -B 5 'SetTxnFailedIfKeyExists' src/pika_transaction.cc # Extract the surrounding context of the `SetTxnFailedIfKeyExists` function calls in `src/pika_client_conn.cc`. rg -A 5 -B 5 'SetTxnFailedIfKeyExists' src/pika_client_conn.ccLength of output: 1837
Script:
#!/bin/bash # Extract the full implementation of the `SetTxnFailedIfKeyExists` function from `src/pika_client_conn.cc`. rg -A 20 -B 0 'void PikaClientConn::SetTxnFailedIfKeyExists' src/pika_client_conn.ccLength of output: 749
Script:
#!/bin/bash # Extract additional lines from the implementation of the `SetTxnFailedIfKeyExists` function in `src/pika_client_conn.cc`. rg -A 40 -B 0 'void PikaClientConn::SetTxnFailedIfKeyExists' src/pika_client_conn.ccLength of output: 1518
436-437
: Verify the impact of logging inSetTxnFailedFromDBs
.Ensure that the logging in the
SetTxnFailedFromDBs
function does not introduce any performance issues.Verification successful
The logging statement in
SetTxnFailedFromDBs
does not introduce significant performance issues.The function is not widely used, and the logging statement is straightforward, ensuring minimal impact on performance.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the impact of logging in `SetTxnFailedFromDBs`. # Test: Check the performance impact of logging in the function. # Note: This is a placeholder command. Replace with actual performance testing commands if available. echo "Performance testing required for logging in SetTxnFailedFromDBs function."Length of output: 156
Script:
#!/bin/bash # Locate the definition of the `SetTxnFailedFromDBs` function and examine its context. ast-grep --lang cpp --pattern 'void SetTxnFailedFromDBs($$$) { $$$ }' # Search for performance-related comments or documentation in the codebase. rg -i 'performance' -A 5Length of output: 128261
Script:
#!/bin/bash # Locate the definition of the `SetTxnFailedFromDBs` function and examine its context. ast-grep --lang cpp --pattern 'void SetTxnFailedFromDBs($$$) { $$$ }'Length of output: 71
Script:
#!/bin/bash # Search for the `SetTxnFailedFromDBs` function in the codebase and examine its context. rg 'SetTxnFailedFromDBs' -A 10 -B 10Length of output: 2823
Script:
#!/bin/bash # Search for calls to the `SetTxnFailedFromDBs` function in the codebase to understand its usage and potential impact on performance. rg 'SetTxnFailedFromDBs' -A 5 -B 5Length of output: 1654
tests/assets/default.conf (6)
37-38
: LGTM! Improved documentation forsync-thread-num
.The updated comment provides better guidance on setting the value of the
sync-thread-num
parameter.
41-46
: LGTM! Newsync-binlog-thread-num
parameter added.The new parameter and its detailed documentation provide better control and guidance for setting the number of threads dedicated to writing binary logs in slave nodes.
111-112
: LGTM! Improved documentation fordatabases
.The expanded comments provide better guidance on aligning the
sync-binlog-thread-num
with the number of databases.
320-323
: LGTM! Newmax-total-wal-size
parameter added.The new parameter and its detailed documentation provide better control and guidance for setting the total size of Write-Ahead Log (WAL) files.
483-485
: LGTM! Improved documentation forthrottle-bytes-per-second
.The enriched comments provide better guidance on the default values and dynamic change capabilities of the
throttle-bytes-per-second
parameter.
487-490
: LGTM! Newrsync-timeout-ms
parameter added.The new parameter and its detailed documentation provide better control and guidance for setting the timeout duration for Rsync during full synchronization.
tests/conf/pika.conf (15)
10-10
: Approved:db-instance-num
settingThe
db-instance-num
parameter is correctly set to 3.
11-12
: Approved: New RocksDB parametersThe new parameters
rocksdb-ttl-second
androcksdb-periodic-second
are correctly introduced to control TTL and periodic operations.
30-36
: Approved: Slow command handling parametersThe new parameters
slow-cmd-thread-pool-size
andslow-cmd-list
are correctly introduced to manage slow commands.
41-46
: Approved:sync-binlog-thread-num
parameterThe
sync-binlog-thread-num
parameter is correctly introduced with recommendations to align with the number of databases.
111-113
: Approved:databases
parameter updateThe
databases
parameter is correctly updated to 3, aligning with the recommended configuration.
240-244
: Approved: RocksDB compaction parametersThe new parameters
disable_auto_compactions
andmax-subcompactions
are correctly introduced to control compaction behavior.
310-318
: Approved: Write buffer merging parametersThe new parameters
min-write-buffer-number-to-merge
are correctly introduced to control write buffer merging in RocksDB.
320-324
: Approved: WAL size parameterThe new parameter
max-total-wal-size
is correctly introduced to control the total size of WAL files.
325-332
: Approved: Level 0 compaction parametersThe new parameters
level0-stop-writes-trigger
,level0-slowdown-writes-trigger
, andlevel0-file-num-compaction-trigger
are correctly introduced to control level 0 compaction behavior in RocksDB.
379-383
: Approved: Slot migration parametersThe new parameters
slotmigrate-thread-num
andthread-migrate-keys-num
are correctly introduced to control slot migration behavior.
427-430
: Approved: Rate limiting parametersThe new parameters related to rate limiting are correctly introduced to control rate limiting behavior in RocksDB.
483-490
: Approved: Rsync rate limiting and timeout parametersThe new parameters
throttle-bytes-per-second
andrsync-timeout-ms
are correctly introduced to control Rsync rate limiting and timeout behavior.
507-507
: Approved:cache-type
parameter updateThe
cache-type
parameter is correctly updated to includebit
, extending the cache type options.
573-588
: Approved: Renaming dangerous commands parametersThe new parameters related to renaming dangerous commands are correctly introduced to enhance security.
Line range hint
938-944
:
Approved: New test forFLUSHALL
while watching keysThe new test for flushing all keys while watching several keys is correctly introduced to ensure the correct behavior of the
FLUSHALL
command.tests/unit/type/multi.tcl (25)
1-9
: Approved:wait_for_dbsize
functionThe
wait_for_dbsize
function is correctly implemented to wait for the database size to reach a specified value.
11-22
: Approved: MULTI / EXEC basics testThe test case for MULTI / EXEC basics is correctly implemented.
24-34
: Approved: DISCARD testThe test case for DISCARD is correctly implemented.
36-42
: Approved: Nested MULTI testThe test case for ensuring nested MULTI commands are not allowed is correctly implemented.
44-49
: Approved: MULTI with commands altering argc/argv testThe test case for MULTI where commands alter argc/argv is correctly implemented.
51-57
: Approved: WATCH inside MULTI testThe test case for ensuring WATCH inside MULTI is not allowed is correctly implemented.
59-68
: Approved: EXEC fails if there are errors while queueing commands testThe test case for ensuring EXEC fails if there are errors while queueing commands is correctly implemented.
88-97
: Approved: EXEC aborts, client MULTI state is cleared testThe test case for ensuring the client MULTI state is cleared if EXEC aborts is correctly implemented.
99-105
: Approved: EXEC works on WATCHed key not modified testThe test case for ensuring EXEC works on WATCHed key not modified is correctly implemented.
107-114
: Approved: EXEC fail on WATCHed key modified (1 key of 1 watched) testThe test case for ensuring EXEC fails on a modified WATCHed key is correctly implemented.
116-123
: Approved: EXEC fail on WATCHed key modified (1 key of 5 watched) testThe test case for ensuring EXEC fails on a modified WATCHed key among multiple watched keys is correctly implemented.
199-209
: Approved: After successful EXEC key is no longer watched testThe test case for ensuring keys are no longer watched after a successful EXEC is correctly implemented.
211-222
: Approved: After failed EXEC key is no longer watched testThe test case for ensuring keys are no longer watched after a failed EXEC is correctly implemented.
224-232
: Approved: UNWATCH testThe test case for ensuring UNWATCH works as expected is correctly implemented.
234-236
: Approved: UNWATCH when nothing is watched testThe test case for ensuring UNWATCH works as expected when nothing is watched is correctly implemented.
238-245
: Approved: FLUSHALL touching watched keys testThe test case for ensuring FLUSHALL touches watched keys is correctly implemented.
247-254
: Approved: FLUSHALL not touching non-affected keys testThe test case for ensuring FLUSHALL does not touch non-affected keys is correctly implemented.
256-263
: Approved: FLUSHDB touching watched keys testThe test case for ensuring FLUSHDB touches watched keys is correctly implemented.
265-272
: Approved: FLUSHDB not touching non-affected keys testThe test case for ensuring FLUSHDB does not touch non-affected keys is correctly implemented.
348-360
: Approved: WATCH remembers the DB a key belongs to testThe test case for ensuring WATCH remembers the DB a key belongs to is correctly implemented.
362-370
: Approved: WATCH considers touched keys target of EXPIRE testThe test case for ensuring WATCH considers touched keys as targets of EXPIRE is correctly implemented.
388-396
: Approved: DISCARD clears the WATCH dirty flag testThe test case for ensuring DISCARD clears the WATCH dirty flag is correctly implemented.
398-407
: Approved: DISCARD UNWATCHs all keys testThe test case for ensuring DISCARD UNWATCHs all keys is correctly implemented.
938-944
: Approved: FLUSHALL while watching several keys testThe test case for ensuring FLUSHALL works correctly while watching several keys is correctly implemented.
947-963
: Approved: MULTI with FLUSHALL and AOF testThe test case for ensuring MULTI works correctly with FLUSHALL and AOF is correctly implemented.
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- include/pika_client_conn.h (1 hunks)
- src/pika_client_conn.cc (2 hunks)
- tests/unit/type/multi.tcl (1 hunks)
Files skipped from review as they are similar to previous changes (3)
- include/pika_client_conn.h
- src/pika_client_conn.cc
- tests/unit/type/multi.tcl
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- tests/test_helper.tcl (4 hunks)
- tests/unit/multi.tcl (6 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/test_helper.tcl
Additional comments not posted (22)
tests/unit/multi.tcl (22)
Line range hint
12-18
:
LGTM!The test case
MULTI / EXEC basics
is correctly implemented and covers the basic functionality of the MULTI and EXEC commands.
Line range hint
20-26
:
LGTM!The test case
DISCARD
is correctly implemented and covers the functionality of the DISCARD command within a transaction.
Line range hint
28-33
:
LGTM!The test case
Nested MULTI are not allowed
is correctly implemented and covers the scenario where nested MULTI commands are not allowed.
Line range hint
35-40
:
LGTM!The test case
MULTI where commands alter argc/argv
is correctly implemented and covers the functionality of commands that alter argument counts within a transaction.
Line range hint
42-47
:
LGTM!The test case
WATCH inside MULTI is not allowed
is correctly implemented and covers the scenario where the WATCH command is not allowed inside a transaction.
60-67
: LGTM!The test case
EXEC fails if there are errors while queueing commands #1
is correctly implemented and covers the scenario where EXEC fails if there are errors while queueing commands.
89-94
: LGTM!The test case
If EXEC aborts, the client MULTI state is cleared
is correctly implemented and covers the scenario where the client MULTI state is cleared if EXEC aborts.
100-104
: LGTM!The test case
EXEC works on WATCHed key not modified
is correctly implemented and covers the scenario where EXEC works on a watched key that is not modified.
107-114
: LGTM!The test case
EXEC fail on WATCHed key modified (1 key of 1 watched)
is correctly implemented and covers the scenario where EXEC fails if a watched key is modified.
116-123
: LGTM!The test case
EXEC fail on WATCHed key modified (1 key of 5 watched)
is correctly implemented and covers the scenario where EXEC fails if one of the watched keys is modified.
Line range hint
198-203
:
LGTM!The test case
After successful EXEC key is no longer watched
is correctly implemented and covers the scenario where a key is no longer watched after a successful EXEC.
Line range hint
205-210
:
LGTM!The test case
After failed EXEC key is no longer watched
is correctly implemented and covers the scenario where a key is no longer watched after a failed EXEC.
Line range hint
212-218
:
LGTM!The test case
It is possible to UNWATCH
is correctly implemented and covers the scenario where it is possible to unwatch a key.
Line range hint
220-222
:
LGTM!The test case
UNWATCH when there is nothing watched works as expected
is correctly implemented and covers the scenario where the UNWATCH command works as expected when there is nothing watched.
238-245
: LGTM!The test case
FLUSHALL is able to touch the watched keys
is correctly implemented and covers the scenario where the FLUSHALL command is able to touch the watched keys.
Line range hint
247-253
:
LGTM!The test case
FLUSHALL does not touch non affected keys
is correctly implemented and covers the scenario where the FLUSHALL command does not touch non-affected keys.
256-263
: LGTM!The test case
FLUSHDB is able to touch the watched keys
is correctly implemented and covers the scenario where the FLUSHDB command is able to touch the watched keys.
Line range hint
265-271
:
LGTM!The test case
FLUSHDB does not touch non affected keys
is correctly implemented and covers the scenario where the FLUSHDB command does not touch non-affected keys.
348-360
: LGTM!The test case
WATCH is able to remember the DB a key belongs to
is correctly implemented and covers the scenario where the WATCH command is able to remember the database a key belongs to.
362-370
: LGTM!The test case
WATCH will consider touched keys target of EXPIRE
is correctly implemented and covers the scenario where the WATCH command will consider touched keys as targets of the EXPIRE command.
Line range hint
388-395
:
LGTM!The test case
DISCARD should clear the WATCH dirty flag on the client
is correctly implemented and covers the scenario where the DISCARD command clears the WATCH dirty flag on the client.
Line range hint
397-405
:
LGTM!The test case
DISCARD should UNWATCH all the keys
is correctly implemented and covers the scenario where the DISCARD command unwatches all the keys.
proc wait_for_dbsize {size} { | ||
set r2 [redis_client] | ||
wait_for_condition 50 100 { | ||
[$r2 dbsize] == $size | ||
} else { | ||
fail "Target dbsize not reached" | ||
} | ||
$r2 close | ||
} |
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.
Add error handling for redis_client
creation and wait_for_condition
execution.
The function wait_for_dbsize
lacks error handling for the redis_client
creation and the wait_for_condition
execution. Consider adding error handling to make the function more robust.
proc wait_for_dbsize {size} {
set r2 [redis_client]
if {$r2 == ""} {
fail "Failed to create redis client"
}
wait_for_condition 50 100 {
[$r2 dbsize] == $size
} else {
fail "Target dbsize not reached"
}
$r2 close
}
@@ -386,32 +387,42 @@ void PikaClientConn::SetTxnFailedFromKeys(const std::vector<std::string>& db_key | |||
auto involved_conns = std::vector<std::shared_ptr<NetConn>>{}; | |||
involved_conns = dispatcher->GetInvolvedTxn(db_keys); | |||
for (auto& conn : involved_conns) { | |||
if (auto c = std::dynamic_pointer_cast<PikaClientConn>(conn); c != nullptr && c.get() != this) { | |||
if (auto c = std::dynamic_pointer_cast<PikaClientConn>(conn); c != nullptr) { |
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.
这里为啥去掉c.get() != this?
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.
这里为啥去掉c.get() != this?
如果一个client watch 了一个 key,就算这个 key 是被这个 client 自己修改的,这个 watch 也会失效。redis 是这个逻辑,所以去除了和这个判断
src/pika_client_conn.cc
Outdated
if (c_ptr->res().ok() && c_ptr->is_write() && name() != kCmdNameExec) { | ||
LOG(INFO) << c_ptr->name(); |
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.
日志删一下
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.
done
src/pika_transaction.cc
Outdated
@@ -258,7 +258,7 @@ void WatchCmd::DoInitial() { | |||
size_t pos = 1; | |||
while (pos < argv_.size()) { | |||
keys_.emplace_back(argv_[pos]); | |||
db_keys_.push_back(db_name() + argv_[pos++]); | |||
db_keys_.push_back(db_name() + "_" +argv_[pos++]); |
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.
代码格式 + argv_[pos++]
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.
代码格式 + argv_[pos++]
这个下划线是特意加上去的,作为 db_key 字符串内容的一部分
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/pika_client_conn.cc (2 hunks)
- src/pika_transaction.cc (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/pika_transaction.cc
Additional comments not posted (4)
src/pika_client_conn.cc (4)
396-424
: Verify the correctness of the new function implementation.Ensure that the
SetTxnFailedIfKeyExists
function correctly handles the transaction failure conditions based on key existence.Verification successful
The
SetTxnFailedIfKeyExists
function correctly handles the transaction failure conditions based on key existence.
- The function checks if the key exists in the target database and sets the transaction watch state to failed if the key is found.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the `SetTxnFailedIfKeyExists` function implementation. # Test: Search for the function implementation. Expect: Correct handling of transaction failure conditions. ast-grep --lang cpp --pattern $'void PikaClientConn::SetTxnFailedIfKeyExists(std::string target_db_name) { $$$ }'Length of output: 116
Script:
#!/bin/bash # Description: Verify the correctness of the `SetTxnFailedIfKeyExists` function implementation. # Test: Search for the function implementation using ripgrep. Expect: Correct handling of transaction failure conditions. rg 'void PikaClientConn::SetTxnFailedIfKeyExists' -A 30Length of output: 1797
389-389
: Verify the correctness of the condition removal.Ensure that the removal of the condition
c.get() != this
aligns with the new logic for handling transaction failures.
204-210
: Verify the correctness of the new logging logic.Ensure that the changes to the
DoCmd
function correctly handle the logging of command names.Verification successful
Verify the correctness of the new logging logic.
The
DoCmd
function correctly handles the logging of command names and updates the command statistics. The changes align with the expected behavior for logging command names.
- The command execution and logging logic are implemented correctly.
- The function updates the command statistics and processes slow logs as expected.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the new logging logic in `DoCmd`. # Test: Search for the function implementation. Expect: Correct handling of command name logging. ast-grep --lang cpp --pattern $'std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const std::string& opt, const std::shared_ptr<std::string>& resp_ptr) { $$$ }'Length of output: 185
Script:
#!/bin/bash # Description: Broaden the search for the `DoCmd` function implementation and verify the logging logic. # Test: Search for the function implementation with a broader pattern. rg -A 10 'std::shared_ptr<Cmd> PikaClientConn::DoCmd' --glob '*.cc'Length of output: 864
Script:
#!/bin/bash # Description: Extract the complete implementation of the `DoCmd` function from `src/pika_client_conn.cc`. # Test: Extract the complete function implementation. rg -A 50 'std::shared_ptr<Cmd> PikaClientConn::DoCmd' src/pika_client_conn.ccLength of output: 1883
Script:
#!/bin/bash # Description: Extract additional lines from the `DoCmd` function implementation in `src/pika_client_conn.cc`. # Test: Extract the next 50 lines of the function implementation. rg -A 100 'std::shared_ptr<Cmd> PikaClientConn::DoCmd' src/pika_client_conn.ccLength of output: 3800
Script:
#!/bin/bash # Description: Extract additional lines from the `DoCmd` function implementation in `src/pika_client_conn.cc`. # Test: Extract the next 100 lines of the function implementation. rg -A 200 'std::shared_ptr<Cmd> PikaClientConn::DoCmd' src/pika_client_conn.ccLength of output: 7561
192-194
: Verify the correctness of the new function call.Ensure that the
SetTxnFailedIfKeyExists
function is correctly handling the transaction failure conditions based on key existence.Verification successful
The
SetTxnFailedIfKeyExists
function correctly handles transaction failure conditions based on key existence.
- The function iterates through involved connections and their watched keys.
- It checks if the watched key exists in the specified database.
- If the key exists, it sets the transaction watch state to failed.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correctness of the `SetTxnFailedIfKeyExists` function call. # Test: Search for the function implementation. Expect: Correct handling of transaction failure conditions. ast-grep --lang cpp --pattern $'void PikaClientConn::SetTxnFailedIfKeyExists(std::string target_db_name) { $$$ }'Length of output: 116
Script:
#!/bin/bash # Description: Search for the implementation of the `SetTxnFailedIfKeyExists` function in the codebase. # Test: Search for the function definition. Expect: Locate the function definition regardless of parameters. ast-grep --lang cpp --pattern $'void PikaClientConn::SetTxnFailedIfKeyExists($$$) { $$$ }'Length of output: 93
Script:
#!/bin/bash # Description: Search for any functions containing `SetTxnFailedIfKeyExists` and other transaction-related functions in the `PikaClientConn` class. # Test: Search for any functions containing `SetTxnFailedIfKeyExists`. rg --no-heading --line-number --color=always 'SetTxnFailedIfKeyExists' # Test: Search for transaction-related functions in the `PikaClientConn` class. ast-grep --lang cpp --pattern $'class PikaClientConn { $$$ void $_($_) { $$$ } $$$ }'Length of output: 1300
Script:
#!/bin/bash # Description: Extract the implementation of the `SetTxnFailedIfKeyExists` function from `src/pika_client_conn.cc`. # Extract the function implementation from the specified file and line. sed -n '397,417p' src/pika_client_conn.ccLength of output: 704
Script:
#!/bin/bash # Description: Extract the remaining implementation of the `SetTxnFailedIfKeyExists` function from `src/pika_client_conn.cc`. # Extract the function implementation from the specified file and line. sed -n '417,437p' src/pika_client_conn.ccLength of output: 558
* add multi.tcl * Commented test cases in Tcl that cannot pass * fix multi bug and compatible ACL test --------- Co-authored-by: saz97 <[email protected]> Co-authored-by: liuyuecai <[email protected]>
fix #2446
改动如下:
1、一个 client watch 的 key,被任何人修改(包括自己的改动),都会失效;
2、当执行 flushdb、flushall 命令时,只有当 watch 的 key 的值非空,才会影响这个 watch 动作;
3、添加了 multi 命令的 ACL 测试
Summary by CodeRabbit
New Features
Bug Fixes
Tests