Jcrespo has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/363195 )

Change subject: mariadb: Support multiple instances directly on the module
......................................................................


mariadb: Support multiple instances directly on the module

Also use it on a new role dbstore_multiinstance as a test.

The idea is to have a common mariadb::config, and then one
resouce mariadb::instance usage for each mysql run, with its own
datadir, tmpdir, port and socket. The custom config should include
the extra config files on /etc/mysql/mysqld.config.d and either
init.d or systemd (with mariadb@.service) should be able to
handle the different configs.

Many questions are still left about the details, such as monitoring
- this is just a first test approximation.

Bug: T169514
Change-Id: Ib313d12e6784700e0afaccd443acb181b7a0e1d4
---
A modules/mariadb/manifests/instance.pp
M modules/mariadb/manifests/service.pp
A modules/mariadb/templates/instance.cnf.erb
A modules/role/manifests/mariadb/dbstore_multiinstance.pp
A modules/role/templates/mariadb/mysqld_config/dbstore3.my.cnf
5 files changed, 223 insertions(+), 1 deletion(-)

Approvals:
  jenkins-bot: Verified
  Jcrespo: Looks good to me, approved



diff --git a/modules/mariadb/manifests/instance.pp 
b/modules/mariadb/manifests/instance.pp
new file mode 100644
index 0000000..8a8362d
--- /dev/null
+++ b/modules/mariadb/manifests/instance.pp
@@ -0,0 +1,39 @@
+# Setups additional instances for hosts that hosts more
+# than one instance
+define mariadb::instance(
+    $port,
+    $datadir = 'undefined',
+    $tmpdir  = 'undefined',
+    $socket  = 'undefined',
+) {
+    if $datadir == 'undefined' {
+        $datadir = "/srv/sqldata.${title}"
+    }
+    if $tmpdir == 'undefined' {
+        $tmpdir  = "/srv/tmp.${title}"
+    }
+    if $tmpdir == 'undefined' {
+        $socket  = "/run/mysqld/mysqld.${title}.sock"
+    }
+
+    file { $datadir:
+        ensure => directory,
+        owner  => 'mysql',
+        group  => 'mysql',
+        mode   => '0755',
+    }
+
+    file { $tmpdir:
+        ensure => directory,
+        owner  => 'mysql',
+        group  => 'mysql',
+        mode   => '0755',
+    }
+
+    file { "/etc/mysql/mysqld.conf.d/${title}.cnf":
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0644',
+        content => template('mariadb/instance.cnf.erb'),
+    }
+}
diff --git a/modules/mariadb/manifests/service.pp 
b/modules/mariadb/manifests/service.pp
index fc2f4af..6247a22 100644
--- a/modules/mariadb/manifests/service.pp
+++ b/modules/mariadb/manifests/service.pp
@@ -14,7 +14,7 @@
 # With $manage = true this class will set $ensure and $enabled as specified.
 
 class mariadb::service (
-    $package  = 'wmf-mariadb10',
+    $package  = 'undefined',
     $basedir  = 'undefined',
     $manage   = false,
     $ensure   = stopped,
@@ -30,6 +30,10 @@
 
     # stretch and later use systemd, others use init.d
     if os_version('debian >= stretch') {
+        # On stretch+, default to MariaDB 10.1
+        if $package == 'undefined' {
+            $package = 'wmf-mariadb101'
+        }
         case $package {
             'wmf-mysql57', 'wmf-mysql80': { $vendor = 'mysql' }
             default:                      { $vendor = 'mariadb' }
@@ -74,6 +78,11 @@
             }
         }
     } else {
+        # Before stretch, default to MariaDB 10.0
+        if $package == 'undefined' {
+            $package = 'wmf-mariadb10'
+        }
+
         file { "${initd_basedir}/service":
             ensure  => present,
             owner   => 'root',
diff --git a/modules/mariadb/templates/instance.cnf.erb 
b/modules/mariadb/templates/instance.cnf.erb
new file mode 100644
index 0000000..9aefd5f
--- /dev/null
+++ b/modules/mariadb/templates/instance.cnf.erb
@@ -0,0 +1,4 @@
+[mysqld@<%= @title %>]
+datadir=<%= @datadir %>
+socket=<%= @socket %>
+port=<%= @port %>
diff --git a/modules/role/manifests/mariadb/dbstore_multiinstance.pp 
b/modules/role/manifests/mariadb/dbstore_multiinstance.pp
new file mode 100644
index 0000000..802b32c
--- /dev/null
+++ b/modules/role/manifests/mariadb/dbstore_multiinstance.pp
@@ -0,0 +1,56 @@
+class role::mariadb::dbstore_multiinstance {
+    system::role { 'mariadb::core':
+        description => 'DBStore multi-instance server',
+    }
+
+    include ::standard
+    include ::base::firewall
+    include role::mariadb::monitor
+    #TODO: Custom firewall rules
+
+    #TODO: define one group per shard
+    class {'mariadb::groups':
+        mysql_group => 'dbstore',
+        mysql_shard => 's1',
+        mysql_role  => 'slave',
+        socket      => '/run/mysqld/mysqld.s1.sock',
+    }
+
+    class {'mariadb::packages_wmf': }
+    class {'mariadb::service':
+        multiinstance => true,
+        # for now we will keep things simple, we probably should have a
+        # higher-level interface with templates
+        override      => "[Service]\nLimitNOFILE=200000",
+    }
+
+    # Read only forced on also for the masters of the primary datacenter
+    class { 'mariadb::config':
+        config        => 'role/mariadb/mysqld_config/dbstore3.my.cnf.erb',
+        p_s           => 'on',
+        ssl           => 'puppet-cert',
+        binlog_format => 'ROW',
+    }
+
+    mariadb::instance {'s1':
+        port => 3311,
+    }
+    mariadb::instance {'s2':
+        port => 3312,
+    }
+    mariadb::instance {'s3':
+        port => 3313,
+    }
+    mariadb::instance {'s4':
+        port => 3314,
+    }
+    mariadb::instance {'s5':
+        port => 3315,
+    }
+    mariadb::instance {'s6':
+        port => 3316,
+    }
+    mariadb::instance {'s7':
+        port => 3317,
+    }
+}
diff --git a/modules/role/templates/mariadb/mysqld_config/dbstore3.my.cnf 
b/modules/role/templates/mariadb/mysqld_config/dbstore3.my.cnf
new file mode 100644
index 0000000..142376d
--- /dev/null
+++ b/modules/role/templates/mariadb/mysqld_config/dbstore3.my.cnf
@@ -0,0 +1,114 @@
+# dbstore delayed and analytic slaves
+
+# Please use separate .cnf templates for each type of server.
+
+[client]
+port   = 3306
+socket = /tmp/mysql.sock
+<% if @ssl == 'on' or @ssl == 'puppet-cert' %>
+# ssl
+ssl-ca=/etc/ssl/certs/Puppet_Internal_CA.pem
+ssl-cert=/etc/mysql/ssl/cert.pem
+ssl-key=/etc/mysql/ssl/server.key
+ssl-verify-server-cert
+<% end %>
+
+[mysqld]
+
+skip-external-locking
+skip-name-resolve
+temp-pool
+
+user      = mysql
+basedir   = <%= @basedir %>
+server_id = <%= @server_id %>
+
+# gtid_domain_id flag is needed for multisource replication and GTID.
+# # Strictly it is only needed on masters or servers that can potentially be
+# # masters but for consistency it should be set in all of them.
+# # https://mariadb.com/kb/en/mariadb/gtid/
+#
+gtid_domain_id  = <%= @gtid_domain_id %>
+
+read_only = 0
+
+# enable socket authentication
+plugin-load = unix_socket=auth_socket.so
+
+secure_file_priv   = /dev/null
+max_connections    = 250
+max_allowed_packet = 32M
+connect_timeout    = 3
+query_cache_size   = 0
+query_cache_type   = 0
+event_scheduler    = 1
+
+table_open_cache       = 50000
+table_definition_cache = 50000
+
+# InnoDB file-per-table + TokuDB love those file descriptors
+open-files-limit = 400000
+
+character_set_server     = binary
+character_set_filesystem = binary
+collation_server         = binary
+
+innodb_file_per_table          = 1
+innodb_buffer_pool_size        = 24G
+innodb_log_file_size           = 4G
+innodb_flush_log_at_trx_commit = 0
+innodb_flush_method            = O_DIRECT
+innodb_thread_concurrency      = 0
+innodb_io_capacity             = 1000
+innodb_stats_sample_pages      = 16
+innodb_stats_method            = nulls_unequal
+innodb_locks_unsafe_for_binlog = 1
+
+# dump and load innodb buffer at start and stop
+innodb_buffer_pool_load_at_startup  = 1
+innodb_buffer_pool_dump_at_shutdown = 1
+
+optimizer_switch='engine_condition_pushdown=on,optimize_join_buffer_size=on'
+join_cache_level = 8
+
+skip-slave-start
+slave_transaction_retries = 4294967295
+
+<% if @ssl == 'on' or @ssl == 'puppet-cert' %>
+# ssl
+ssl-ca=/etc/ssl/certs/Puppet_Internal_CA.pem
+ssl-cert=/etc/mysql/ssl/cert.pem
+ssl-key=/etc/mysql/ssl/server.key
+ssl-cipher=TLSv1.2
+<% end %>
+<% if @p_s == 'on' %>
+# Enabling performance_schema (disabled by default in MariaDB10)
+performance_schema                                     = 1
+# downsizing performance schema memory usage: T99485
+performance_schema_digests_size                        = -1
+performance_schema_max_thread_instances                = 500
+performance_schema_max_cond_instances                  = 1000
+performance_schema_accounts_size                       = 300
+performance_schema_hosts_size                          = 300
+performance_schema_events_statements_history_size      = 10
+performance_schema_events_statements_history_long_size = 1000
+performance_schema_events_waits_history_size           = 10
+performance_schema_events_waits_history_long_size      = 1000
+performance_schema_events_stages_history_size          = 10
+performance_schema_events_stages_history_long_size     = 1000
+performance_schema_max_mutex_instances                 = 5000
+performance_schema_max_rwlock_instances                = 2000
+performance_schema_max_socket_instances                = 500
+performance_schema_max_table_instances                 = 1000
+<% else %>
+# only enable userstat if p_s is disabled
+performance_schema                                     = 0
+userstat                                               = 1
+<% end %>
+
+[mysqldump]
+
+quick
+max_allowed_packet = 32M
+
+#!includedir /etc/mysql/mysqld.conf.d/

-- 
To view, visit https://gerrit.wikimedia.org/r/363195
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib313d12e6784700e0afaccd443acb181b7a0e1d4
Gerrit-PatchSet: 8
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Jcrespo <jcre...@wikimedia.org>
Gerrit-Reviewer: Jcrespo <jcre...@wikimedia.org>
Gerrit-Reviewer: Marostegui <maroste...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to