alibaba patches in mariadb
Post on 12-Apr-2017
Embed Size (px)
Time Machine Demo
Alibaba Patches in MariaDBLixun Peng
TopicTime Machine / Flashback (Developing)Double Sync Replication (Will Contribute)Multi-Source ReplicationThread Memory Monitor
Whats a Time MachineRolling back instances/databases/tables to a snapshot
Implement on Server-Level to support all engines.
By full image format binary logs
Currently, its a feature of mysqlbinlog tool (with--flashback option)
Why Time MachineEveryone may make mistakes, including a DBA.
After users mis-operating their data, of course, we can recovery it from the last full backup set and binary logs.
But if users database is too huge, it will cost so much time! And usually, mis-operation just modify a few data, but we need to recovery whole database.
How Time Machine WorksAs we know, if binlog_format is ROW (binlog-row-image=FULL in 5.6 and later), all columns values are store in the row event, so we can get the data before mis-operation.
Just do following things:Change Event Type, INSERT->DELETE, DELETE->INSERTFor Update_Event, swapping the SET part and WHERE partApplying those events from the last one to the first one which mis-operation happened.All the data will be recovered by inverse operations of mis-oprerations.
Done ListFull DML support
Review table supportBecause users may want to check which part of data is flashbacked.
GTID support (MariaDB)We add GTID event support for MariaDB 10.1MySQL 5.6 GTID events support is still working
ToDo ListAdding DDL supportsFor ADD INDEX/COLUMN, or CREATE TABLE query, just drop the index, column, table when running Flashback.For DROP INDEX/COLUMN, or DROP TABLE query, copy or rename the old table to a reserved database. When Flashback is running, I can drop the new table, and rename the saved old one to the original database.For TRUNCATE table, I just rename the old table to a reserved database and create a new empty table.
Adding a script for time machine.
Double Sync ReplicationEnhancing data security guaranteeLixun Peng @ Alibaba Cloud Compute
Problem of Async ReplicationMaster dont need to wait the ACK from Slave.Slave doesnt know if it dumped the latest binary logs from Master.When crashed, slave can check if itself is the same with Master or not by its own.
SoThe main problem is that Slave doesnt know the status of Master.
Problem of SemiSync
Master needs to wait ACK from Slave.Slave will downgrade to Async when timeout happen.If the timeout is too small, timeout will happen frequently.If the timeout is too big, Master will often be blocked.After network is recovered, Slave should dump the binary logs generated during timeout. During the time, Slave is still Async.When a Master is crashed, Slave doesnt know if the master is Async or SemiSync.So, Slave still doesnt know if its the same with Master or not when Master crashed.
SoSemiSync doesnt solve the main problem of Async Repplication.
Problem of Async/SemiSync
Backgroup & Target
BackgroupSA guarantee the server availability: 99.999%NA guarantee the network availability: 99.999%So, we can assume when the Master is crashed, network will not timeout at that time point.TargetSlave can know its status by itself. (the same with Master or not)If the data isnt the same with Master, notice the app&dev to fix the data, and show the range of lost data.
Key Point To avoid Slave's status being unknown!
Solve the weak point of SemiSyncOnce SemiSync is timeout, even network is recovered, Slave still need to dump the binary logs generated during timeout, under Async.If SemiSync is timeout, we give up the binary logs during timeout, Master just send the latest position & logs. What will happen?When the network is down, the Slave will always know the latest position on Master.So, Slave can know if its data is the same with Master or not.
But, if Slave just dump the latest data, how to get the data during the time when network is down?Async replication can dump the continuous binaray logsSo we can use Async replication to do the full log apply.
Combine the Async and SemiSyncAsync ReplicationAsync_ChannelDumping continuous binary logs to guarantee that the Slaves logs are continuous.Applying for logs after received immediately.
SemiSync ReplicationSync_ChannelDumping the latest binary logs to guarantee that the Slave knows the latest position of Master.Will not apply logs after received, just save the logs & position and outdated logs will be purged automatically.
Analyzing consistencyComparing the received logs positions with these two channels.
Combine the Async and SemiSync
How to create two channels1Multi-Source replication can create N channels in one Slave.
ProblemWhen Master received two dump requests from the same Server-ID servers, it will disconnect the previous one.SolveWe set Sync Channel as a special Server-ID (0xFFFFFF).
How to create two channels 2ProblemThere are a SemiSync and a non-SemiSync Channel in one Slave, but the SemiSync settings are global.SolveWe moved SemiSyncSlave class to Master_info.
Analyzing consistencyUsing the GTIDUsing the Log_file_name and Log_file_pos
How to judge, check the following pictures
CASE 1: Neednt FixGTIDs between Sync and Async Channel are the same.
CASE 2: Cant FixExist broken gap between Sync and Async Channel.
CASE 3: Can RepairCombine two channels logs, its continuous.
How to RepairWe wait for the Async Channel till it applied for all logs that received. Then start the SQL THREAD of Sync Channel.
GTID will filter the event that applied by Async Channel.
We provide the REPAIR SLAVE command to do these things automaticially.
Multi-Source Replication N Masters and 1 SlaveLixun Peng @ Alibaba Cloud Compute
Why we need multi-sourceOLAP
Most of users using MySQL for data sharding.
Multi-Source can help users to combine their data from sharding instances.
If you are using Master-Slave for backup, Multi-Source can help you to backup many instances into one, its easy to maintain.
How Multi-Source implement
What changes in the codeMove Rpl_filter/skip_slave_counters into Master_info.
Every channels will create a new Master_info.
Every replication-related function will use the special Maser_info.
We create a Master_info_index class to maintain all Master_info.
The SyntaxCHANGE MASTER ["connection_name"] ... FLUSH RELAY LOGS ["connection_name"] MASTER_POS_WAIT(....,["connection_name"]) RESET SLAVE ["connection_name"] SHOW RELAYLOG ["connection_name"] EVENTS SHOW SLAVE ["connection_name"] STATUS SHOW ALL SLAVES STATUS START SLAVE ["connection_name"...]START ALL SLAVES ... STOP SLAVE ["connection_name"] ... STOP ALL SLAVES ...
The Syntaxset @@default_master_connection=''; show status like 'Slave_running'; set @@default_master_connection=connection'; show status like 'Slave_running';
How it runs
Thread Memory MonitorKnown how MySQL using memoryLixun Peng @ Alibaba Cloud Compute
Why we need TMMMySQLs memory limitation just work fine on Storage EngineFor example in InnoDB: innodb_buffer_pool_sizeIn the Server we can limit only some features memory, like sort_buffer_size, join_buffer_size.But for big Querythe most of memory cost is from MEM_ROOTno option to limit it.
So when mysqld process used too many memory, we dont know which thread is the reason.Then we dont know which thread to kill to release the memory.
How to solve itAdd a hack in my_malloc.Record the malloc size and which thread applied for this memoryCalculate a total memory size of all threads.