Skip to content
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

fix:slave parse tnx binlog failed #2642

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/pika_transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ExecCmd : public Cmd {
void Split(const HintKeys& hint_keys) override {}
void Merge() override {}
std::vector<std::string> current_key() const override { return {}; }

void Execute() override;
private:
struct CmdInfo {
public:
Expand Down
41 changes: 23 additions & 18 deletions src/pika_transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include "include/pika_transaction.h"
#include "include/pika_admin.h"
#include "include/pika_client_conn.h"
#include "include/pika_define.h"
#include "include/pika_list.h"
#include "include/pika_rm.h"
#include "include/pika_server.h"
#include "include/pika_transaction.h"
#include "src/pstd/include/scope_record_lock.h"

extern std::unique_ptr<PikaServer> g_pika_server;
Expand Down Expand Up @@ -42,22 +42,6 @@ void MultiCmd::DoInitial() {
void ExecCmd::Do() {
auto conn = GetConn();
auto client_conn = std::dynamic_pointer_cast<PikaClientConn>(conn);
if (client_conn == nullptr) {
res_.SetRes(CmdRes::kErrOther, name());
return;
}
if (!client_conn->IsInTxn()) {
res_.SetRes(CmdRes::kErrOther, "EXEC without MULTI");
return;
}
if (IsTxnFailedAndSetState()) {
client_conn->ExitTxn();
return;
}
SetCmdsVec();
Lock();
conn = GetConn();
client_conn = std::dynamic_pointer_cast<PikaClientConn>(conn);
std::vector<CmdRes> res_vec = {};
std::vector<std::shared_ptr<std::string>> resp_strs;
for (size_t i = 0; i < cmds_.size(); ++i) {
Expand Down Expand Up @@ -96,9 +80,30 @@ void ExecCmd::Do() {
});

res_.AppendArrayLen(res_vec.size());
for (auto &r : res_vec) {
for (auto& r : res_vec) {
res_.AppendStringRaw(r.message());
}
}

void ExecCmd::Execute() {
auto conn = GetConn();
auto client_conn = std::dynamic_pointer_cast<PikaClientConn>(conn);
if (client_conn == nullptr) {
res_.SetRes(CmdRes::kErrOther, name());
return;
}
if (!client_conn->IsInTxn()) {
res_.SetRes(CmdRes::kErrOther, "EXEC without MULTI");
return;
}
if (IsTxnFailedAndSetState()) {
client_conn->ExitTxn();
return;
}
SetCmdsVec();
Lock();
Do();

Unlock();
ServeToBLrPopWithKeys();
list_cmd_.clear();
Expand Down
49 changes: 46 additions & 3 deletions tests/integration/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,9 @@ var _ = Describe("should replication ", func() {
for i := int64(0); i < clientMaster.LLen(ctx, "list0").Val(); i++ {
Expect(clientMaster.LIndex(ctx, "list0", i)).To(Equal(clientSlave.LIndex(ctx, "list0", i)))
}
// for i := int64(0); i < clientMaster.LLen(ctx, "list1").Val(); i++ {
// Expect(clientMaster.LIndex(ctx, "list1", i)).To(Equal(clientSlave.LIndex(ctx, "list1", i)))
// }
// for i := int64(0); i < clientMaster.LLen(ctx, "list1").Val(); i++ {
// Expect(clientMaster.LIndex(ctx, "list1", i)).To(Equal(clientSlave.LIndex(ctx, "list1", i)))
// }
}
err = clientMaster.Del(ctx, lists...)

Expand Down Expand Up @@ -738,6 +738,49 @@ var _ = Describe("should replication ", func() {
Expect(r.Err()).To(MatchError("ERR EXEC without MULTI"))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以加上一行注释说明这个测试的目的是为了issue2643:
//The test below is related with issue: #2643

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以加上一行注释说明这个测试的目的是为了issue2643: //The test below is related with issue: #2643

done

err = clientMaster.Del(ctx, "txkey1")

//The test below is related with issue: https://github.com/OpenAtomFoundation/pika/issues/2643
r1 := clientMaster.Do(ctx, "MULTI")
Expect(r1.Err()).NotTo(HaveOccurred())

setkey1 := clientMaster.Set(ctx, "Tnxkey1", "Tnxvalue1", 0)
Expect(setkey1.Err()).NotTo(HaveOccurred())
Expect(setkey1.Val()).To(Equal("QUEUED"))

setkey2 := clientMaster.Set(ctx, "Tnxkey2", "Tnxvalue2", 0)
Expect(setkey2.Err()).NotTo(HaveOccurred())
Expect(get.Val()).To(Equal("QUEUED"))

r2 := clientMaster.Do(ctx, "EXEC")
Expect(r2.Err()).NotTo(HaveOccurred())
Expect(r2.Val()).To(Equal([]interface{}{"OK", "OK"}))

time.Sleep(3 * time.Second)

getkey1 := clientSlave.Get(ctx, "Tnxkey1")
Expect(getkey1.Err()).NotTo(HaveOccurred())
Expect(getkey1.Val()).To(Equal("Tnxvalue1"))

getkey2 := clientSlave.Get(ctx, "Tnxkey2")
Expect(getkey2.Err()).NotTo(HaveOccurred())
Expect(getkey2.Val()).To(Equal("Tnxvalue2"))

ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
loopCount := 0

for loopCount < 10 {
select {
case <-ticker.C:
infoResExec := clientSlave.Info(ctx, "replication")
Expect(infoResExec.Err()).NotTo(HaveOccurred())
Expect(infoResExec.Val()).To(ContainSubstring("master_link_status:up"))
loopCount++
if loopCount >= 10 {
ticker.Stop()
}
}
}
log.Println("master-slave replication test success")
})

Expand Down
Loading