-
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
Feature/txn #1585
Feature/txn #1585
Changes from all commits
3541c5a
da524e0
821434f
0823cb6
b9e92ee
a24b9ec
3439146
c8ca075
867dbfb
bc24a33
d3c63a4
20f7148
2a0f9a5
7b6e279
3e4cae9
5a3aacf
fcf3015
6f97281
8ed5dc1
ebc3abf
684bcca
d553036
84651a4
dca87ee
bd78516
f664260
d497d08
e1da3da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#ifndef PIKA_CLIENT_CONN_H_ | ||
#define PIKA_CLIENT_CONN_H_ | ||
|
||
#include <bitset> | ||
#include <utility> | ||
|
||
#include "include/pika_command.h" | ||
|
@@ -24,6 +25,14 @@ class PikaClientConn : public net::RedisConn { | |
uint32_t slot_id; | ||
}; | ||
|
||
struct TxnStateBitMask { | ||
public: | ||
static constexpr uint8_t Start = 0; | ||
static constexpr uint8_t InitCmdFailed = 1; | ||
static constexpr uint8_t WatchFailed = 2; | ||
static constexpr uint8_t Execing = 3; | ||
}; | ||
|
||
// Auth related | ||
class AuthStat { | ||
public: | ||
|
@@ -42,7 +51,7 @@ class PikaClientConn : public net::RedisConn { | |
|
||
PikaClientConn(int fd, const std::string& ip_port, net::Thread* server_thread, net::NetMultiplexer* mpx, | ||
const net::HandleType& handle_type, int max_conn_rbuf_size); | ||
~PikaClientConn() override = default; | ||
~PikaClientConn() = default; | ||
|
||
void ProcessRedisCmds(const std::vector<net::RedisCmdArgsType>& argvs, bool async, | ||
std::string* response) override; | ||
|
@@ -54,10 +63,30 @@ class PikaClientConn : public net::RedisConn { | |
|
||
bool IsPubSub() { return is_pubsub_; } | ||
void SetIsPubSub(bool is_pubsub) { is_pubsub_ = is_pubsub; } | ||
void SetCurrentTable(const std::string& db_name) { current_db_ = db_name; } | ||
const std::string& GetCurrentTable() override{ return current_db_; } | ||
void SetCurrentDb(const std::string& db_name) { current_db_ = db_name; } | ||
const std::string& GetCurrentTable() override { return current_db_; } | ||
void SetWriteCompleteCallback(WriteCompleteCallback cb) { write_completed_cb_ = std::move(cb); } | ||
|
||
// Txn | ||
void PushCmdToQue(std::shared_ptr<Cmd> cmd); | ||
std::queue<std::shared_ptr<Cmd>> GetTxnCmdQue(); | ||
void ClearTxnCmdQue(); | ||
bool IsInTxn(); | ||
bool IsTxnFailed(); | ||
bool IsTxnInitFailed(); | ||
bool IsTxnWatchFailed(); | ||
bool IsTxnExecing(void); | ||
void SetTxnWatchFailState(bool is_failed); | ||
void SetTxnInitFailState(bool is_failed); | ||
void SetTxnStartState(bool is_start); | ||
|
||
void AddKeysToWatch(const std::vector<std::string> &db_keys); | ||
void RemoveWatchedKeys(); | ||
void SetTxnFailedFromKeys(const std::vector<std::string> &db_keys); | ||
void SetAllTxnFailed(); | ||
void SetTxnFailedFromDBs(std::string db_name); | ||
void ExitTxn(); | ||
|
||
net::ServerThread* server_thread() { return server_thread_; } | ||
|
||
AuthStat& auth_stat() { return auth_stat_; } | ||
|
@@ -70,14 +99,18 @@ class PikaClientConn : public net::RedisConn { | |
std::string current_db_; | ||
WriteCompleteCallback write_completed_cb_; | ||
bool is_pubsub_ = false; | ||
std::queue<std::shared_ptr<Cmd>> txn_cmd_que_; | ||
std::bitset<16> txn_state_; | ||
std::unordered_set<std::string> watched_db_keys_; | ||
std::mutex txn_state_mu_; | ||
|
||
std::shared_ptr<Cmd> DoCmd(const PikaCmdArgsType& argv, const std::string& opt, | ||
const std::shared_ptr<std::string>& resp_ptr); | ||
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. The code patch seems to add Redis transactions support for a PikaClientConn class. Here are some suggestions and improvements:
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. The code review consists of the following points:
Some possible improvements include providing more detailed comments, catching potential exceptional scenarios, adding unit tests, and implementing standard C++ exception handling to improve code robustness. 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. Overall, the code does not seem to contain any syntax or semantic errors. However, some suggestions for improvement are:
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. Here are some suggestions and improvements for the code:
These suggestions aim to improve the overall clarity, maintainability, and reliability of the code. It's important to thoroughly test and validate the code after implementing any changes to ensure its correctness. |
||
|
||
void ProcessSlowlog(const PikaCmdArgsType& argv, uint64_t start_us, uint64_t do_duration); | ||
void ProcessMonitor(const PikaCmdArgsType& argv); | ||
|
||
void ExecRedisCmd(const PikaCmdArgsType& argv, const std::shared_ptr<std::string>& resp_ptr); | ||
void ExecRedisCmd(const PikaCmdArgsType& argv, std::shared_ptr<std::string>& resp_ptr); | ||
void TryWriteResp(); | ||
|
||
AuthStat auth_stat_; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,9 @@ class PikaReplicaManager { | |
~PikaReplicaManager() = default; | ||
|
||
friend Cmd; | ||
friend class FlushdbCmd; | ||
friend class FlushallCmd; | ||
friend class ExecCmd; | ||
|
||
void Start(); | ||
void Stop(); | ||
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. Based on the provided code patch, it appears that you have added several friend classes to the Without more context or the complete codebase, it is challenging to provide an extensive code review. However, based on the provided information, here are a few general suggestions:
Remember, a thorough code review often requires a comprehensive understanding of the entire codebase. Consider involving other developers familiar with the project to perform a more detailed and contextualized review. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,11 @@ | |
#include "include/pika_repl_client.h" | ||
#include "include/pika_repl_server.h" | ||
#include "include/pika_rsync_service.h" | ||
#include "include/pika_migrate_thread.h" | ||
#include "include/rsync_server.h" | ||
#include "include/pika_statistic.h" | ||
#include "include/pika_slot_command.h" | ||
#include "include/pika_migrate_thread.h" | ||
#include "include/pika_transaction.h" | ||
#include "include/pika_cmd_table_manager.h" | ||
|
||
|
||
|
@@ -506,6 +507,8 @@ class PikaServer : public pstd::noncopyable { | |
friend class InfoCmd; | ||
friend class PikaReplClientConn; | ||
friend class PkClusterInfoCmd; | ||
friend class FlushallCmd; | ||
friend class ExecCmd; | ||
|
||
private: | ||
/* | ||
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. Based on the code patch you provided, here are a few observations:
Please provide more details or specific sections of the code if you would like a more comprehensive review. |
||
|
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.
Here are some suggestions for code review and improvements:
Make sure the necessary header files are included, such as
"pika_db.h"
. Check if all required dependencies are correctly included to avoid compilation errors.Review the changes made to the
SelectCmd
class. Check if the addition of theselect_db_
member variable and related methods (Execute
,FlushAllWithoutLock
, andDoWithoutLock
) are implemented correctly. Verify that these changes do not introduce any new bugs or affect the overall functionality of the class.For the
FlushallCmd
class, check the implementation of the new methodsExecute
,FlushAllWithoutLock
, andDoWithoutLock
. Ensure that they are correctly implemented and handle flushing behavior appropriately. Review the existing methods (Split
,Merge
,Clone
,DoInitial
, andToBinlog
) for any related modifications required due to the new changes.Similarly, review the changes made to the
FlushdbCmd
class, including the implementation of the new methodsFlushAllSlotsWithoutLock
,Execute
,GetFlushDname
, andDoWithoutLock
. Verify that these changes are consistent with the expected behavior of the class and do not introduce any bugs. Review the existing methods (Split
,Merge
,Clone
,DoInitial
, andClear
) for any necessary adjustments.Check the implementation of the new methods
Execute
in theInfoCmd
andConfigCmd
classes. Ensure that they perform the intended actions correctly and consider any impact they may have on other parts of the code.Confirm that all added methods in the classes follow a consistent naming convention and adhere to the coding style guidelines of the project.
If possible, conduct thorough testing after incorporating these changes to ensure the desired functionality is achieved and there are no regression issues.
Remember to consult project-specific coding guidelines, conventions, and best practices while reviewing the code.