-
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
Changes from 5 commits
e06e24d
afa99e1
7ff7a4b
0258654
d5bdcb8
376cf0f
b6198ff
9c2131c
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 |
---|---|---|
|
@@ -186,28 +186,29 @@ std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st | |
} | ||
} | ||
|
||
// Process Command | ||
c_ptr->Execute(); | ||
time_stat_->process_done_ts_ = pstd::NowMicros(); | ||
auto cmdstat_map = g_pika_cmd_table_manager->GetCommandStatMap(); | ||
(*cmdstat_map)[opt].cmd_count.fetch_add(1); | ||
(*cmdstat_map)[opt].cmd_time_consuming.fetch_add(time_stat_->total_time()); | ||
|
||
if (c_ptr->res().ok() && c_ptr->is_write() && name() != kCmdNameExec) { | ||
LOG(INFO) << c_ptr->name(); | ||
if (c_ptr->name() == kCmdNameFlushdb) { | ||
auto flushdb = std::dynamic_pointer_cast<FlushdbCmd>(c_ptr); | ||
SetTxnFailedFromDBs(flushdb->GetFlushDBname()); | ||
SetTxnFailedIfKeyExists(flushdb->GetFlushDBname()); | ||
} else if (c_ptr->name() == kCmdNameFlushall) { | ||
SetAllTxnFailed(); | ||
SetTxnFailedIfKeyExists(); | ||
} else { | ||
auto table_keys = c_ptr->current_key(); | ||
for (auto& key : table_keys) { | ||
key = c_ptr->db_name().append(key); | ||
key = c_ptr->db_name().append("_").append(key); | ||
} | ||
SetTxnFailedFromKeys(table_keys); | ||
} | ||
} | ||
|
||
// Process Command | ||
c_ptr->Execute(); | ||
time_stat_->process_done_ts_ = pstd::NowMicros(); | ||
auto cmdstat_map = g_pika_cmd_table_manager->GetCommandStatMap(); | ||
(*cmdstat_map)[opt].cmd_count.fetch_add(1); | ||
(*cmdstat_map)[opt].cmd_time_consuming.fetch_add(time_stat_->total_time()); | ||
|
||
if (g_pika_conf->slowlog_slower_than() >= 0) { | ||
ProcessSlowlog(argv, c_ptr->GetDoDuration()); | ||
} | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
如果一个client watch 了一个 key,就算这个 key 是被这个 client 自己修改的,这个 watch 也会失效。redis 是这个逻辑,所以去除了和这个判断 |
||
c->SetTxnWatchFailState(true); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void PikaClientConn::SetAllTxnFailed() { | ||
// if key in target_db exists, then the key been watched multi will be failed | ||
void PikaClientConn::SetTxnFailedIfKeyExists(std::string target_db_name) { | ||
auto dispatcher = dynamic_cast<net::DispatchThread*>(server_thread()); | ||
if (dispatcher != nullptr) { | ||
auto involved_conns = dispatcher->GetAllTxns(); | ||
for (auto& conn : involved_conns) { | ||
if (auto c = std::dynamic_pointer_cast<PikaClientConn>(conn); c != nullptr && c.get() != this) { | ||
c->SetTxnWatchFailState(true); | ||
} | ||
} | ||
if (dispatcher == nullptr) { | ||
return; | ||
} | ||
} | ||
auto involved_conns = dispatcher->GetAllTxns(); | ||
for (auto& conn : involved_conns) { | ||
std::shared_ptr<PikaClientConn> c; | ||
if (c = std::dynamic_pointer_cast<PikaClientConn>(conn); c == nullptr) { | ||
continue; | ||
} | ||
|
||
void PikaClientConn::SetTxnFailedFromDBs(std::string db_name) { | ||
auto dispatcher = dynamic_cast<net::DispatchThread*>(server_thread()); | ||
if (dispatcher != nullptr) { | ||
auto involved_conns = dispatcher->GetDBTxns(db_name); | ||
for (auto& conn : involved_conns) { | ||
if (auto c = std::dynamic_pointer_cast<PikaClientConn>(conn); c != nullptr && c.get() != this) { | ||
c->SetTxnWatchFailState(true); | ||
for (const auto& db_key : c->watched_db_keys_) { | ||
size_t pos = db_key.find('_'); | ||
if (pos == std::string::npos) { | ||
continue; | ||
} | ||
|
||
auto db_name = db_key.substr(0, pos); | ||
auto key = db_key.substr(pos + 1); | ||
|
||
if (target_db_name == "" || target_db_name == "all" || target_db_name == db_name) { | ||
auto db = g_pika_server->GetDB(db_name); | ||
// if watched key exists, set watch state to failed | ||
if (db->storage()->Exists({key}) > 0) { | ||
c->SetTxnWatchFailState(true); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,14 +57,14 @@ void ExecCmd::Do() { | |
if (cmd->name() == kCmdNameFlushall) { | ||
auto flushall = std::dynamic_pointer_cast<FlushallCmd>(cmd); | ||
flushall->FlushAllWithoutLock(); | ||
client_conn->SetAllTxnFailed(); | ||
client_conn->SetTxnFailedIfKeyExists(); | ||
} else if (cmd->name() == kCmdNameFlushdb) { | ||
auto flushdb = std::dynamic_pointer_cast<FlushdbCmd>(cmd); | ||
flushdb->FlushAllDBsWithoutLock(); | ||
if (cmd->res().ok()) { | ||
cmd->res().SetRes(CmdRes::kOk); | ||
} | ||
client_conn->SetTxnFailedFromDBs(each_cmd_info.db_->GetDBName()); | ||
client_conn->SetTxnFailedIfKeyExists(each_cmd_info.db_->GetDBName()); | ||
} else { | ||
cmd->Do(); | ||
if (cmd->res().ok() && cmd->is_write()) { | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
这个下划线是特意加上去的,作为 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.
日志删一下
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