-
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
Conversation
conf/pika.conf
Outdated
@@ -92,7 +92,7 @@ instance-mode : classic | |||
# The default database id is DB 0. You can select a different one on | |||
# a per-connection by using SELECT. The db id range is [0, 'databases' value -1]. | |||
# The value range of this parameter is [1, 8]. | |||
databases : 1 | |||
databases : 8 | |||
|
|||
# The default slot number of each table when Pika runs in sharding mode. | |||
default-slot-num : 1024 |
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.
Overall, the code patch is simple and straightforward. It appears that the only change being made is to the value of the "databases" parameter, which is being updated from 1 to 8.
There don't seem to be any immediate bug risks associated with this change, but it's possible that it could have unintended consequences if other parts of the system are relying on the previous value of the parameter.
As for improvement suggestions, perhaps adding a comment explaining the rationale behind the change would be useful for future readers of the code. Additionally, some documentation around the configuration file format (if it doesn't already exist) could help prevent future mistakes or confusion when making changes to these types of parameters.
std::vector<std::string> txn_exec_dbs_; | ||
std::mutex txn_state_mu_; // 用于锁事务状态 | ||
std::mutex txn_db_mu_; // 在执行事务的时候,采用加db锁的方式加锁,那么就会有多个db被加锁,那么就会有加锁顺序的问题,所以加了这把大锁 | ||
// 在void Cmd::ProcessExecCmd();中使用这把锁 | ||
|
||
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 comment
The 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:
- It seems that the destructor is overridden but not doing anything. It could be removed altogether as it does not seem to provide any additional functionality.
- The TxnStateBitMask class containing static constants is related to transaction states, but the use of bit shifting is unclear. Enum values could be used instead.
- There are utility methods for managing transactions (e.g., IsInTxn(), AddKeysToWatch()) in the PikaClientConn class, but there is no documentation explaining how they should be used or what their side effects might be. Adding docstrings would help improve code readability and maintainability.
- The comment about the large txn_db_mu_ lock mentions that "there will be an issue with the order in which locks are acquired." This statement is not explained further, so users of the class may not understand the rationale behind the design decision or the potential for deadlock if the locking scheme is not followed properly.
- It's difficult to determine whether there are any bugs without more context or code coverage information.
include/pika_command.h
Outdated
@@ -454,7 +477,7 @@ class Cmd : public std::enable_shared_from_this<Cmd> { | |||
std::string db_name_; | |||
|
|||
std::weak_ptr<net::NetConn> conn_; | |||
std::weak_ptr<std::string> resp_; | |||
std::shared_ptr<std::string> resp_; | |||
CmdStage stage_ = kNone; | |||
uint64_t do_duration_ = 0; | |||
|
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.
The code patch appears to add a set of new commands and related functionality for transactions. Here are a few observations and suggestions:
- It's good that the required headers have been included, and the namespace usage is consistent.
- Adding new commands and related data structures should be reviewed thoroughly to ensure they don't affect existing functionality by introducing side effects or bugs.
- The CmdRes class has been modified to include response values for the new transaction-related commands. However, it might need further testing to ensure it works correctly with every transaction scenario.
- The ProcessExecCmd virtual function has been added to allow processing of EXEC command execution. The implementation would also require proper testing to catch any side effects or bugs in the existing application flow.
- There seems to be a typo in the spelling of "invalid" in kInvaildTranscation, and it may go unnoticed during the review process. A spell-check can avoid such issues.
- It's unclear why the cmd_names are initialized to string constants; concern should be given to their lifespan and scope.
- Some comments that explain the purpose of each data structure would help other developers understand it more easily.
- There could be additional methods or properties on the Cmd object like ID, Priority or Token, which could be useful for scheduling purposes.
- Lastly, running meaningful unit tests to validate all functionalities would be highly recommended before merging the patch.
std::vector<std::string> txn_exec_dbs_; | ||
std::mutex txn_state_mu_; // 用于锁事务状态 | ||
std::mutex txn_db_mu_; // 在执行事务的时候,采用加db锁的方式加锁,那么就会有多个db被加锁,那么就会有加锁顺序的问题,所以加了这把大锁 | ||
// 在void Cmd::ProcessExecCmd();中使用这把锁 | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The code review consists of the following points:
- The code adds a new class
TxnStateBitMask
to manage transaction states, which seems like a reasonable and clean approach. - The default destructor is modified to be non-default in
PikaClientConn
, but no reason is given for this change, so it's hard to tell if it was necessary or not. - The use of
std::queue<std::shared_ptr<Cmd>>
for storing transaction commands seems appropriate for managing transactions. - The use of locks for
txn_state_
andtxn_db_mu_
also appears appropriate since these variables are shared between threads. - There are some incomplete comments, such as
//TODO(leeHao): 将一个超时关闭的连接所watch的key给从全局的那个变量里面给清除掉
that need to be addressed.
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.
void DoInitial() override; | ||
}; | ||
|
||
#endif // PIKA_TRANSACTION_H_ |
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.
The provided code is a set of header and class declarations related to transactions in Pika, which includes multi, exec, discard, watch, and unwatch commands.
Without the definitions of these classes' member functions, it is difficult to identify any potential bugs or improvements. However, there seems to be no syntax or formatting issues in the provided code patch.
One potential improvement suggestion would be to add comments explaining each class's purpose and usage in more detail. It helps other programmers understand and use these classes in the future.
std::vector<std::string> txn_exec_dbs_; | ||
std::mutex txn_state_mu_; // 用于锁事务状态 | ||
std::mutex txn_db_mu_; // 在执行事务的时候,采用加db锁的方式加锁,那么就会有多个db被加锁,那么就会有加锁顺序的问题,所以加了这把大锁 | ||
// 在void Cmd::ProcessExecCmd();中使用这把锁 | ||
|
||
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 comment
The 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:
-
The destructor of
PikaClientConn
is overriden but doesn't have any implementation. Since the parent class has a virtual destructor, it should be explicitly called in the child class destructor or its only declaration can be left as default. -
The use of raw locks and mutexes might lead to deadlocks if proper care is not taken. Consider using RAII wrappers like
std::lock_guard
orstd::unique_lock
to mitigate this risk. -
Some comments mention "db" but it's unclear what it refers to. Adding more descriptive comments and naming conventions would improve its readability and maintainability.
-
The current design uses a queue and a bitset to implement a transaction. This may suffice, but there are more efficient and flexible ways to structure transactions, such as using a directed acyclic graph(DAG) to represent dependencies among operations within a transaction.
-
The name
PikaClientConn
could be improved by following existing conventions in the project or industry standards.
src/net/src/dispatch_thread.cc
Outdated
} | ||
return involved_conns; | ||
} | ||
|
||
extern ServerThread* NewDispatchThread(int port, int work_num, ConnFactory* conn_factory, int cron_interval, | ||
int queue_limit, const ServerHandle* handle) { | ||
return new DispatchThread(port, work_num, conn_factory, cron_interval, queue_limit, handle); |
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.
The code patch adds functionality to watch keys and get involved transactions in a multithreaded environment. Here are some suggestions:
-
It is good that the code is making use of mutexes to protect concurrent access to shared data structures. However, it's not clear whether these mutexes are defined and initialized correctly. Make sure they are instantiated as appropriate types (e.g., std::mutex, std::shared_mutex) and properly constructed with their default constructors.
-
In
AddWatchKeys
, there is a mistake in the emplace call tokey_conns_map_
: it should be an argument containing the key and the value (i.e.,key, std::set<std::shared_ptr<NetConn>>()
). The same applies tokey_conns_map_.erase(key)
. -
In
RemoveWatchKeys
, we could avoid the double map lookup by iterating directly over the set of keys for a given client_connection instead of looking them up inconn_keys_map_
. e.g:
auto it = key_conns_map_.begin();
while (it != key_conns_map_.end()) {
it->second.erase(client_conn);
if (it->second.empty()) it = key_conns_map_.erase(it);
else ++it;
}
- In
GetInvolvedTxn
, since the function returns a vector of shared pointers, we can use a range-based for loop to simplify the code a bit, e.g:
for (const auto& [key, conns] : key_conns_map_) {
if (std::find(keys.begin(), keys.end(), key) == keys.end()) continue;
for (const auto& conn : conns) involved_conns.emplace_back(conn);
}
- Overall, the code looks good, but it would be helpful to add some comments that explain the purpose of each function and clarify any ambiguities in the code.
src/pika_command.cc
Outdated
@@ -547,6 +568,38 @@ void Cmd::ProcessFlushAllCmd() { | |||
} | |||
res_.SetRes(CmdRes::kOk); | |||
} | |||
/** | |||
* TODO(leeHao): 这个exec命令本身的binlog我不确定如何处理,我感觉应该还是需要写的,因为如果执行队列中的命令,执行到了一半但是退出了 | |||
* 那么下次启动的时候,应该回滚部分操作? |
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.
单独设计事务的binlogOp,比如BEGAIN_TXN END_TXN,回滚binlog的时候要检查 是不是配对的
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.
同步binlog的时候,在BEGAN_TXN END_TXN中间的op不执行,直到配对检查到之后再执行
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.
是这样的水哥,我这两天怎么想都觉得在从机消费binlog的时候,来检查是不是配对的这个很难做。
我理解全量更新的话,从机那边是不用做读取和解析log并执行log中命令的操作的,直接将log文件替换即可,所以其实是不知道这个log里面包不包含事务的,所以我觉得目前全量更新很难做成下面这样子,即在读到事务开始便将主机发的binlog给加入内存,而不写磁盘,等到读到exec命令,再统一写磁盘,然后增量更新的话,是可以做的。
那么能否这样?
- 在主节点,执行到事务这块儿的时候,只有执行到exec命令,且事务当中命令有效的情况下,就加锁,开始执行本次事务中各个命令的Do,以及DoBinlog(不包含multi和exec,watch,unwatch,这几个命令不写binlog),写完之后返回给客户端成功。
- 在从机消费主机的binlog的时候,因为都是有效的,其实不需要回退这个功能。
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.
你的意思是从机只同步事务的结果。也可以
src/pika_command.cc
Outdated
* TODO(leeHao): 还有个得到执行时间的函数,这个统计命令时间,是统计事务队列中,每个命令单独统计还是统计一整个队列的执行时长 | ||
* 这里因为是多个db的锁,所以需要注意执行顺序,否则就会死锁,我的选择是,先拿取一把大锁 | ||
* 然后将所有的锁给拿齐了,再释放掉这把大锁 | ||
*/ |
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.
目前的这种设计,跨db的事务如何处理?
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.
目前的处理是在Exec的Do函数中,先拿取一把大锁g_pika_server->dbs_rw_,再拿取涉及到的所有Slot的锁,然后再处理所有的命令,处理完成之后,统一释放所有锁
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.
你这种写法会不会影响别的命令。事务的锁应该只锁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.
这样写是一定会影响其他命令的,只要是涉及到这个slot的命令都会被卡住。
好像只锁key也确实可以。
54b8825
to
89d8740
Compare
std::queue<std::shared_ptr<Cmd>> txn_cmd_que_; // redis事务的队列 | ||
std::bitset<16> txn_state_; // class TxnStateBitMask | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some suggestions and improvements for the code:
-
In the constructor
PikaClientConn
, initializeis_pubsub_
explicitly along with other member variables to improve readability. -
In the destructor
~PikaClientConn
, use curly braces{}
instead ofdefault
. Even though the default destructor is fine, using curly braces makes it explicit. -
Consider making the member function
GetCurrentDb
a const member function since it only retrieves the value and doesn't modify the object. -
Provide descriptive comments for the
PushCmdToQue
function and other functions in the Txn section to explain their purpose and usage. -
Consider using more descriptive variable names rather than abbreviations. For example, replace
db_keys
withdatabaseKeys
or something similar. This will improve code understandability. -
Review the error handling and exception handling mechanisms in the code to ensure that all potential error scenarios are properly handled.
-
Consider adding unit tests for the code, especially for the functions related to transaction processing, to ensure their correctness.
-
Review the usage of locks and mutexes in the code to prevent any potential race conditions when accessing shared data structures, such as
txn_cmd_que_
andtxn_state_
. Ensure that the locking mechanism is correctly implemented to avoid deadlocks.
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.
尽量分片锁,然后锁一组key,避免影响别的命令
…------------------ 原始邮件 ------------------
发件人: ***@***.***>;
发送时间: 2023年7月12日(星期三) 下午2:30
收件人: ***@***.***>;
抄送: ***@***.***>; ***@***.***>;
主题: Re: [OpenAtomFoundation/pika] Feature/txn (PR #1585)
@ForestLH commented on this pull request.
In src/pika_command.cc:
> @@ -547,6 +568,38 @@ void Cmd::ProcessFlushAllCmd() { } res_.SetRes(CmdRes::kOk); } +/** + * TODO(leeHao): 这个exec命令本身的binlog我不确定如何处理,我感觉应该还是需要写的,因为如果执行队列中的命令,执行到了一半但是退出了 + * 那么下次启动的时候,应该回滚部分操作? + * TODO(leeHao): 还有个得到执行时间的函数,这个统计命令时间,是统计事务队列中,每个命令单独统计还是统计一整个队列的执行时长 + * 这里因为是多个db的锁,所以需要注意执行顺序,否则就会死锁,我的选择是,先拿取一把大锁 + * 然后将所有的锁给拿齐了,再释放掉这把大锁 + */
这样写是一定会影响其他命令的,只要是涉及到这个slot的命令都会被卡住。
好像只锁key也确实可以。
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
水哥这个建议很好,使用分片锁吧。Pika 分片锁的代码是从 RocksDB 抄过来的,效率还是很在线的。 |
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
todo:test txn. Just to verify the feasibility of the program. Signed-off-by: Hao Lee <1838249551@qq.com>
Add comments Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
@@ -176,6 +176,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 comment
The 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 PikaReplicaManager
class. This grants those classes access to the private and protected members of PikaReplicaManager
. This change seems reasonable assuming that you have a valid reason for doing so.
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:
- Documentation: Ensure that the purpose and behavior of the
PikaReplicaManager
class and its associated functions (Start()
,Stop()
, etc.) are adequately documented. Clear documentation will help improve code maintainability. - Error Handling: Review the error handling mechanism in place. It's essential to handle potential errors gracefully and provide appropriate feedback or recovery mechanisms where needed.
- Testing: It's good practice to have unit tests covering the functionality of
PikaReplicaManager
and any associated classes. Automated tests can help catch bugs and ensure that changes made to the codebase do not introduce new issues. - Code Organization: Check if there is an opportunity to refactor the code for better organization and readability. Aim for clear and concise functions that follow established coding standards and best practices.
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.
@@ -501,6 +502,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 comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the code patch you provided, here are a few observations:
-
In line 38, there seems to be a redundant inclusion of "pika_migrate_thread.h" since it's already included in line 11.
-
In line 39, there is an additional inclusion of "pika_transaction.h". Make sure it is necessary and doesn't conflict with existing code.
-
It seems like classes named "FlushallCmd" and "ExecCmd" are being declared. Double-check if they are properly defined elsewhere.
-
Since this code snippet only provides the inclusion part and not the definition or implementation, it's challenging to identify specific bugs or improvements. A more thorough review would require examining the logic and functionality of the classes and functions involved.
Please provide more details or specific sections of the code if you would like a more comprehensive review.
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
include/pika_client_conn.h
Outdated
@@ -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() override {} |
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.
改回去
include/pika_command.h
Outdated
|
||
std::weak_ptr<net::NetConn> conn_; | ||
std::weak_ptr<std::string> resp_; | ||
std::shared_ptr<std::string> resp_; |
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.
这里是因为在PikaClientConn::TryWriteResp函数中,会将conn的resp数组给清空,由于command不持有这个string,所以这个string会被释放掉,但是如果是事务之中的命令的话,这个command会被加入到队列中,后续要使用,但是后续使用的时候就拿不到string了,于是我就变成了shared指针。
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.
在此提交之中,还原了cmd中的 weak ptr
Signed-off-by: Hao Lee <1838249551@qq.com>
Signed-off-by: Hao Lee <1838249551@qq.com>
0461d72
to
e1da3da
Compare
b115187
into
OpenAtomFoundation:OpenAtom-Transaction
* Feature/txn (#1585) * fix: fix select cmd return inconsistent with redis Signed-off-by: Hao Lee <1838249551@qq.com> * refactor:modified lock style while involve db level Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn basic Signed-off-by: Hao Lee <1838249551@qq.com> * fix:merge upstream Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn udpate Signed-off-by: Hao Lee <1838249551@qq.com> * feature:add txn for pika(#1446) todo:test txn. Just to verify the feasibility of the program. Signed-off-by: Hao Lee <1838249551@qq.com> * update unwatch cmd Add comments Signed-off-by: Hao Lee <1838249551@qq.com> * clear watched key when connection closed Signed-off-by: Hao Lee <1838249551@qq.com> * merge upstream code Signed-off-by: Hao Lee <1838249551@qq.com> * update Signed-off-by: Hao Lee <1838249551@qq.com> * feature: add txn for pika completely Signed-off-by: Hao Lee <1838249551@qq.com> * add set txn failed for modified watch key Signed-off-by: Hao Lee <1838249551@qq.com> * update:reduce the particle size of the lock in txn Signed-off-by: Hao Lee <1838249551@qq.com> * chore:remove redundant comment Signed-off-by: Hao Lee <1838249551@qq.com> * test:add go ci test for txn Signed-off-by: Hao Lee <1838249551@qq.com> * fix compile error for linux Signed-off-by: Hao Lee <1838249551@qq.com> * update txn go ci test Signed-off-by: Hao Lee <1838249551@qq.com> * update txn for block list pop command Signed-off-by: Hao Lee <1838249551@qq.com> * Improve blpop-related in Redis transactions Signed-off-by: Hao Lee <1838249551@qq.com> * blpop_txn_fix * add some test for go test txn Signed-off-by: Hao Lee <1838249551@qq.com> * update txn integration test Signed-off-by: Hao Lee <1838249551@qq.com> * txn change class to struct Signed-off-by: Hao Lee <1838249551@qq.com> * txn:use weak ptr instead of shared ptr in Cmd Signed-off-by: Hao Lee <1838249551@qq.com> --------- Signed-off-by: Hao Lee <1838249551@qq.com> Co-authored-by: cheniujh <1271435567@qq.com> * FNT * fix:txn compile error in ubuntu (#2128) Signed-off-by: LeeHao <1838249551@qq.com> * using func instead of class private member (#2130) * using func instead of class private member --------- Signed-off-by: Hao Lee <1838249551@qq.com> Signed-off-by: LeeHao <1838249551@qq.com> Co-authored-by: LeeHao <39085999+ForestLH@users.noreply.github.com> Co-authored-by: cheniujh <1271435567@qq.com> Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
* fix: fix select cmd return inconsistent with redis Signed-off-by: Hao Lee <1838249551@qq.com> * refactor:modified lock style while involve db level Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn basic Signed-off-by: Hao Lee <1838249551@qq.com> * fix:merge upstream Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn udpate Signed-off-by: Hao Lee <1838249551@qq.com> * feature:add txn for pika(OpenAtomFoundation#1446) todo:test txn. Just to verify the feasibility of the program. Signed-off-by: Hao Lee <1838249551@qq.com> * update unwatch cmd Add comments Signed-off-by: Hao Lee <1838249551@qq.com> * clear watched key when connection closed Signed-off-by: Hao Lee <1838249551@qq.com> * merge upstream code Signed-off-by: Hao Lee <1838249551@qq.com> * update Signed-off-by: Hao Lee <1838249551@qq.com> * feature: add txn for pika completely Signed-off-by: Hao Lee <1838249551@qq.com> * add set txn failed for modified watch key Signed-off-by: Hao Lee <1838249551@qq.com> * update:reduce the particle size of the lock in txn Signed-off-by: Hao Lee <1838249551@qq.com> * chore:remove redundant comment Signed-off-by: Hao Lee <1838249551@qq.com> * test:add go ci test for txn Signed-off-by: Hao Lee <1838249551@qq.com> * fix compile error for linux Signed-off-by: Hao Lee <1838249551@qq.com> * update txn go ci test Signed-off-by: Hao Lee <1838249551@qq.com> * update txn for block list pop command Signed-off-by: Hao Lee <1838249551@qq.com> * Improve blpop-related in Redis transactions Signed-off-by: Hao Lee <1838249551@qq.com> * blpop_txn_fix * add some test for go test txn Signed-off-by: Hao Lee <1838249551@qq.com> * update txn integration test Signed-off-by: Hao Lee <1838249551@qq.com> * txn change class to struct Signed-off-by: Hao Lee <1838249551@qq.com> * txn:use weak ptr instead of shared ptr in Cmd Signed-off-by: Hao Lee <1838249551@qq.com> --------- Signed-off-by: Hao Lee <1838249551@qq.com> Co-authored-by: cheniujh <1271435567@qq.com>
* Feature/txn (OpenAtomFoundation#1585) * fix: fix select cmd return inconsistent with redis Signed-off-by: Hao Lee <1838249551@qq.com> * refactor:modified lock style while involve db level Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn basic Signed-off-by: Hao Lee <1838249551@qq.com> * fix:merge upstream Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn udpate Signed-off-by: Hao Lee <1838249551@qq.com> * feature:add txn for pika(OpenAtomFoundation#1446) todo:test txn. Just to verify the feasibility of the program. Signed-off-by: Hao Lee <1838249551@qq.com> * update unwatch cmd Add comments Signed-off-by: Hao Lee <1838249551@qq.com> * clear watched key when connection closed Signed-off-by: Hao Lee <1838249551@qq.com> * merge upstream code Signed-off-by: Hao Lee <1838249551@qq.com> * update Signed-off-by: Hao Lee <1838249551@qq.com> * feature: add txn for pika completely Signed-off-by: Hao Lee <1838249551@qq.com> * add set txn failed for modified watch key Signed-off-by: Hao Lee <1838249551@qq.com> * update:reduce the particle size of the lock in txn Signed-off-by: Hao Lee <1838249551@qq.com> * chore:remove redundant comment Signed-off-by: Hao Lee <1838249551@qq.com> * test:add go ci test for txn Signed-off-by: Hao Lee <1838249551@qq.com> * fix compile error for linux Signed-off-by: Hao Lee <1838249551@qq.com> * update txn go ci test Signed-off-by: Hao Lee <1838249551@qq.com> * update txn for block list pop command Signed-off-by: Hao Lee <1838249551@qq.com> * Improve blpop-related in Redis transactions Signed-off-by: Hao Lee <1838249551@qq.com> * blpop_txn_fix * add some test for go test txn Signed-off-by: Hao Lee <1838249551@qq.com> * update txn integration test Signed-off-by: Hao Lee <1838249551@qq.com> * txn change class to struct Signed-off-by: Hao Lee <1838249551@qq.com> * txn:use weak ptr instead of shared ptr in Cmd Signed-off-by: Hao Lee <1838249551@qq.com> --------- Signed-off-by: Hao Lee <1838249551@qq.com> Co-authored-by: cheniujh <1271435567@qq.com> * FNT * fix:txn compile error in ubuntu (OpenAtomFoundation#2128) Signed-off-by: LeeHao <1838249551@qq.com> * using func instead of class private member (OpenAtomFoundation#2130) * using func instead of class private member --------- Signed-off-by: Hao Lee <1838249551@qq.com> Signed-off-by: LeeHao <1838249551@qq.com> Co-authored-by: LeeHao <39085999+ForestLH@users.noreply.github.com> Co-authored-by: cheniujh <1271435567@qq.com> Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
* fix: fix select cmd return inconsistent with redis Signed-off-by: Hao Lee <1838249551@qq.com> * refactor:modified lock style while involve db level Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn basic Signed-off-by: Hao Lee <1838249551@qq.com> * fix:merge upstream Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn udpate Signed-off-by: Hao Lee <1838249551@qq.com> * feature:add txn for pika(OpenAtomFoundation#1446) todo:test txn. Just to verify the feasibility of the program. Signed-off-by: Hao Lee <1838249551@qq.com> * update unwatch cmd Add comments Signed-off-by: Hao Lee <1838249551@qq.com> * clear watched key when connection closed Signed-off-by: Hao Lee <1838249551@qq.com> * merge upstream code Signed-off-by: Hao Lee <1838249551@qq.com> * update Signed-off-by: Hao Lee <1838249551@qq.com> * feature: add txn for pika completely Signed-off-by: Hao Lee <1838249551@qq.com> * add set txn failed for modified watch key Signed-off-by: Hao Lee <1838249551@qq.com> * update:reduce the particle size of the lock in txn Signed-off-by: Hao Lee <1838249551@qq.com> * chore:remove redundant comment Signed-off-by: Hao Lee <1838249551@qq.com> * test:add go ci test for txn Signed-off-by: Hao Lee <1838249551@qq.com> * fix compile error for linux Signed-off-by: Hao Lee <1838249551@qq.com> * update txn go ci test Signed-off-by: Hao Lee <1838249551@qq.com> * update txn for block list pop command Signed-off-by: Hao Lee <1838249551@qq.com> * Improve blpop-related in Redis transactions Signed-off-by: Hao Lee <1838249551@qq.com> * blpop_txn_fix * add some test for go test txn Signed-off-by: Hao Lee <1838249551@qq.com> * update txn integration test Signed-off-by: Hao Lee <1838249551@qq.com> * txn change class to struct Signed-off-by: Hao Lee <1838249551@qq.com> * txn:use weak ptr instead of shared ptr in Cmd Signed-off-by: Hao Lee <1838249551@qq.com> --------- Signed-off-by: Hao Lee <1838249551@qq.com> Co-authored-by: cheniujh <1271435567@qq.com>
* Feature/txn (OpenAtomFoundation#1585) * fix: fix select cmd return inconsistent with redis Signed-off-by: Hao Lee <1838249551@qq.com> * refactor:modified lock style while involve db level Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn basic Signed-off-by: Hao Lee <1838249551@qq.com> * fix:merge upstream Signed-off-by: Hao Lee <1838249551@qq.com> * feature:txn udpate Signed-off-by: Hao Lee <1838249551@qq.com> * feature:add txn for pika(OpenAtomFoundation#1446) todo:test txn. Just to verify the feasibility of the program. Signed-off-by: Hao Lee <1838249551@qq.com> * update unwatch cmd Add comments Signed-off-by: Hao Lee <1838249551@qq.com> * clear watched key when connection closed Signed-off-by: Hao Lee <1838249551@qq.com> * merge upstream code Signed-off-by: Hao Lee <1838249551@qq.com> * update Signed-off-by: Hao Lee <1838249551@qq.com> * feature: add txn for pika completely Signed-off-by: Hao Lee <1838249551@qq.com> * add set txn failed for modified watch key Signed-off-by: Hao Lee <1838249551@qq.com> * update:reduce the particle size of the lock in txn Signed-off-by: Hao Lee <1838249551@qq.com> * chore:remove redundant comment Signed-off-by: Hao Lee <1838249551@qq.com> * test:add go ci test for txn Signed-off-by: Hao Lee <1838249551@qq.com> * fix compile error for linux Signed-off-by: Hao Lee <1838249551@qq.com> * update txn go ci test Signed-off-by: Hao Lee <1838249551@qq.com> * update txn for block list pop command Signed-off-by: Hao Lee <1838249551@qq.com> * Improve blpop-related in Redis transactions Signed-off-by: Hao Lee <1838249551@qq.com> * blpop_txn_fix * add some test for go test txn Signed-off-by: Hao Lee <1838249551@qq.com> * update txn integration test Signed-off-by: Hao Lee <1838249551@qq.com> * txn change class to struct Signed-off-by: Hao Lee <1838249551@qq.com> * txn:use weak ptr instead of shared ptr in Cmd Signed-off-by: Hao Lee <1838249551@qq.com> --------- Signed-off-by: Hao Lee <1838249551@qq.com> Co-authored-by: cheniujh <1271435567@qq.com> * FNT * fix:txn compile error in ubuntu (OpenAtomFoundation#2128) Signed-off-by: LeeHao <1838249551@qq.com> * using func instead of class private member (OpenAtomFoundation#2130) * using func instead of class private member --------- Signed-off-by: Hao Lee <1838249551@qq.com> Signed-off-by: LeeHao <1838249551@qq.com> Co-authored-by: LeeHao <39085999+ForestLH@users.noreply.github.com> Co-authored-by: cheniujh <1271435567@qq.com> Co-authored-by: Xin.Zh <dragoncharlie@foxmail.com>
Fixes: #1446
验证一下代码思路,留了一些注释方便看,还有一些测试功能未做完
请老师们帮忙看一下实现思路有没有问题,感谢
7月16日更新
flushall
命令,会在整个事务的执行期间,锁住所有的db,和没有事务时,加锁方式保持一致flushdb
命令,会在将这个db给加锁,直到事务执行结束,才会释放具体更改:
select
命令的话,在入队的时候不会检测,只有在exec
的时候才会去执行select
命令,但是pika却会在select
命令的SelectCmd::DoInitial()
函数会执行后面切换db的参数检测,所以,将其移到Do
函数中去Cmd
抽象类的Execute
方法,这个Cmd::Execute()
方法在基类中的实现我觉得是有点儿冗余的,直接在具体的命令中的Execute
函数中实现就好了flushall
和flushdb
这两个命令的加锁方法给修改了一下,做出了一个不加锁的DoWithoutLock
函数,方便在事务中去调用ExecCmd::SetCmdsVec()
函数用于在ExecCmd::Lock()
和ExecCmd::Do()
执行前,给构造出一个带有各种信息的cmd的队列,因为cmd是不带比如slot或者是db这类信息的,但是在Do函数中没法拿到,因为去get这些信息的函数里面都有锁,可是在执行Do()
函数时候已经加好锁了,所以必须提前准备好。ExecCmd
类中增加几个hash set或者是hash map,为了记录加锁的资源lock_db_
:涉及到的db就会加锁,只有flushall
和flushdb
会往里面加lock_slot_keys_
:涉及到的keys,普通命令会往里面加r_lock_slots_
:涉及到的slot,以加读锁的方式去加锁is_lock_rm_slots_
:是否锁了PikaReplicaManager::slots_rw_
,就是flushall
和flushdb
会锁