SlideShare a Scribd company logo
1 of 24
Download to read offline
Galera Cluster Best Practices Part 3:
Schema Changes and DDL
Philip Stoev
Codership Oy
Agenda
• A very quick overview of Galera Cluster
• DDL handling in Galera Cluster
• Preparing for a schema upgrade
• Execution strategies for DDL
• Recent Developments and Future Improvements
• Q/A
Galera Cluster Overview
Synchronous
– each transaction is immediately replicated on all nodes at commit
– no stale slaves
Multi-Master
– read from and write to any node
– automatic transaction conflict detection
Replication
– a copy of the entire dataset is available on all nodes
– new nodes can join automatically
For MySQL
– based on a modified version of MySQL (5.5, 5.6, 5.7)
– InnoDB storage engine
And more …
• Recovers from node failures within seconds
• Data consistency protections
– avoids reading stale data
– prevents unsafe data modifications
• Cloud and WAN support
DDL in Galera
• DDL statements are handled differently in Galera
– this is to ensure maximum data consistency in a distributed
environment
– The “online”, “in-place” and “non-blocking” terms from the
MySQL documentation do not apply directly
• DDL execution must be thought out in advance
DDL Execution Methods
• Total Order Isolation (TOI) - the default
– the DDL is run on all nodes at the same time
– the cluster can not commit other transactions while the DDL is
running
• RSU – Rolling Schema Upgrade
– the DDL is run on one node at a time
The Application and DDLs
• Check for DDLs executed by the application/framework:
– some applications run a lot of
CREATE TABLE [IF NOT EXISTS] at connection time
– some run ALTER TABLE when started,
if they feel they need to upgrade the schema
– TEMPORARY tables are OK
• Take control over DDLs:
– Revoke ALTER, INDEX privileges
– A SQL-aware proxy / load balancer can also intercept such
queries
The DDL Statement
• CREATE, DROP [PARTITION]
– usually fast enough, no need for special planning
– unless executed repeatedly by multiple connections
• ALTER TABLE or CREATE INDEX
– some operations have different execution speed depending on
MySQL version
– some statements operate on metadata only, so are fast
– some DDL support ALGORITHM=INPLACE for faster execution
• Will still cause locking in Galera under TOI
– some DDLs require creating a complete copy of the entire table
OPTIMIZE TABLE, etc.
• If a statement can be given the
NO_WRITE_TO_BINLOG modifier, it will not be
replicated by Galera
• Such a statement may fail if concurrent updates against
the same table are going on elsewhere in the cluster.
• If you experience deadlock errors:
– do not perform concurrent updates against the table, or
– make the updates only on the node running the statement
Total Order Isolation (TOI)
Running DDL on all nodes at once
General Principles for TOI
• No other write transactions can commit anywhere on the
cluster while a TOI DDL is in progress
• Even if the DDL is “online”, ”inplace” or allows
concurrent table access in stand-alone MySQL, it is still
fully blocking for writes
• DML transactions operating on same table may get
deadlock error
• wsrep_sync_wait queries may time out
General Principles for TOI (#2)
• DDL statements can not be killed once started
• If a node dies during DDL, it may need to rejoin via SST
• In Galera 3.x, DDL execution errors are ignored
– so check server error log
– a GRA*.log file will also be created for each failure
How Galera runs TOI DDL
1. The DDL statement is sent to all nodes
2. All transactions in the cluster that committed prior to the
DDL are replicated and applied first, new commits are
blocked
3. The DDL is run on all nodes at exactly the same place
in the logical sequence of events
Procedure for TOI
1. Practice the DDL on a test cluster, if possible
2. Ensure enough free disk space is available on all nodes
3. Schedule a maintenance window / put application in read-
only mode
– hangs or deadlock errors will occur for all DML transactions
4. Run the DDL on one node only, it will be replicated to the
rest
5. Examine SHOW PROCESSLIST, SHOW CREATE TABLE
on all nodes to confirm successful execution
6. Check error logs on all nodes for errors
Potential Failure Scenarios
• MySQL returns a SQL error locally
– statement still ran on all nodes even if it failed locally;
– it may have succeeded elsewhere
• Statement fails to complete successfully on other nodes
– disk space issues
– constraint violation due to data inconsistency
ALTER TABLE ADD UNIQUE KEY may expose inconsistencies that
have not been noticed previously
• Statement takes longer than expected
RSU
Rolling Schema Upgrade
Basic Principles for RSU
• Statement is manually run on one node at a time
• Node will temporarily fall behind the cluster for the
duration of the DDL
• Standard MySQL locking rules apply on local node
• Nothing is locked on remote nodes
• Other transactions can continue unaffected
• The binary log on each node will contain events in
different order – important when using async replication
Your Application and RSU
• During a Rolling Schema Upgrade:
– a cluster contains some nodes with old schema
and some nodes with the new one
– the node that is currently running the DDL may temporarily
fall behind
• Remove it from load balancer if data freshness is important
– RSU is a global setting, so application should not attempt to
run other DDLs while you execute the RSU procedure
Coexistence of Two Schemas
• INSERT queries should not attempt to insert into a
column that does not yet exist everywhere.
– INSERT INTO table (old_col1, new_col2) VALUES (123,
‘abc’);
• Column count and position may be different in old and
new schema:
– SELECT * may return differently-shaped result sets
• SELECT old_col1, old_col2 is better
– INSERT INTO table VALUES (123, ‘abc’) may fail or put
data in the wrong column
Preparation
1. Practice the DDL on a test machine, if possible
2. Practice taking nodes out of the load balancer, as this
needs to be done repeatedly
3. Do one DDL at a time, to avoid confusion
– multiple operations can be combined in a single DDL
statement
Step-By-Step Procedure
1. On every node, one at a time:
2. Remove node from load balancer if data freshness is important
3. Run DDL:
SET GLOBAL wsrep_osu_method=RSU;
ALTER TABLE …
SET GLOBAL wsrep_osu_method=TOI;
4. Wait for node to catch up - wsrep_local_recv_queue variable
5. Restore node to load balancer
6. Check for application errors
7. Repeat procedure on the other nodes
Current and Future Improvements
• In recently-released Galera Cluster 5.7:
certain DDL statements are now much faster or instantaneous:
– ALTER TABLE ADD KEY
– ALTER TABLE CHANGE COLUMN for some VARCHAR types
– OPTIMIZE TABLE
• In upcoming Galera Replication Library 4.x:
– a new schema upgrade method, NBO, will allow ALTER
statements to run without blocking the entire cluster
– a new consistency mechanism will check if a DDL succeeded
or failed equally on all nodes
Questions
• Please use the Question/Chat box in the GoToWebinar
panel
• Ideas welcome for future webinars
Thank You
http://www.galeracluster.com
Discussion group:
codership-team@googlegroups.com

More Related Content

What's hot

Best practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability TutorialBest practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability TutorialColin Charles
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Mydbops
 
Galera cluster for high availability
Galera cluster for high availability Galera cluster for high availability
Galera cluster for high availability Mydbops
 
Maxscale 소개 1.1.1
Maxscale 소개 1.1.1Maxscale 소개 1.1.1
Maxscale 소개 1.1.1NeoClova
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLRené Cannaò
 
MariaDB 10.5 binary install (바이너리 설치)
MariaDB 10.5 binary install (바이너리 설치)MariaDB 10.5 binary install (바이너리 설치)
MariaDB 10.5 binary install (바이너리 설치)NeoClova
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsMydbops
 
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)Jean-François Gagné
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performancePostgreSQL-Consulting
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxNeoClova
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQLMydbops
 
