I have dealt with this pesky 0 to infinity and back to 0 issue with Seconds_Behind_Master
. Here are my past posts where I have addressed this:
Although there is a bug fix in place based on binlogs not being flushed properly and if you configure sync_binlog=1
on Master1 and Master2, it may exacerbate the problem.
Even in a perfect world for Binary Logs, sometimes there will be occasions when queries will bunch up on one Master and have the same timestamp. When those queries are completed in parallel on a Master, every Slave processes them in a serialized manner.
EXAMPLE
If 60 queries take one second to run on a Master and all of them complete at the same time...
- all 60 queries will be written to the Master's Binary Logs on-by-one
- all 60 queries will have the same timestamp
- each of the 60 one-second queries are executed one-by-one of the Slave
- The timestamp of each query won't move while NOW() on the Slave is moving (The difference between NOW() on the Slave and the timestamp of the query from the Master is
Seconds_Behind_Master
)
- When the first 59 queries are processed, Seconds_Behind_Master will be 59
- When the 60th query is processed, Seconds_Behind_Master drops to 0
Given this computation of Second_Behind_Master
and Master1 records multiple queries in the same timeframe, Master2 will always experience this time warp.
SUGGESTION
You could try zapping all the relay logs on the Master2.
- On Master1,
STOP SLAVE;
- On Master2,
SHOW SLAVE STATUS\G
- On Master2, get LOGFIL from
Relay_Master_Log_File
- On Master2, get LOGPOS from
Exec_Master_Log_Pos
- On Master2,
CHANGE MASTER TO master_log_file='LOGFIL',master_log_pos=LOGPOS;
- On Master2,
START SLAVE;
- On Master1,
STOP SLAVE;
Once you run these steps, you have a clean set of relay logs on Master2, but you still subject to Slave Lag emanating from Master1 due to multiple queries completing at the same time.
All the numbers I mentioned in the Example assumes that Master1 and Master2 have identical Storage Engine configs, identical OS, identical hardware, identical disks, and excellent network communication. If Master2 is inferior to Master1 in any of these aspects, perhaps the 60 seconds to process the queries on the Slave will be more like 70 or 80 seconds.
If the hardware, software, and Storage Engine configs are not identical, then make them identical and restart MySQL as needed.
These are the facts. There is no "Magic Bullet" for this phenomenon so long as your hammer multiple INSERT, UPDATEs, and DELETEs on Master1.
LOOKING OUTSIDE THE BOX
- What you need to look for in the Master1's Binary Logs is 15-second Windows of Time among the timestamps and see how many INSERT, UPDATEs, and DELETEs and being done.
- If your application performs these writes with the same rhythmic pattern, then you need to look at the application as to how it does writes in InnoDB and MyISAM.
- Look around for any cronjobs that perform any scheduled writes
SELECT NOW();
give you the same answer on all servers? This usually means your clocks disagree.FLUSH LOGS;
trigger this behavior?