Managing MySQL at Scale Pradeep Nayak & Junyi (Luke) Lu - - PowerPoint PPT Presentation

managing mysql at scale
SMART_READER_LITE
LIVE PREVIEW

Managing MySQL at Scale Pradeep Nayak & Junyi (Luke) Lu - - PowerPoint PPT Presentation

Managing MySQL at Scale Pradeep Nayak & Junyi (Luke) Lu Production Engineers - MySQL Infra Agenda 1 Terminology 2 Lifecycle of a MySQL instance 3 How do we migrate MySQL instance 4 How do we migrate shard 5 Balancing 6 Testing


slide-1
SLIDE 1
slide-2
SLIDE 2

Managing MySQL at Scale

Pradeep Nayak & Junyi (Luke) Lu

Production Engineers - MySQL Infra

slide-3
SLIDE 3

Agenda

1 Terminology 2 Lifecycle of a MySQL instance 3 How do we migrate MySQL instance 4 How do we migrate shard 5 Balancing 6 Testing Infrastructure for automations

slide-4
SLIDE 4

Terminology

slide-5
SLIDE 5

What’s a instance ? What’s a shard ? What’s a replicaset ?

Terminology

slide-6
SLIDE 6

foobar.prn:3307 foobar.prn:3309 foobar.prn:3306

Instance

3306 3307 3309

foobar.prn

slide-7
SLIDE 7

db.helloworld db.12345 db.44365

Shard

slide-8
SLIDE 8

Replicaset

WWW Service Discovery

Replicaset 1 (0-99) Replicaset 2 (100-199) Replicaset 3 (200-299) M1 S1 M2 S2 M3 S3

slide-9
SLIDE 9

Shard ID Replicaset Master Slave

0-99 Replicaset 1 db1234.prn1:3306 db1234.frc1:3306 100-199 Replicaset 2 db4567.ftw1:3306 200-299 Replicaset 3 db4567.prn1:3307 db1234.atn1:3306 db1234.frc2:3308

Service Discovery

slide-10
SLIDE 10

Shard ID Replicaset Master Slave

0-99 Replicaset 1 db1234.prn1:3306 db1234.frc1:3306 100-199 Replicaset 2 db4567.ftw1:3306 200-299 Replicaset 3 db1234.frc2:3308 db1234.prn1:3309 db1234.atn1:3309

Service Discovery

slide-11
SLIDE 11

db.helloworld

mysql.replicaset.12345 host123.prn host245.ftw host567.frc 3309 3306 3306 3307 3306 3309

db.foobar

shard replicaset instance host mysql.replicaset.6789

slide-12
SLIDE 12

Lifecycle of an instance

slide-13
SLIDE 13
  • States are production, spare, spare allocated, spare

deallocated, reimage, drained

  • Metadata includes instance properties like name,

port, mysql rpm version, state etc

  • A mysql shard hosts metadata of all instances in the

fleet

Lifecycle of an instance

slide-14
SLIDE 14

Lifecycle of an instance

reimage production drained spare allocated spare deallocated spare pre-prod checks success prod checks fail undrain copy success copy success copy failed p r e

  • p

r

  • d

c h e c k s s u c c e s s allocated for copy copy success

slide-15
SLIDE 15
  • Each state has its own processor to do the work
  • Each state has a queue where work is queued
  • Runs constantly scanning the fleet

Lifecycle of an instance

slide-16
SLIDE 16

Instance Migration

slide-17
SLIDE 17

Use case of cloning a production MySQL instance

  • Replace a broken instance/host
  • Move data around for maintenance
  • Balancing host utilization

Clone an instance

slide-18
SLIDE 18

A workflow system that manages the requests for cloning MySQL instances

  • spare allocation
  • set up MySQL config
  • copy data
  • replication
  • validation
  • bring it online & remove the old instance if necessary

MPS Copy

slide-19
SLIDE 19

Choose the best slot for the instance based on its footprint

  • Disk usage
  • CPU utilization
  • Failure domain

MPS Copy - Allocation

Allocation Setup Migration Replication Validation Registeration

slide-20
SLIDE 20

Turn up an empty instance using the right configuration

  • Install the right RPM version
  • Bootstrap the correct directory
  • Generate the right my.cnf based on its use case
  • Make sure the empty instance is connectable

MPS Copy - Setup

Allocation Setup Migration Replication Validation Registeration

slide-21
SLIDE 21

We support three different ways of cloning a production instance

  • Physical copy: xtrabackup and myrocks_hotbackup
  • Logical copy:

○ mysqldump ○ Restore from backup

MPS Copy - Data Migration

Allocation Setup Migration Replication Validation Registeration

slide-22
SLIDE 22
  • Setup replication

○ From current production master ○ From Binlog Server

  • Catchup

MPS Copy - Replication

Allocation Setup Migration Replication Validation Registeration

slide-23
SLIDE 23

If the data migration is a logical one, we will use snapshot based checksum to verify the correctness of data by comparing to its current master

MPS Copy - Validation

Allocation Setup Migration Replication Validation Registeration

slide-24
SLIDE 24

Register the new instance in our service discovery system so that the MySQL users will be able to notice this new instance that has been recently turned up

