-
Notifications
You must be signed in to change notification settings - Fork 131
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
feed downstream by relay log at startup if need #883
Changes from 13 commits
5767a31
b764a25
8876d36
2acc6fa
3604ca6
95e28ff
56877bb
81db7e5
ae18878
8107f2f
5bd613a
d919746
d341425
bb81853
002d449
34cb18e
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 |
---|---|---|
|
@@ -19,6 +19,9 @@ import ( | |
"sync" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/pingcap/log" | ||
"go.uber.org/zap" | ||
|
||
// mysql driver | ||
_ "github.com/go-sql-driver/mysql" | ||
pkgsql "github.com/pingcap/tidb-binlog/pkg/sql" | ||
|
@@ -35,10 +38,13 @@ type MysqlCheckPoint struct { | |
schema string | ||
table string | ||
|
||
CommitTS int64 `toml:"commitTS" json:"commitTS"` | ||
TsMap map[string]int64 `toml:"ts-map" json:"ts-map"` | ||
StatusSaved int `toml:"status" json:"status"` | ||
CommitTS int64 `toml:"commitTS" json:"commitTS"` | ||
TsMap map[string]int64 `toml:"ts-map" json:"ts-map"` | ||
} | ||
|
||
var _ CheckPoint = &MysqlCheckPoint{} | ||
|
||
var sqlOpenDB = pkgsql.OpenDB | ||
|
||
func newMysql(cfg *Config) (CheckPoint, error) { | ||
|
@@ -68,6 +74,16 @@ func newMysql(cfg *Config) (CheckPoint, error) { | |
return nil, errors.Annotatef(err, "exec failed, sql: %s", sql) | ||
} | ||
|
||
if sp.clusterID == 0 { | ||
id, err := getClusterID(db, sp.schema, sp.table) | ||
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. This logic is very weird. 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. I file an issue about it #889 |
||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
log.Info("set cluster id", zap.Uint64("id", id)) | ||
sp.clusterID = id | ||
} | ||
|
||
err = sp.Load() | ||
return sp, errors.Trace(err) | ||
} | ||
|
@@ -106,7 +122,7 @@ func (sp *MysqlCheckPoint) Load() error { | |
} | ||
|
||
// Save implements checkpoint.Save interface | ||
func (sp *MysqlCheckPoint) Save(ts, slaveTS int64) error { | ||
func (sp *MysqlCheckPoint) Save(ts, slaveTS int64, status int) error { | ||
sp.Lock() | ||
defer sp.Unlock() | ||
|
||
|
@@ -115,6 +131,7 @@ func (sp *MysqlCheckPoint) Save(ts, slaveTS int64) error { | |
} | ||
|
||
sp.CommitTS = ts | ||
sp.StatusSaved = status | ||
|
||
if slaveTS > 0 { | ||
sp.TsMap["master-ts"] = ts | ||
|
@@ -135,6 +152,14 @@ func (sp *MysqlCheckPoint) Save(ts, slaveTS int64) error { | |
return nil | ||
} | ||
|
||
// Status implements CheckPoint.Status interface | ||
func (sp *MysqlCheckPoint) Status() int { | ||
sp.RLock() | ||
defer sp.RUnlock() | ||
|
||
return sp.StatusSaved | ||
} | ||
|
||
// TS implements CheckPoint.TS interface | ||
func (sp *MysqlCheckPoint) TS() int64 { | ||
sp.RLock() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 checkpoint | ||
|
||
import ( | ||
"github.com/DATA-DOG/go-sqlmock" | ||
. "github.com/pingcap/check" | ||
"github.com/pingcap/errors" | ||
) | ||
|
||
var _ = Suite(&testUtil{}) | ||
|
||
type testUtil struct{} | ||
|
||
func (t *testUtil) TestG(c *C) { | ||
tests := []struct { | ||
name string | ||
rows []uint64 | ||
id uint64 | ||
err bool | ||
checkSpecifiedErr error | ||
}{ | ||
{"no row", nil, 0, true, ErrNoCheckpointItem}, | ||
{"on row", []uint64{1}, 1, false, nil}, | ||
{"multi row", []uint64{1, 2}, 0, true, nil}, | ||
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. should the 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. yes, true, nil means the result will be some error but we don't check what kind of error. |
||
} | ||
|
||
for _, test := range tests { | ||
db, mock, err := sqlmock.New() | ||
c.Assert(err, IsNil) | ||
|
||
rows := sqlmock.NewRows([]string{"clusterID"}) | ||
for _, row := range test.rows { | ||
rows.AddRow(row) | ||
} | ||
|
||
mock.ExpectQuery("select clusterID from .*").WillReturnRows(rows) | ||
|
||
c.Log("test: ", test.name) | ||
id, err := getClusterID(db, "schema", "table") | ||
if test.err { | ||
c.Assert(err, NotNil) | ||
c.Assert(id, Equals, test.id) | ||
if test.checkSpecifiedErr != nil { | ||
c.Assert(errors.Cause(err), Equals, test.checkSpecifiedErr) | ||
} | ||
} else { | ||
c.Assert(err, IsNil) | ||
c.Assert(id, Equals, test.id) | ||
} | ||
} | ||
} |
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.
Worth a better name, like
StatusConsistent
andStatusDrained
In fact, I'm not sure what's meaning of it, does it mean the binlog is drained, or reaching a consistent replication state? which one is right?
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.
Good Change!
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.
rename as
StatusConsistent
002d449