Comments (18)
I tested in my local machine, mysql server does not close the binlog dump connection even if the underlying tcp connection is lost(or in close_wait state).
until there is a new event to be send, mysql will check and clean the bad connections
Seemingly no good solution for this
Add tcp keepalive can avoid unplug the network cable situation but has no effect on the removal of bad connections
from go-mysql.
Hi @3manuek
The HEARTBEAT_EVENT is sent by the master periodically. We can add MASTER_HEARTBEAT_PERIOD
configuration.
If set (>0, maybe should better > the time configured in MySQL), we will set read timeout for the connection, and we will retry after the connection is closed.
from go-mysql.
Hi @iampastor
I think we can add a read timeout here. But if the connection is good and we don't receive any binlog from MySQL after the timeout, the connection will be closed too and go-mysql will reconnect it.
Another way is to update the TCP heartbeat interval parameters with sysctrl.
from go-mysql.
@siddontang ye, this is what I did, adding a read timeout, but I think this is not a very good solution, Does mysql replication have any heart beat message or other keep alive mechanism so that we can check whether the connection is bad?
from go-mysql.
@iampastor
MySQL replication has no heartbeat message, so I can't figure out other ways.
from go-mysql.
@siddontang
ok, I see. thanks a lot. I will use time out to check the connection.
from go-mysql.
Thanks @iampastor
You can send me a PR.
from go-mysql.
@iampastor You can keep the coordinates, retry the connection after timeout and set a limit to the loop.
@siddontang I see that you can enable heartbeat by using semi-sync through Slave_heartbeat_period, don't know how the underlying protocol works tho :( .
from go-mysql.
Hi @3manuek , I don't find any protocol document on how to support Slave_heartbeat_period
😭
from go-mysql.
Yeah, the only entry on the docs is this one. So, I dug into the Binlog_sender::send_heartbeat_event at sql/rpl_binlog_sender.cc and I see that it is just an "empty" event (it only has the checksum if enabled).
But mostly it just sets the header and nothing more:
/* Timestamp field */
int4store(header, 0);
header[EVENT_TYPE_OFFSET] = binary_log::HEARTBEAT_LOG_EVENT;
int4store(header + SERVER_ID_OFFSET, server_id);
int4store(header + EVENT_LEN_OFFSET, event_len);
int4store(header + LOG_POS_OFFSET, static_cast<uint32>(log_pos));
int2store(header + FLAGS_OFFSET, 0);
So dealing with it shouldn't be more issue as it is a generic event \o/
The tricky part I guess will be how to deal with the timeout tho. The MASTER_HEARTBEAT_PERIOD
can be set at replication.BinlogSyncerConfig
, but a timer should be set at the beginning of the streamer and reset on each heartbeat event. Seems like it can be handled manually outside the library by just providing the necessary interface to handle the event (it can be up to the user on how to deal with it).
from go-mysql.
just use "SELECT 'x'" to keep the coordinates?
from go-mysql.
if client.conn is closed periodically,connection maybe not close on master.
issue like this: alibaba/canal#139
from go-mysql.
Hi @lkpjj
Can mysql keepalive not close the tombstone connection? Seem this is the problem for all client connections.
from go-mysql.
How about TCP keepAlive ?
Like this:
Add a extra function with a tcp-keep-alive paramter in package client/conn.go
func ConnectWithKeepAlive(keepd time.Duration) {
// ...
// ... same as Connect() method
conn, err := net.DialTimeout(proto, addr, 10*time.Second)
if err != nil {
return nil, errors.Trace(err)
}
if tcpConn, ok :=conn.(*net.TCPConn); ok && keepd > 0 {
err = tcpConn.SetKeepAlive(true)
if err != nil {
return nil, errors.Trace(err)
}
err = tcpConn.SetKeepAlivePeriod(keepd)
if err != nil {
return nil, errors.Trace(err)
}
}
c.Conn = packet.NewConn(conn)
// ... same as Connect() method
// ...
}
And then use it in package replication/binlogsyncer.go?
(maybe add a option into the BinlogSyncerConfig struct)
from go-mysql.
We can't do it directly, in some cases, MySQL will not send any events but we can't close the connection.
#82 (comment) may work but I have no time to verify it now yet.
from go-mysql.
@siddontang
I mean, use TCP‘s KeepAlive feature (layer 4) to deal with the unplug the network cable situation.
Even if mysql no event to send, tcp will keep the heartbeat between client and server.
So, the connection will not closed until the server crashed or tcp loss the FIN segment.
from go-mysql.
Hi @iyidan
There may be another problem if we close the connection explicitly, see alibaba/canal#139
from go-mysql.
Hi Thanks for the siddon galaxy tools,
The replication protocol as been fully describe here
https://mariadb.com/kb/en/library/replication-protocol/
/Svar
from go-mysql.
Related Issues (20)
- 关于Canal的binlog事件重试疑问 HOT 1
- 什么情况下event.Rows长度会为0 或者为nil? HOT 1
- When will the length of event.Rows be 0 or nil? HOT 4
- invalid sequence 0 != 1 HOT 6
- canal.RowsEvent returns 2 duplicate rows for every update event HOT 2
- Proper way to save position after Canal OnRow event HOT 3
- canal处理Text类型字段时增量日志和存量日志对应的数据结构不同 HOT 1
- add value string output HOT 5
- add a EventCacheSize variable to BinlogSyncerConfig to limit the streamer's memory usage
- How to start binlog syncer from last position HOT 3
- Tables
- Why In OnRow e.Header is nil ,no e.Header.LogPos
- canal can't send create index and drop index sql HOT 2
- MySQL 8.3 will introduce new GTID format
- [Warning] Aborted connection 52412 to db: 'unconnected' user: 'boss' host: '' (Got an error reading communication packets) HOT 7
- how to remove log output HOT 2
- column values missing
- help to understand why do we dump some data first before sync the data from binlog HOT 4
- How to use TRANSACTION_CONTEXT_EVENT for the replication HOT 2
- Driver Compression Enablement HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-mysql.