How To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesHow To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesSeveralnines
 
How to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleHow to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleMariaDB plc
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialJean-François Gagné
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder
 
MySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptxMySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptxNeoClova
 
[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기NHN FORWARD
 
Understanding Oracle RAC 12c Internals OOW13 [CON8806]
Understanding Oracle RAC 12c Internals OOW13 [CON8806]Understanding Oracle RAC 12c Internals OOW13 [CON8806]
Understanding Oracle RAC 12c Internals OOW13 [CON8806]Markus Michalewicz
 
Deep review of LMS process
Deep review of LMS processDeep review of LMS process
Deep review of LMS processRiyaj Shamsudeen
 

What's hot (20)

Best practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability TutorialBest practices for MySQL High Availability Tutorial
Best practices for MySQL High Availability Tutorial
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
 
Galera cluster for high availability
Galera cluster for high availability Galera cluster for high availability
Galera cluster for high availability
 
Maxscale 소개 1.1.1
Maxscale 소개 1.1.1Maxscale 소개 1.1.1
Maxscale 소개 1.1.1
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQL
 
MariaDB 10.5 binary install (바이너리 설치)
MariaDB 10.5 binary install (바이너리 설치)MariaDB 10.5 binary install (바이너리 설치)
MariaDB 10.5 binary install (바이너리 설치)
 
PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performance
 
MySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptxMySQL8.0_performance_schema.pptx
MySQL8.0_performance_schema.pptx
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQL
 
How To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - SlidesHow To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - Slides
 
How to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScaleHow to Manage Scale-Out Environments with MariaDB MaxScale
How to Manage Scale-Out Environments with MariaDB MaxScale
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
 
Galera Cluster Best Practices for DBA's and DevOps Part 1
Galera Cluster Best Practices for DBA's and DevOps Part 1Galera Cluster Best Practices for DBA's and DevOps Part 1
Galera Cluster Best Practices for DBA's and DevOps Part 1
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
MySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptxMySQL_MariaDB-성능개선-202201.pptx
MySQL_MariaDB-성능개선-202201.pptx
 
[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기[2018] MySQL 이중화 진화기
[2018] MySQL 이중화 진화기
 
Understanding Oracle RAC 12c Internals OOW13 [CON8806]
Understanding Oracle RAC 12c Internals OOW13 [CON8806]Understanding Oracle RAC 12c Internals OOW13 [CON8806]
Understanding Oracle RAC 12c Internals OOW13 [CON8806]
 
Deep review of LMS process
Deep review of LMS processDeep review of LMS process
Deep review of LMS process
 

Viewers also liked

Сильные стороны MySQL для высоконагруженных проектов
Сильные стороны MySQL для высоконагруженных проектовСильные стороны MySQL для высоконагруженных проектов
Сильные стороны MySQL для высоконагруженных проектовCEE-SEC(R)
 
Introduction to Galera
Introduction to GaleraIntroduction to Galera
Introduction to GaleraHenrik Ingo
 
MariaDB Galera Cluster - Simple, Transparent, Highly Available
MariaDB Galera Cluster - Simple, Transparent, Highly AvailableMariaDB Galera Cluster - Simple, Transparent, Highly Available
MariaDB Galera Cluster - Simple, Transparent, Highly AvailableMariaDB Corporation
 
Webinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterWebinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterSeveralnines
 
Maria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityMaria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityOSSCube
 
Best practices for MySQL High Availability
Best practices for MySQL High AvailabilityBest practices for MySQL High Availability
Best practices for MySQL High AvailabilityColin Charles
 
MySQL High Availability Solutions - Feb 2015 webinar
MySQL High Availability Solutions - Feb 2015 webinarMySQL High Availability Solutions - Feb 2015 webinar
MySQL High Availability Solutions - Feb 2015 webinarAndrew Morgan
 
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison Severalnines
 
Galera cluster for MySQL - Introduction Slides
Galera cluster for MySQL - Introduction SlidesGalera cluster for MySQL - Introduction Slides
Galera cluster for MySQL - Introduction SlidesSeveralnines
 
Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesDimas Prasetyo
 
Universitas terbuka at a glance
Universitas terbuka at a glanceUniversitas terbuka at a glance
Universitas terbuka at a glanceDimas Prasetyo
 

Viewers also liked (15)

Taking Full Advantage of Galera Multi Master Cluster
Taking Full Advantage of Galera Multi Master ClusterTaking Full Advantage of Galera Multi Master Cluster
Taking Full Advantage of Galera Multi Master Cluster
 
Using galera replication to create geo distributed clusters on the wan
Using galera replication to create geo distributed clusters on the wanUsing galera replication to create geo distributed clusters on the wan
Using galera replication to create geo distributed clusters on the wan
 
Сильные стороны MySQL для высоконагруженных проектов
Сильные стороны MySQL для высоконагруженных проектовСильные стороны MySQL для высоконагруженных проектов
Сильные стороны MySQL для высоконагруженных проектов
 
Introduction to Galera
Introduction to GaleraIntroduction to Galera
Introduction to Galera
 
MariaDB Galera Cluster - Simple, Transparent, Highly Available
MariaDB Galera Cluster - Simple, Transparent, Highly AvailableMariaDB Galera Cluster - Simple, Transparent, Highly Available
MariaDB Galera Cluster - Simple, Transparent, Highly Available
 
Galera webinar migration to galera cluster from my sql async replication
Galera webinar migration to galera cluster from my sql async replicationGalera webinar migration to galera cluster from my sql async replication
Galera webinar migration to galera cluster from my sql async replication
 
Codership's galera cluster installation and quickstart webinar march 2016
Codership's galera cluster installation and quickstart webinar march 2016Codership's galera cluster installation and quickstart webinar march 2016
Codership's galera cluster installation and quickstart webinar march 2016
 
Webinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera ClusterWebinar Slides: Migrating to Galera Cluster
Webinar Slides: Migrating to Galera Cluster
 
Maria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityMaria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High Availability
 
Best practices for MySQL High Availability
Best practices for MySQL High AvailabilityBest practices for MySQL High Availability
Best practices for MySQL High Availability
 
MySQL High Availability Solutions - Feb 2015 webinar
MySQL High Availability Solutions - Feb 2015 webinarMySQL High Availability Solutions - Feb 2015 webinar
MySQL High Availability Solutions - Feb 2015 webinar
 
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
 
Galera cluster for MySQL - Introduction Slides
Galera cluster for MySQL - Introduction SlidesGalera cluster for MySQL - Introduction Slides
Galera cluster for MySQL - Introduction Slides
 
Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practices
 
Universitas terbuka at a glance
Universitas terbuka at a glanceUniversitas terbuka at a glance
Universitas terbuka at a glance
 

Similar to Galera Cluster DDL and Schema Upgrades 220217

M|18 Battle of the Online Schema Change Methods
M|18 Battle of the Online Schema Change MethodsM|18 Battle of the Online Schema Change Methods
M|18 Battle of the Online Schema Change MethodsMariaDB plc
 
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSINGSKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSINGSkillwise Group
 
Migrating to XtraDB Cluster
Migrating to XtraDB ClusterMigrating to XtraDB Cluster
Migrating to XtraDB Clusterpercona2013
 
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseNoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseParesh Patel
 
Reducing Your E-Business Suite Storage Footprint Using Oracle Advanced Compre...
Reducing Your E-Business Suite Storage Footprint Using Oracle Advanced Compre...Reducing Your E-Business Suite Storage Footprint Using Oracle Advanced Compre...
Reducing Your E-Business Suite Storage Footprint Using Oracle Advanced Compre...Andrejs Karpovs
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-featuresNavneet Upneja
 
IDUG NA 2014 / 11 tips for DB2 11 for z/OS
IDUG NA 2014 / 11 tips for DB2 11 for z/OSIDUG NA 2014 / 11 tips for DB2 11 for z/OS
IDUG NA 2014 / 11 tips for DB2 11 for z/OSCuneyt Goksu
 
SynapseIndia drupal presentation on drupal info
SynapseIndia drupal  presentation on drupal infoSynapseIndia drupal  presentation on drupal info
SynapseIndia drupal presentation on drupal infoSynapseindiappsdevelopment
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAiougVizagChapter
 
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedRoman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedMSDEVMTL
 
My sql performance
My sql performanceMy sql performance
My sql performancenchandra33
 
SQL Server Wait Types Everyone Should Know
SQL Server Wait Types Everyone Should KnowSQL Server Wait Types Everyone Should Know
SQL Server Wait Types Everyone Should KnowDean Richards
 
Building scalable application with sql server
Building scalable application with sql serverBuilding scalable application with sql server
Building scalable application with sql serverChris Adkin
 
Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Antonios Chatzipavlis
 
MySQL High Availability Solutions
MySQL High Availability SolutionsMySQL High Availability Solutions
MySQL High Availability SolutionsLenz Grimmer
 

Similar to Galera Cluster DDL and Schema Upgrades 220217 (20)

Dal deck
Dal deckDal deck
Dal deck
 
M|18 Battle of the Online Schema Change Methods
M|18 Battle of the Online Schema Change MethodsM|18 Battle of the Online Schema Change Methods
M|18 Battle of the Online Schema Change Methods
 
Zero Downtime Schema Changes in Galera Cluster
Zero Downtime Schema Changes in Galera ClusterZero Downtime Schema Changes in Galera Cluster
Zero Downtime Schema Changes in Galera Cluster
 
Rails DB migrate SAFE.pdf
Rails DB migrate SAFE.pdfRails DB migrate SAFE.pdf
Rails DB migrate SAFE.pdf
 
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSINGSKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
SKILLWISE-SSIS DESIGN PATTERN FOR DATA WAREHOUSING
 
01 oracle architecture
01 oracle architecture01 oracle architecture
01 oracle architecture
 
Migrating to XtraDB Cluster
Migrating to XtraDB ClusterMigrating to XtraDB Cluster
Migrating to XtraDB Cluster
 
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseNoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
 
Reducing Your E-Business Suite Storage Footprint Using Oracle Advanced Compre...
Reducing Your E-Business Suite Storage Footprint Using Oracle Advanced Compre...Reducing Your E-Business Suite Storage Footprint Using Oracle Advanced Compre...
Reducing Your E-Business Suite Storage Footprint Using Oracle Advanced Compre...
 
NoSQL Evolution
NoSQL EvolutionNoSQL Evolution
NoSQL Evolution
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-features
 
IDUG NA 2014 / 11 tips for DB2 11 for z/OS
IDUG NA 2014 / 11 tips for DB2 11 for z/OSIDUG NA 2014 / 11 tips for DB2 11 for z/OS
IDUG NA 2014 / 11 tips for DB2 11 for z/OS
 
SynapseIndia drupal presentation on drupal info
SynapseIndia drupal  presentation on drupal infoSynapseIndia drupal  presentation on drupal info
SynapseIndia drupal presentation on drupal info
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedRoman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
 
My sql performance
My sql performanceMy sql performance
My sql performance
 
SQL Server Wait Types Everyone Should Know
SQL Server Wait Types Everyone Should KnowSQL Server Wait Types Everyone Should Know
SQL Server Wait Types Everyone Should Know
 
Building scalable application with sql server
Building scalable application with sql serverBuilding scalable application with sql server
Building scalable application with sql server
 
Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)Concurrency in SQL Server (SQL Night #24)
Concurrency in SQL Server (SQL Night #24)
 
MySQL High Availability Solutions
MySQL High Availability SolutionsMySQL High Availability Solutions
MySQL High Availability Solutions
 

More from Codership Oy - Creators of Galera Cluster (6)

Galera Cluster 4 for MySQL 8 Release Webinar slides
Galera Cluster 4 for MySQL 8 Release Webinar slidesGalera Cluster 4 for MySQL 8 Release Webinar slides
Galera Cluster 4 for MySQL 8 Release Webinar slides
 
Choosing between Codership's MySQL Galera, MariaDB Galera Cluster and Percona...
Choosing between Codership's MySQL Galera, MariaDB Galera Cluster and Percona...Choosing between Codership's MySQL Galera, MariaDB Galera Cluster and Percona...
Choosing between Codership's MySQL Galera, MariaDB Galera Cluster and Percona...
 
Running Galera Cluster on Microsoft Azure
Running Galera Cluster on Microsoft AzureRunning Galera Cluster on Microsoft Azure
Running Galera Cluster on Microsoft Azure
 
How to understand Galera Cluster - 2013
How to understand Galera Cluster - 2013How to understand Galera Cluster - 2013
How to understand Galera Cluster - 2013
 
Galera Cluster 3.0 Features
Galera Cluster 3.0 FeaturesGalera Cluster 3.0 Features
Galera Cluster 3.0 Features
 
Introducing Galera 3.0
Introducing Galera 3.0Introducing Galera 3.0
Introducing Galera 3.0
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 

Galera Cluster DDL and Schema Upgrades 220217

  • 1. Galera Cluster Best Practices Part 3: Schema Changes and DDL Philip Stoev Codership Oy
  • 2. Agenda • A very quick overview of Galera Cluster • DDL handling in Galera Cluster • Preparing for a schema upgrade • Execution strategies for DDL • Recent Developments and Future Improvements • Q/A
  • 3. Galera Cluster Overview Synchronous – each transaction is immediately replicated on all nodes at commit – no stale slaves Multi-Master – read from and write to any node – automatic transaction conflict detection Replication – a copy of the entire dataset is available on all nodes – new nodes can join automatically For MySQL – based on a modified version of MySQL (5.5, 5.6, 5.7) – InnoDB storage engine
  • 4. And more … • Recovers from node failures within seconds • Data consistency protections – avoids reading stale data – prevents unsafe data modifications • Cloud and WAN support
  • 5. DDL in Galera • DDL statements are handled differently in Galera – this is to ensure maximum data consistency in a distributed environment – The “online”, “in-place” and “non-blocking” terms from the MySQL documentation do not apply directly • DDL execution must be thought out in advance
  • 6. DDL Execution Methods • Total Order Isolation (TOI) - the default – the DDL is run on all nodes at the same time – the cluster can not commit other transactions while the DDL is running • RSU – Rolling Schema Upgrade – the DDL is run on one node at a time
  • 7. The Application and DDLs • Check for DDLs executed by the application/framework: – some applications run a lot of CREATE TABLE [IF NOT EXISTS] at connection time – some run ALTER TABLE when started, if they feel they need to upgrade the schema – TEMPORARY tables are OK • Take control over DDLs: – Revoke ALTER, INDEX privileges – A SQL-aware proxy / load balancer can also intercept such queries
  • 8. The DDL Statement • CREATE, DROP [PARTITION] – usually fast enough, no need for special planning – unless executed repeatedly by multiple connections • ALTER TABLE or CREATE INDEX – some operations have different execution speed depending on MySQL version – some statements operate on metadata only, so are fast – some DDL support ALGORITHM=INPLACE for faster execution • Will still cause locking in Galera under TOI – some DDLs require creating a complete copy of the entire table
  • 9. OPTIMIZE TABLE, etc. • If a statement can be given the NO_WRITE_TO_BINLOG modifier, it will not be replicated by Galera • Such a statement may fail if concurrent updates against the same table are going on elsewhere in the cluster. • If you experience deadlock errors: – do not perform concurrent updates against the table, or – make the updates only on the node running the statement
  • 10. Total Order Isolation (TOI) Running DDL on all nodes at once
  • 11. General Principles for TOI • No other write transactions can commit anywhere on the cluster while a TOI DDL is in progress • Even if the DDL is “online”, ”inplace” or allows concurrent table access in stand-alone MySQL, it is still fully blocking for writes • DML transactions operating on same table may get deadlock error • wsrep_sync_wait queries may time out
  • 12. General Principles for TOI (#2) • DDL statements can not be killed once started • If a node dies during DDL, it may need to rejoin via SST • In Galera 3.x, DDL execution errors are ignored – so check server error log – a GRA*.log file will also be created for each failure
  • 13. How Galera runs TOI DDL 1. The DDL statement is sent to all nodes 2. All transactions in the cluster that committed prior to the DDL are replicated and applied first, new commits are blocked 3. The DDL is run on all nodes at exactly the same place in the logical sequence of events
  • 14. Procedure for TOI 1. Practice the DDL on a test cluster, if possible 2. Ensure enough free disk space is available on all nodes 3. Schedule a maintenance window / put application in read- only mode – hangs or deadlock errors will occur for all DML transactions 4. Run the DDL on one node only, it will be replicated to the rest 5. Examine SHOW PROCESSLIST, SHOW CREATE TABLE on all nodes to confirm successful execution 6. Check error logs on all nodes for errors
  • 15. Potential Failure Scenarios • MySQL returns a SQL error locally – statement still ran on all nodes even if it failed locally; – it may have succeeded elsewhere • Statement fails to complete successfully on other nodes – disk space issues – constraint violation due to data inconsistency ALTER TABLE ADD UNIQUE KEY may expose inconsistencies that have not been noticed previously • Statement takes longer than expected
  • 17. Basic Principles for RSU • Statement is manually run on one node at a time • Node will temporarily fall behind the cluster for the duration of the DDL • Standard MySQL locking rules apply on local node • Nothing is locked on remote nodes • Other transactions can continue unaffected • The binary log on each node will contain events in different order – important when using async replication
  • 18. Your Application and RSU • During a Rolling Schema Upgrade: – a cluster contains some nodes with old schema and some nodes with the new one – the node that is currently running the DDL may temporarily fall behind • Remove it from load balancer if data freshness is important – RSU is a global setting, so application should not attempt to run other DDLs while you execute the RSU procedure
  • 19. Coexistence of Two Schemas • INSERT queries should not attempt to insert into a column that does not yet exist everywhere. – INSERT INTO table (old_col1, new_col2) VALUES (123, ‘abc’); • Column count and position may be different in old and new schema: – SELECT * may return differently-shaped result sets • SELECT old_col1, old_col2 is better – INSERT INTO table VALUES (123, ‘abc’) may fail or put data in the wrong column
  • 20. Preparation 1. Practice the DDL on a test machine, if possible 2. Practice taking nodes out of the load balancer, as this needs to be done repeatedly 3. Do one DDL at a time, to avoid confusion – multiple operations can be combined in a single DDL statement
  • 21. Step-By-Step Procedure 1. On every node, one at a time: 2. Remove node from load balancer if data freshness is important 3. Run DDL: SET GLOBAL wsrep_osu_method=RSU; ALTER TABLE … SET GLOBAL wsrep_osu_method=TOI; 4. Wait for node to catch up - wsrep_local_recv_queue variable 5. Restore node to load balancer 6. Check for application errors 7. Repeat procedure on the other nodes
  • 22. Current and Future Improvements • In recently-released Galera Cluster 5.7: certain DDL statements are now much faster or instantaneous: – ALTER TABLE ADD KEY – ALTER TABLE CHANGE COLUMN for some VARCHAR types – OPTIMIZE TABLE • In upcoming Galera Replication Library 4.x: – a new schema upgrade method, NBO, will allow ALTER statements to run without blocking the entire cluster – a new consistency mechanism will check if a DDL succeeded or failed equally on all nodes
  • 23. Questions • Please use the Question/Chat box in the GoToWebinar panel • Ideas welcome for future webinars