From 2c31d7b1361c75a973ef318cd2339c847d190946 Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 11:52:48 +0100 Subject: [PATCH 01/11] Make datadir dynamic depending on ubuntu version --- hooks/percona_hooks.py | 8 +++++++- templates/my.cnf | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hooks/percona_hooks.py b/hooks/percona_hooks.py index 86b2745..fb90a43 100755 --- a/hooks/percona_hooks.py +++ b/hooks/percona_hooks.py @@ -114,6 +114,11 @@ def render_config(clustered=False, hosts=[]): if not os.path.exists(os.path.dirname(MY_CNF)): os.makedirs(os.path.dirname(MY_CNF)) + if lsb_release()['DISTRIB_CODENAME'] < 'vivid': + data_dir = '/var/lib/mysql' + else: + data_dir = '/var/lib/percona' + context = { 'cluster_name': 'juju_cluster', 'private_address': get_host_ip(), @@ -123,7 +128,8 @@ def render_config(clustered=False, hosts=[]): 'sst_password': config('sst-password'), 'innodb_file_per_table': config('innodb-file-per-table'), 'table_open_cache': config('table-open-cache'), - 'lp1366997_workaround': config('lp1366997-workaround') + 'lp1366997_workaround': config('lp1366997-workaround'), + 'data_dir': data_dir, } if config('prefer-ipv6'): diff --git a/templates/my.cnf b/templates/my.cnf index c3b59c5..c3c7afc 100644 --- a/templates/my.cnf +++ b/templates/my.cnf @@ -9,7 +9,7 @@ bind-address = {{ bind_address }} wsrep_provider_options = {{ wsrep_provider_options }} {% endif %} -datadir=/var/lib/mysql +datadir={{ data_dir }} user=mysql pid_file = /var/run/mysqld/mysqld.pid From a8c6634dd2d84521da6411f4ddb26ccad5719afe Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 12:11:09 +0100 Subject: [PATCH 02/11] Update seeded usage as well --- hooks/percona_hooks.py | 8 ++------ hooks/percona_utils.py | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/hooks/percona_hooks.py b/hooks/percona_hooks.py index fb90a43..65402d2 100755 --- a/hooks/percona_hooks.py +++ b/hooks/percona_hooks.py @@ -61,6 +61,7 @@ from percona_utils import ( notify_bootstrapped, is_bootstrapped, get_wsrep_value, + resolve_data_dir, ) from charmhelpers.contrib.database.mysql import ( PerconaClusterHelper, @@ -114,11 +115,6 @@ def render_config(clustered=False, hosts=[]): if not os.path.exists(os.path.dirname(MY_CNF)): os.makedirs(os.path.dirname(MY_CNF)) - if lsb_release()['DISTRIB_CODENAME'] < 'vivid': - data_dir = '/var/lib/mysql' - else: - data_dir = '/var/lib/percona' - context = { 'cluster_name': 'juju_cluster', 'private_address': get_host_ip(), @@ -129,7 +125,7 @@ def render_config(clustered=False, hosts=[]): 'innodb_file_per_table': config('innodb-file-per-table'), 'table_open_cache': config('table-open-cache'), 'lp1366997_workaround': config('lp1366997-workaround'), - 'data_dir': data_dir, + 'data_dir': resolve_data_dir(), } if config('prefer-ipv6'): diff --git a/hooks/percona_utils.py b/hooks/percona_utils.py index 80185f5..d1cd548 100644 --- a/hooks/percona_utils.py +++ b/hooks/percona_utils.py @@ -47,7 +47,7 @@ KEY = "keys/repo.percona.com" REPO = """deb http://repo.percona.com/apt {release} main deb-src http://repo.percona.com/apt {release} main""" MY_CNF = "/etc/mysql/my.cnf" -SEEDED_MARKER = "/var/lib/mysql/seeded" +SEEDED_MARKER = "{data_dir}/seeded" HOSTS_FILE = '/etc/hosts' @@ -69,12 +69,13 @@ def determine_packages(): def seeded(): ''' Check whether service unit is already seeded ''' - return os.path.exists(SEEDED_MARKER) + return os.path.exists(SEEDED_MARKER.format(data_dir=resolve_data_dir())) def mark_seeded(): ''' Mark service unit as seeded ''' - with open(SEEDED_MARKER, 'w') as seeded: + with open(SEEDED_MARKER.format(data_dir=resolve_data_dir()), + 'w') as seeded: seeded.write('done') @@ -360,3 +361,12 @@ def notify_bootstrapped(cluster_rid=None, cluster_uuid=None): (cluster_uuid), DEBUG) for rid in rids: relation_set(relation_id=rid, **{'bootstrap-uuid': cluster_uuid}) + + +def resolve_data_dir(): + if lsb_release()['DISTRIB_CODENAME'] < 'vivid': + return '/var/lib/mysql' + else: + return '/var/lib/percona' + + From bd9cdb1767cf259961f1706b70f72eae425a8686 Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 12:12:43 +0100 Subject: [PATCH 03/11] Fixup actual name --- hooks/percona_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/percona_utils.py b/hooks/percona_utils.py index d1cd548..5b230c1 100644 --- a/hooks/percona_utils.py +++ b/hooks/percona_utils.py @@ -367,6 +367,6 @@ def resolve_data_dir(): if lsb_release()['DISTRIB_CODENAME'] < 'vivid': return '/var/lib/mysql' else: - return '/var/lib/percona' + return '/var/lib/percona-xtradb-cluster' From ae5ee98c985022ace918086e24a074508b9475c0 Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 12:23:18 +0100 Subject: [PATCH 04/11] Enable networking by default --- templates/my.cnf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/my.cnf b/templates/my.cnf index c3c7afc..34cc255 100644 --- a/templates/my.cnf +++ b/templates/my.cnf @@ -3,6 +3,8 @@ {% if bind_address %} bind-address = {{ bind_address }} +{% else %} +bind-address = * {% endif %} {% if wsrep_provider_options %} From 990887d2e898e6b0a1a8dd70fc0d9057a130585f Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 12:26:08 +0100 Subject: [PATCH 05/11] Switch to 0.0.0.0 --- templates/my.cnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/my.cnf b/templates/my.cnf index 34cc255..1a0c1b6 100644 --- a/templates/my.cnf +++ b/templates/my.cnf @@ -4,7 +4,7 @@ {% if bind_address %} bind-address = {{ bind_address }} {% else %} -bind-address = * +bind-address = 0.0.0.0 {% endif %} {% if wsrep_provider_options %} From 1c3645663f7e90c40c5458b953445cc7a4a63503 Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 12:58:07 +0100 Subject: [PATCH 06/11] Rework for >= vivid --- hooks/percona_hooks.py | 15 +++-- hooks/percona_utils.py | 13 ++++- templates/mysqld.cnf | 126 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 11 deletions(-) create mode 100644 templates/mysqld.cnf diff --git a/hooks/percona_hooks.py b/hooks/percona_hooks.py index 65402d2..7779ba8 100755 --- a/hooks/percona_hooks.py +++ b/hooks/percona_hooks.py @@ -45,7 +45,6 @@ from charmhelpers.contrib.peerstorage import ( ) from percona_utils import ( determine_packages, - MY_CNF, setup_percona_repo, get_host_ip, get_cluster_hosts, @@ -61,7 +60,7 @@ from percona_utils import ( notify_bootstrapped, is_bootstrapped, get_wsrep_value, - resolve_data_dir, + resolve_cnf_file, ) from charmhelpers.contrib.database.mysql import ( PerconaClusterHelper, @@ -112,8 +111,8 @@ def install(): def render_config(clustered=False, hosts=[]): - if not os.path.exists(os.path.dirname(MY_CNF)): - os.makedirs(os.path.dirname(MY_CNF)) + if not os.path.exists(os.path.dirname(resolve_cnf_file())): + os.makedirs(os.path.dirname(resolve_cnf_file())) context = { 'cluster_name': 'juju_cluster', @@ -125,7 +124,6 @@ def render_config(clustered=False, hosts=[]): 'innodb_file_per_table': config('innodb-file-per-table'), 'table_open_cache': config('table-open-cache'), 'lp1366997_workaround': config('lp1366997-workaround'), - 'data_dir': resolve_data_dir(), } if config('prefer-ipv6'): @@ -139,7 +137,8 @@ def render_config(clustered=False, hosts=[]): context['ipv6'] = False context.update(PerconaClusterHelper().parse_config()) - render(os.path.basename(MY_CNF), MY_CNF, context, perms=0o444) + render(os.path.basename(resolve_cnf_file()), + resolve_cnf_file(), context, perms=0o444) def render_config_restart_on_changed(clustered, hosts, bootstrap=False): @@ -154,10 +153,10 @@ def render_config_restart_on_changed(clustered, hosts, bootstrap=False): it is started so long as the new node to be added is guaranteed to have been restarted so as to apply the new config. """ - pre_hash = file_hash(MY_CNF) + pre_hash = file_hash(resolve_cnf_file()) render_config(clustered, hosts) update_db_rels = False - if file_hash(MY_CNF) != pre_hash or bootstrap: + if file_hash(resolve_cnf_file()) != pre_hash or bootstrap: if bootstrap: service('bootstrap-pxc', 'mysql') # NOTE(dosaboy): this will not actually do anything if no cluster diff --git a/hooks/percona_utils.py b/hooks/percona_utils.py index 5b230c1..2f48f4d 100644 --- a/hooks/percona_utils.py +++ b/hooks/percona_utils.py @@ -25,6 +25,7 @@ from charmhelpers.core.hookenv import ( INFO, WARNING, ERROR, + cached, ) from charmhelpers.fetch import ( apt_install, @@ -46,7 +47,6 @@ from MySQLdb import ( KEY = "keys/repo.percona.com" REPO = """deb http://repo.percona.com/apt {release} main deb-src http://repo.percona.com/apt {release} main""" -MY_CNF = "/etc/mysql/my.cnf" SEEDED_MARKER = "{data_dir}/seeded" HOSTS_FILE = '/etc/hosts' @@ -363,10 +363,17 @@ def notify_bootstrapped(cluster_rid=None, cluster_uuid=None): relation_set(relation_id=rid, **{'bootstrap-uuid': cluster_uuid}) +@cached def resolve_data_dir(): if lsb_release()['DISTRIB_CODENAME'] < 'vivid': - return '/var/lib/mysql' + '/var/lib/mysql' else: - return '/var/lib/percona-xtradb-cluster' + '/var/lib/percona-xtradb-cluster' +@cached +def resolve_cnf_file(): + if lsb_release()['DISTRIB_CODENAME'] < 'vivid': + '/etc/mysql/my.cnf' + else: + '/etc/mysql/percona-xtradb-cluster.conf.d/mysqld.cnf' diff --git a/templates/mysqld.cnf b/templates/mysqld.cnf new file mode 100644 index 0000000..fcc98f7 --- /dev/null +++ b/templates/mysqld.cnf @@ -0,0 +1,126 @@ +[mysqld] +# +# * Basic Settings +# +user = mysql +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock +port = 3306 +basedir = /usr +datadir = /var/lib/percona-xtradb-cluster +tmpdir = /tmp +lc-messages-dir = /usr/share/mysql +skip-external-locking + +# +# * Networking +# +{% if bind_address -%} +bind-address = {{ bind_address }} +{% else -%} +bind-address = 0.0.0.0 +{% endif %} + +# +# * Fine Tuning +# +key_buffer = {{ key_buffer }} +table_open_cache = {{ table_open_cache }} +max_allowed_packet = 16M +thread_stack = 192K +thread_cache_size = 8 + +# This replaces the startup script and checks MyISAM tables if needed +# the first time they are touched +myisam-recover = BACKUP + +{% if max_connections != -1 -%} +max_connections = {{ max_connections }} +{% endif %} + +{% if wait_timeout != -1 -%} +# Seconds before clearing idle connections +wait_timeout = {{ wait_timeout }} +{% endif %} + +# +# * Query Cache Configuration +# +query_cache_limit = 1M +query_cache_size = 16M + +# +# * Logging and Replication +# +# +# Error log - should be very few entries. +# +log_error = /var/log/mysql/error.log +# +# The following can be used as easy to replay backup logs or for replication. +# note: if you are setting up a replication slave, see README.Debian about +# other settings you may need to change. +expire_logs_days = 10 +max_binlog_size = 100M + +# +# * InnoDB +# +{% if innodb_file_per_table -%} +# This enables storing InnoDB tables in separate .ibd files. Note that, however +# existing InnoDB tables will remain in ibdata file(s) unles OPTIMIZE is run +# on them. Still, the ibdata1 file will NOT shrink - a full dump/import of the +# data is needed in order to get rid of large ibdata file. +innodb_file_per_table = 1 +{% else -%} +innodb_file_per_table = 0 +{% endif %} + +# InnoDB buffer should consume 100% of the bytes of the dataset size +# query cache is not supported with Active/Active configuration +innodb_buffer_pool_size = {{ innodb_buffer_pool_size }} + +# +# * Galera +# +# Add address of other cluster nodes here +{% if not clustered -%} +# Empty gcomm address is being used when cluster is getting bootstrapped +wsrep_cluster_address=gcomm:// +{% else -%} +# Cluster connection URL contains the IPs of node#1, node#2 and node#3 +wsrep_cluster_address=gcomm://{{ cluster_hosts }} +{% endif %} + +# +# Node address +wsrep_node_address={{ private_address }} +# +# SST method +wsrep_sst_method={{ sst_method }} +# +# Cluster name +wsrep_cluster_name={{ cluster_name }} +# +# Authentication for SST method +wsrep_sst_auth="sstuser:{{ sst_password }}" + +{% if wsrep_provider_options -%} +wsrep_provider_options = {{ wsrep_provider_options }} +{% endif %} + +{% if lp1366997_workaround -%} +# Adding workaround for bug: +# https://bugs.launchpad.net/charms/+source/percona-cluster/+bug/1366997 +# Note that this should only be required for percona 5.5 +wsrep_drupal_282555_workaround = ON +wsrep_retry_autocommit = 100 +{% endif %} + +# +# * IPv6 SST configuration +# +{% if ipv6 -%} +[sst] +sockopt=,pf=ip6 +{% endif %} From 8f662a504093319dcc44c982e49afc4757ff4e10 Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 13:05:10 +0100 Subject: [PATCH 07/11] Actually return stuff --- hooks/percona_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hooks/percona_utils.py b/hooks/percona_utils.py index 2f48f4d..ef3fdc5 100644 --- a/hooks/percona_utils.py +++ b/hooks/percona_utils.py @@ -366,14 +366,14 @@ def notify_bootstrapped(cluster_rid=None, cluster_uuid=None): @cached def resolve_data_dir(): if lsb_release()['DISTRIB_CODENAME'] < 'vivid': - '/var/lib/mysql' + return '/var/lib/mysql' else: - '/var/lib/percona-xtradb-cluster' + return '/var/lib/percona-xtradb-cluster' @cached def resolve_cnf_file(): if lsb_release()['DISTRIB_CODENAME'] < 'vivid': - '/etc/mysql/my.cnf' + return '/etc/mysql/my.cnf' else: - '/etc/mysql/percona-xtradb-cluster.conf.d/mysqld.cnf' + return '/etc/mysql/percona-xtradb-cluster.conf.d/mysqld.cnf' From 3c1092d615db3840b3178cd5f957a6ada8cc49c9 Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 13:24:32 +0100 Subject: [PATCH 08/11] Fixup layout --- templates/mysqld.cnf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/mysqld.cnf b/templates/mysqld.cnf index fcc98f7..ca898a8 100644 --- a/templates/mysqld.cnf +++ b/templates/mysqld.cnf @@ -25,7 +25,7 @@ bind-address = 0.0.0.0 # * Fine Tuning # key_buffer = {{ key_buffer }} -table_open_cache = {{ table_open_cache }} +table_open_cache = {{ table_open_cache }} max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 From d58ab06f163e8d87863ef43ef5bfc1178aaa04ec Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 13:31:13 +0100 Subject: [PATCH 09/11] Drop errant comment --- templates/mysqld.cnf | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/mysqld.cnf b/templates/mysqld.cnf index ca898a8..87978f3 100644 --- a/templates/mysqld.cnf +++ b/templates/mysqld.cnf @@ -76,8 +76,6 @@ innodb_file_per_table = 1 innodb_file_per_table = 0 {% endif %} -# InnoDB buffer should consume 100% of the bytes of the dataset size -# query cache is not supported with Active/Active configuration innodb_buffer_pool_size = {{ innodb_buffer_pool_size }} # From 5647e76cbbc69f6be2192d8bc040f52ecbe0619b Mon Sep 17 00:00:00 2001 From: James Page Date: Fri, 18 Sep 2015 15:00:57 +0100 Subject: [PATCH 10/11] Revert changes to older config template --- templates/my.cnf | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/templates/my.cnf b/templates/my.cnf index 1a0c1b6..c3b59c5 100644 --- a/templates/my.cnf +++ b/templates/my.cnf @@ -3,15 +3,13 @@ {% if bind_address %} bind-address = {{ bind_address }} -{% else %} -bind-address = 0.0.0.0 {% endif %} {% if wsrep_provider_options %} wsrep_provider_options = {{ wsrep_provider_options }} {% endif %} -datadir={{ data_dir }} +datadir=/var/lib/mysql user=mysql pid_file = /var/run/mysqld/mysqld.pid From f42fb3d04dd06e040bec6037a16bc6e364671e45 Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 29 Sep 2015 12:03:48 +0100 Subject: [PATCH 11/11] Drop workaround for pxc 5.6 - not required --- templates/mysqld.cnf | 8 -------- 1 file changed, 8 deletions(-) diff --git a/templates/mysqld.cnf b/templates/mysqld.cnf index 87978f3..e56aa51 100644 --- a/templates/mysqld.cnf +++ b/templates/mysqld.cnf @@ -107,14 +107,6 @@ wsrep_sst_auth="sstuser:{{ sst_password }}" wsrep_provider_options = {{ wsrep_provider_options }} {% endif %} -{% if lp1366997_workaround -%} -# Adding workaround for bug: -# https://bugs.launchpad.net/charms/+source/percona-cluster/+bug/1366997 -# Note that this should only be required for percona 5.5 -wsrep_drupal_282555_workaround = ON -wsrep_retry_autocommit = 100 -{% endif %} - # # * IPv6 SST configuration #