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

Optimize the performance of bidirectional synchronous update table of _drainer_repl_mark (#903) #909

Merged
merged 7 commits into from
Feb 24, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
1.fix code format
freemindLi authored and sre-bot committed Feb 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 65ff6f2fbd5ff6a48776a660b288deba90be3ec7
2 changes: 1 addition & 1 deletion drainer/loopbacksync/loopbacksync.go
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ const (
//MarkTableName mark table name
MarkTableName = "retl._drainer_repl_mark"
//ID syncer worker coroutine id
ID = "coroutineID"
CoroutineID = "coroutine_id"
//ChannelID channel id
ChannelID = "channel_id"
//Val val
4 changes: 2 additions & 2 deletions pkg/loader/executor.go
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ func (e *executor) updateMark(channel string, tx *tx) error {
}
v := e.addIndex()
var args []interface{}
sql := fmt.Sprintf("update %s set %s=%s+1 where %s=? and %s=? limit 1;", loopbacksync.MarkTableName, loopbacksync.Val, loopbacksync.Val, loopbacksync.ID, loopbacksync.ChannelID)
sql := fmt.Sprintf("update %s set %s=%s+1 where %s=? and %s=? limit 1;", loopbacksync.MarkTableName, loopbacksync.Val, loopbacksync.Val, loopbacksync.CoroutineID, loopbacksync.ChannelID)
args = append(args, v, e.info.ChannelID)
_, err1 := tx.autoRollbackExec(sql, args...)
if err1 != nil {
@@ -149,7 +149,7 @@ func (e *executor) initMarkTable() error {
channel := ""
var builder strings.Builder
holder := "(?,?,?,?)"
columns := fmt.Sprintf("(%s,%s,%s,%s) ", loopbacksync.ID, loopbacksync.ChannelID, loopbacksync.Val, loopbacksync.ChannelInfo)
columns := fmt.Sprintf("(%s,%s,%s,%s) ", loopbacksync.CoroutineID, loopbacksync.ChannelID, loopbacksync.Val, loopbacksync.ChannelInfo)
builder.WriteString("REPLACE INTO " + loopbacksync.MarkTableName + columns + " VALUES ")
for i := 0; i < e.workerCount; i++ {
if i > 0 {
2 changes: 1 addition & 1 deletion pkg/loader/model.go
Original file line number Diff line number Diff line change
@@ -192,7 +192,7 @@ func (dml *DML) updateSQL() (sql string, args []interface{}) {
}

func createMarkTableDDL() string {
sql := fmt.Sprintf("CREATE TABLE If Not Exists %s (%s bigint not null,%s bigint not null DEFAULT 0, %s bigint DEFAULT 0, %s varchar(64) ,PRIMARY KEY (%s,%s));", loopbacksync.MarkTableName, loopbacksync.ID, loopbacksync.ChannelID, loopbacksync.Val, loopbacksync.ChannelInfo, loopbacksync.ID, loopbacksync.ChannelID)
sql := fmt.Sprintf("CREATE TABLE If Not Exists %s (%s bigint not null,%s bigint not null DEFAULT 0, %s bigint DEFAULT 0, %s varchar(64) ,PRIMARY KEY (%s,%s));", loopbacksync.MarkTableName, loopbacksync.CoroutineID, loopbacksync.ChannelID, loopbacksync.Val, loopbacksync.ChannelInfo, loopbacksync.CoroutineID, loopbacksync.ChannelID)
return sql
}

4 changes: 2 additions & 2 deletions pkg/loader/model_test.go
Original file line number Diff line number Diff line change
@@ -242,7 +242,7 @@ func (s *SQLSuite) TestUpdateMarkSQL(c *check.C) {
db, mock, err := sqlmock.New()
c.Assert(err, check.IsNil)
defer db.Close()
sql := fmt.Sprintf("update %s set %s=%s+1 where %s=? and %s=? limit 1;", loopbacksync.MarkTableName, loopbacksync.Val, loopbacksync.Val, loopbacksync.ID, loopbacksync.ChannelID)
sql := fmt.Sprintf("update %s set %s=%s+1 where %s=? and %s=? limit 1;", loopbacksync.MarkTableName, loopbacksync.Val, loopbacksync.Val, loopbacksync.CoroutineID, loopbacksync.ChannelID)
mock.ExpectBegin()
mock.ExpectExec(regexp.QuoteMeta(sql)).
WithArgs(1, 100).WillReturnResult(sqlmock.NewResult(1, 1))
@@ -260,6 +260,6 @@ func (s *SQLSuite) TestUpdateMarkSQL(c *check.C) {
}
func (s *SQLSuite) TestCreateMarkTable(c *check.C) {
sql := createMarkTableDDL()
sql1 := fmt.Sprintf("CREATE TABLE If Not Exists %s (%s bigint not null,%s bigint not null DEFAULT 0, %s bigint DEFAULT 0, %s varchar(64) ,PRIMARY KEY (%s,%s));", loopbacksync.MarkTableName, loopbacksync.ID, loopbacksync.ChannelID, loopbacksync.Val, loopbacksync.ChannelInfo, loopbacksync.ID, loopbacksync.ChannelID)
sql1 := fmt.Sprintf("CREATE TABLE If Not Exists %s (%s bigint not null,%s bigint not null DEFAULT 0, %s bigint DEFAULT 0, %s varchar(64) ,PRIMARY KEY (%s,%s));", loopbacksync.MarkTableName, loopbacksync.CoroutineID, loopbacksync.ChannelID, loopbacksync.Val, loopbacksync.ChannelInfo, loopbacksync.CoroutineID, loopbacksync.ChannelID)
c.Assert(sql, check.Equals, sql1)
}