-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Charset parameter for Mysql connection #1027
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
Open
sigalikanevsky
wants to merge
38
commits into
go-mysql-org:master
Choose a base branch
from
RiveryIO:bugfix/DEV-13143
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
ef55c4c
Added waitTimeBetweenConnection check
eitamring 6855741
Added safe conn close
eitamring e6565cd
Added file name to each event
eitamring cb4f084
Added gtid to each event
eitamring 8d7d13c
Removed FlushBinlog which was only used for testing
eitamring f81397d
Fixed testing
eitamring f77308e
Merge pull request #1 from RiveryIO/feature/eitam/removed_flush_for_t…
eitamring 824d650
Added delete on table when deleted
eitamring 61a148b
probably grammar
eitamring 8cc642f
Merge pull request #2 from RiveryIO/fix/eitam/add_skip_when_table_is_…
eitamring 05b87bb
Removed spamming log
eitamring 2025086
Merge pull request #3 from RiveryIO/feature/eitam/removed_spaming_log
eitamring fa2e8fa
Added covert to string interface if needed
eitamring e95e5cd
Merge pull request #4 from RiveryIO/feature/eitam/support_base64_byte…
eitamring fdd11a6
Remove unneeded log on SP
eitamring d947c9e
Merge pull request #5 from RiveryIO/feautre/eitam/remove_uneeded_log_…
eitamring 73477d3
Change mysql_date default zero based value to nil
eitamring eb2ea8e
Merge pull request #6 from RiveryIO/feature/eitam/add_nil_based_value…
eitamring 007d419
Change mysql_MYSQL_TYPE_TIMESTAMP2 and MYSQL_TYPE_TIMESTAMP to be def…
eitamring c6c9248
Merge pull request #7 from RiveryIO/feature/eitam/add_nil_based_value…
eitamring d15a7ce
Change decodeDatetime2 default to zero
eitamring 4298599
Merge pull request #8 from RiveryIO/feature/eitam/add_nil_based_value…
eitamring 1f7d701
Change decodeTimestamp2 to return nil in case sec = 0
eitamring 98108dd
Merge pull request #9 from RiveryIO/fix/eitam/decode_timestamp
eitamring 411b75d
Add limit to max host name length
eitamring 9bd5965
Merge pull request #10 from RiveryIO/feature/eitam/limit_max_host_name
eitamring c349655
Change log debug level
eitamring e7d51c3
Merge pull request #12 from RiveryIO/feature/eitam/change_log_debug_s…
eitamring c3593a7
add latin support
sigalikanevsky fd2c582
add latin support
sigalikanevsky 3d213ae
add latin support
sigalikanevsky b34a98d
add latin support
sigalikanevsky 7222b87
add latin support
sigalikanevsky b4851e0
add latin support
sigalikanevsky b939f18
move to function
sigalikanevsky 88f0609
move to function
sigalikanevsky 0799a57
fixes and tests
sigalikanevsky a2053cd
fixes
sigalikanevsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,10 @@ func NewCanal(cfg *Config) (*Canal, error) { | |
|
||
c.ctx, c.cancel = context.WithCancel(context.Background()) | ||
|
||
if cfg.WaitTimeBetweenConnectionSeconds > 0 { | ||
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. it should be |
||
cfg.WaitTimeBetweenConnectionSeconds = time.Duration(5) * time.Second | ||
} | ||
|
||
c.dumpDoneCh = make(chan struct{}) | ||
c.eventHandler = &DummyEventHandler{} | ||
c.parser = parser.New() | ||
|
@@ -192,6 +196,7 @@ func (c *Canal) RunFrom(pos mysql.Position) error { | |
return c.Run() | ||
} | ||
|
||
// Start from selected GTIDSet | ||
func (c *Canal) StartFromGTID(set mysql.GTIDSet) error { | ||
c.master.UpdateGTIDSet(set) | ||
|
||
|
@@ -238,15 +243,17 @@ func (c *Canal) run() error { | |
} | ||
|
||
func (c *Canal) Close() { | ||
log.Infof("closing canal") | ||
log.Debugf("closing canal") | ||
c.m.Lock() | ||
defer c.m.Unlock() | ||
|
||
c.cancel() | ||
c.syncer.Close() | ||
c.connLock.Lock() | ||
c.conn.Close() | ||
c.conn = nil | ||
if c.conn != nil { | ||
c.conn.Close() | ||
c.conn = nil | ||
} | ||
c.connLock.Unlock() | ||
|
||
_ = c.eventHandler.OnPosSynced(c.master.Position(), c.master.GTIDSet(), true) | ||
|
@@ -413,20 +420,21 @@ func (c *Canal) checkBinlogRowFormat() error { | |
|
||
func (c *Canal) prepareSyncer() error { | ||
cfg := replication.BinlogSyncerConfig{ | ||
ServerID: c.cfg.ServerID, | ||
Flavor: c.cfg.Flavor, | ||
User: c.cfg.User, | ||
Password: c.cfg.Password, | ||
Charset: c.cfg.Charset, | ||
HeartbeatPeriod: c.cfg.HeartbeatPeriod, | ||
ReadTimeout: c.cfg.ReadTimeout, | ||
UseDecimal: c.cfg.UseDecimal, | ||
ParseTime: c.cfg.ParseTime, | ||
SemiSyncEnabled: c.cfg.SemiSyncEnabled, | ||
MaxReconnectAttempts: c.cfg.MaxReconnectAttempts, | ||
DisableRetrySync: c.cfg.DisableRetrySync, | ||
TimestampStringLocation: c.cfg.TimestampStringLocation, | ||
TLSConfig: c.cfg.TLSConfig, | ||
ServerID: c.cfg.ServerID, | ||
Flavor: c.cfg.Flavor, | ||
User: c.cfg.User, | ||
Password: c.cfg.Password, | ||
Charset: c.cfg.Charset, | ||
HeartbeatPeriod: c.cfg.HeartbeatPeriod, | ||
ReadTimeout: c.cfg.ReadTimeout, | ||
UseDecimal: c.cfg.UseDecimal, | ||
ParseTime: c.cfg.ParseTime, | ||
SemiSyncEnabled: c.cfg.SemiSyncEnabled, | ||
MaxReconnectAttempts: c.cfg.MaxReconnectAttempts, | ||
DisableRetrySync: c.cfg.DisableRetrySync, | ||
TimestampStringLocation: c.cfg.TimestampStringLocation, | ||
TLSConfig: c.cfg.TLSConfig, | ||
WaitTimeBetweenConnectionSeconds: c.cfg.WaitTimeBetweenConnectionSeconds, | ||
} | ||
|
||
if strings.Contains(c.cfg.Addr, "/") { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package canal | |
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"sync/atomic" | ||
"time" | ||
|
||
|
@@ -22,15 +23,15 @@ func (c *Canal) startSyncer() (*replication.BinlogStreamer, error) { | |
if err != nil { | ||
return nil, errors.Errorf("start sync replication at binlog %v error %v", pos, err) | ||
} | ||
log.Infof("start sync binlog at binlog file %v", pos) | ||
log.Debugf("start sync binlog at binlog file %v", pos) | ||
return s, nil | ||
} else { | ||
gsetClone := gset.Clone() | ||
s, err := c.syncer.StartSyncGTID(gset) | ||
if err != nil { | ||
return nil, errors.Errorf("start sync replication at GTID set %v error %v", gset, err) | ||
} | ||
log.Infof("start sync binlog at GTID set %v", gsetClone) | ||
log.Debugf("start sync binlog at GTID set %v", gsetClone) | ||
return s, nil | ||
} | ||
} | ||
|
@@ -65,7 +66,7 @@ func (c *Canal) runSyncBinlog() error { | |
switch e := ev.Event.(type) { | ||
case *replication.RotateEvent: | ||
fakeRotateLogName = string(e.NextLogName) | ||
log.Infof("received fake rotate event, next log name is %s", e.NextLogName) | ||
log.Debugf("received fake rotate event, next log name is %s", e.NextLogName) | ||
} | ||
|
||
continue | ||
|
@@ -92,7 +93,7 @@ func (c *Canal) runSyncBinlog() error { | |
case *replication.RotateEvent: | ||
pos.Name = string(e.NextLogName) | ||
pos.Pos = uint32(e.Position) | ||
log.Infof("rotate binlog to %s", pos) | ||
log.Debugf("rotate binlog to %s", pos) | ||
savePos = true | ||
force = true | ||
if err = c.eventHandler.OnRotate(e); err != nil { | ||
|
@@ -142,7 +143,15 @@ func (c *Canal) runSyncBinlog() error { | |
case *replication.QueryEvent: | ||
stmts, _, err := c.parser.Parse(string(e.Query), "", "") | ||
if err != nil { | ||
log.Errorf("parse query(%s) err %v, will skip this event", e.Query, err) | ||
msg := err.Error() | ||
if strings.Contains(strings.ToLower(msg), strings.ToLower("procedure")) { | ||
// Cut the first row from the message since it contain the procedure call and not the entire message | ||
fl := strings.Split(msg, "\n") | ||
log.Debugf("parse SP Error: (%s)", fl[0]) | ||
} else { | ||
log.Debugf("parse query(%s) err %v", e.Query, err) | ||
} | ||
log.Debugln("will skip this event") | ||
continue | ||
} | ||
for _, stmt := range stmts { | ||
|
@@ -232,7 +241,7 @@ func parseStmt(stmt ast.StmtNode) (ns []*node) { | |
|
||
func (c *Canal) updateTable(db, table string) (err error) { | ||
c.ClearTableCache([]byte(db), []byte(table)) | ||
log.Infof("table structure changed, clear table cache: %s.%s\n", db, table) | ||
log.Debugf("table structure changed, clear table cache: %s.%s\n", db, table) | ||
if err = c.eventHandler.OnTableChanged(db, table); err != nil && errors.Cause(err) != schema.ErrTableNotExist { | ||
return errors.Trace(err) | ||
} | ||
|
@@ -270,38 +279,10 @@ func (c *Canal) handleRowsEvent(e *replication.BinlogEvent) error { | |
return errors.Errorf("%s not supported now", e.Header.EventType) | ||
} | ||
events := newRowsEvent(t, action, ev.Rows, e.Header) | ||
events.Header.Gtid = c.SyncedGTIDSet() | ||
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. Can you explain why this is changed? |
||
return c.eventHandler.OnRow(events) | ||
} | ||
|
||
func (c *Canal) FlushBinlog() error { | ||
_, err := c.Execute("FLUSH BINARY LOGS") | ||
return errors.Trace(err) | ||
} | ||
|
||
func (c *Canal) WaitUntilPos(pos mysql.Position, timeout time.Duration) error { | ||
timer := time.NewTimer(timeout) | ||
for { | ||
select { | ||
case <-timer.C: | ||
return errors.Errorf("wait position %v too long > %s", pos, timeout) | ||
default: | ||
err := c.FlushBinlog() | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
curPos := c.master.Position() | ||
if curPos.Compare(pos) >= 0 { | ||
return nil | ||
} else { | ||
log.Debugf("master pos is %v, wait catching %v", curPos, pos) | ||
time.Sleep(100 * time.Millisecond) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Canal) GetMasterPos() (mysql.Position, error) { | ||
rr, err := c.Execute("SHOW MASTER STATUS") | ||
if err != nil { | ||
|
@@ -336,12 +317,3 @@ func (c *Canal) GetMasterGTIDSet() (mysql.GTIDSet, error) { | |
} | ||
return gset, nil | ||
} | ||
|
||
func (c *Canal) CatchMasterPos(timeout time.Duration) error { | ||
pos, err := c.GetMasterPos() | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
return c.WaitUntilPos(pos, timeout) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
the log level should be kept, other developers may rely on this behaviour.
Also for other files.