This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
/
job.go
165 lines (146 loc) · 3.68 KB
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package syncer
import (
"fmt"
"github.com/siddontang/go-mysql/mysql"
"github.com/pingcap/dm/pkg/gtid"
)
type opType byte
const (
null opType = iota
insert
update
del
ddl
xid
flush
skip // used by Syncer.recordSkipSQLsPos to record global pos, but not execute SQL
rotate
)
func (t opType) String() string {
switch t {
case insert:
return "insert"
case update:
return "update"
case del:
return "delete"
case ddl:
return "ddl"
case xid:
return "xid"
case flush:
return "flush"
case skip:
return "skip"
case rotate:
return "rotate"
}
return ""
}
type job struct {
tp opType
sourceSchema string
sourceTable string
targetSchema string
targetTable string
sql string
args []interface{}
key string
retry bool
pos mysql.Position
currentPos mysql.Position // exactly binlog position of current SQL
gtidSet gtid.Set
ddlExecItem *DDLExecItem
ddls []string
traceID string
traceGID string
}
func (j *job) String() string {
// only output some important information, maybe useful in execution.
return fmt.Sprintf("sql: %s, args: %v, key: %s, last_pos: %s, current_pos: %s, gtid:%v", j.sql, j.args, j.key, j.pos, j.currentPos, j.gtidSet)
}
func newJob(tp opType, sourceSchema, sourceTable, targetSchema, targetTable, sql string, args []interface{}, key string, pos, cmdPos mysql.Position, currentGtidSet gtid.Set, traceID string) *job {
var gs gtid.Set
if currentGtidSet != nil {
gs = currentGtidSet.Clone()
}
return &job{
tp: tp,
sourceSchema: sourceSchema,
sourceTable: sourceTable,
targetSchema: targetSchema,
targetTable: targetTable,
sql: sql,
args: args,
key: key,
pos: pos,
currentPos: cmdPos,
gtidSet: gs,
retry: true,
traceID: traceID,
}
}
func newDDLJob(ddlInfo *shardingDDLInfo, ddls []string, pos, cmdPos mysql.Position, currentGtidSet gtid.Set, ddlExecItem *DDLExecItem, traceID string) *job {
var gs gtid.Set
if currentGtidSet != nil {
gs = currentGtidSet.Clone()
}
j := &job{
tp: ddl,
ddls: ddls,
pos: pos,
currentPos: cmdPos,
gtidSet: gs,
ddlExecItem: ddlExecItem,
traceID: traceID,
}
if ddlInfo != nil {
j.sourceSchema = ddlInfo.tableNames[0][0].Schema
j.sourceTable = ddlInfo.tableNames[0][0].Name
j.targetSchema = ddlInfo.tableNames[1][0].Schema
j.targetTable = ddlInfo.tableNames[1][0].Name
}
if ddlExecItem != nil && ddlExecItem.req != nil {
j.traceGID = ddlExecItem.req.TraceGID
}
return j
}
func newXIDJob(pos, cmdPos mysql.Position, currentGtidSet gtid.Set, traceID string) *job {
var gs gtid.Set
if currentGtidSet != nil {
gs = currentGtidSet.Clone()
}
return &job{
tp: xid,
pos: pos,
currentPos: cmdPos,
gtidSet: gs,
traceID: traceID,
}
}
func newFlushJob() *job {
return &job{tp: flush}
}
func newSkipJob(pos mysql.Position, currentGtidSet gtid.Set) *job {
return &job{
tp: skip,
pos: pos,
gtidSet: currentGtidSet,
}
}
// put queues into bucket to monitor them
func queueBucketName(queueID int) string {
return fmt.Sprintf("q_%d", queueID%defaultBucketCount)
}