MPS Copy - Service Registration

Allocation Setup Migration Replication Validation Registeration

slide-25
SLIDE 25

Online Shard Migration

slide-26
SLIDE 26

Another fundamental piece of our infra to control the growth of each MySQL instance

  • Instance can grow beyond the host level limit
  • Too big
  • Too hot

Online Shard Migration

slide-27
SLIDE 27

Key concept: Move the data of a shard into other smaller/cooler instance through logical migration and register the new address into the service discovery system

Online Shard Migration (OLM)

slide-28
SLIDE 28

db.1

mysql.replicaset.1234 host123.prn host245.ftw 3306 3306 shard replicaset instance host mysql.replicaset.5678 host345.prn host567.ftw 3307 3307

OLM

db.2 db.3

slide-29
SLIDE 29

OLM

db.2 = 300G db.1 = 100G db.3 = 50G

mysql.replicaset.1

100G table1.csv table2.csv db.1 table3.csv

mysql.replicaset.2

Shard Replicaset db.1 mysql.replicaset.1 db.2 mysql.replicaset.1 db.3 mysql.replicaset.3 mysql.replicaset.2

binlogs

slide-30
SLIDE 30

Workflow management for massive OLM operations

  • Conflict solver
  • Picking the best destination replicaset
  • Kickoff the actual move
  • Proper retry and cleanup

OLM Processor

slide-31
SLIDE 31

Balancing

slide-32
SLIDE 32

Balancing

Find the right place for the workload in order to achieve maximum sustainable resource utilization

slide-33
SLIDE 33

Poor Stacking

RS1: 400G RS2: 300G RS4: 200G RS3: 100G Host: 500G

Total: 1000G

Host: 500G Host: 500G Host: 500G

slide-34
SLIDE 34

Poor Stacking

Host 1 Free: 500G Host 2 Free: 500G RS1: 400G Host 3 Free: 500G RS1: 400G Free: 100G

slide-35
SLIDE 35

Poor Stacking

Host 1 Free: 500G Host 2 Free: 500G RS2: 300G Host 3 Free: 500G RS1: 400G Free: 100G RS2: 300G Free: 200G

slide-36
SLIDE 36

Poor Stacking

Host 1 Free: 500G Host 2 Free: 500G Host 3 Free: 500G RS1: 400G Free: 100G RS2: 300G Free: 200G Free: 100G RS3: 100G RS3: 100G

slide-37
SLIDE 37

Poor Stacking

Host 1 Free: 500G Host 2 Free: 500G Host 3 Free: 500G RS1: 400G Free: 100G RS2: 300G Free: 200G Free: 100G RS4: 200G RS3: 100G RS4: 200G Free: 300G

slide-38
SLIDE 38

Proper Stacking

Host 1 Free: 500G Host 2 Free: 500G Host 3 Free: 500G RS1: 400G Free: 100G RS2: 300G Free: 200G RS3: 100G RS3: 100G

slide-39
SLIDE 39

Proper Stacking

Host 1 Free: 500G Host 2 Free: 500G Host 3 Free: 500G RS1: 400G Free: 100G RS2: 300G Free: 200G RS4: 200G RS3: 100G RS4: 200G

slide-40
SLIDE 40

Carve the Shape

RS1: 400G RS2: 200G RS3: 200G RS4: 200G

Total: 1000G

Host: 500G Host: 500G Host: 500G Host: 500G

slide-41
SLIDE 41

Host 3 Free: 500G

Poor Shape

Free: 100G RS1: 400G Free: 300G RS2: 200G Free: 300G RS4: 200G RS3: 200G Free: 100G

X3

slide-42
SLIDE 42

RS1: 400G RS4: 200G RS3: 200G RS2: 200G

Carve the Shape

Total: 1000G

100G 100G 100G 100G 100G 100G 100G 100G 100G 100G 100G RS1: 400G RS2: 300G RS3: 200G RS4: 100G Host: 500G Host: 500G Host: 500G Host: 500G

slide-43
SLIDE 43

Rebalancer

Goal: Find the best slot for hosting the given workload profile and reduce the imbalance score across the fleet to be minimum

Maintenance Replace Broken Host Rebalancer Moves

slide-44
SLIDE 44

Rebalancer - Challenges

Multiple balancing factors

  • CPU/Memory/Disk usage
  • Fault domain spreading
  • MySQL vs LBU anti affinity
slide-45
SLIDE 45

Testing Infrastructure

slide-46
SLIDE 46

Testing Infra for Automations

  • Lots of Automation code handling critical

components of Infra

  • UnitTests are good but mock backend connection
  • Need to test end to end
slide-47
SLIDE 47

Testing Infra Goals

  • build and canary packages based on the change
  • provide signals at diff time for developer
  • production like setup, but isolated environment
  • iterate quickly with confidence
slide-48
SLIDE 48

Run the test code

Diff

Testing Infra Service

metadata

prod snapshot deallocate & refresh

allocate/deallocate trigger test test signal metadata access Virtual test assets deallocate

developer

slide-49
SLIDE 49

Q&A

slide-50
SLIDE 50