Merge lp:~hopem/charms/trusty/percona-cluster/next-fix-lp1425999 into lp:~openstack-charmers-archive/charms/trusty/percona-cluster/next

Proposed by Edward Hope-Morley
Status: Superseded
Proposed branch: lp:~hopem/charms/trusty/percona-cluster/next-fix-lp1425999
Merge into: lp:~openstack-charmers-archive/charms/trusty/percona-cluster/next
Diff against target: 154 lines (+46/-58)
1 file modified
hooks/charmhelpers/contrib/database/mysql.py (+46/-58)
To merge this branch: bzr merge lp:~hopem/charms/trusty/percona-cluster/next-fix-lp1425999
Reviewer Review Type Date Requested Status
Billy Olsen Approve
Review via email: mp+251161@code.launchpad.net

This proposal has been superseded by a proposal from 2015-02-27.

To post a comment you must log in.
Revision history for this message
Billy Olsen (billy-olsen) wrote :

LGTM, Approved. Everything looks good to in my testing.

review: Approve

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'hooks/charmhelpers/contrib/database/mysql.py'
--- hooks/charmhelpers/contrib/database/mysql.py 2015-02-25 20:48:34 +0000
+++ hooks/charmhelpers/contrib/database/mysql.py 2015-02-26 20:05:56 +0000
@@ -21,6 +21,7 @@
21 log,21 log,
22 DEBUG,22 DEBUG,
23 INFO,23 INFO,
24 WARNING,
24)25)
25from charmhelpers.core.hookenv import config as config_get26from charmhelpers.core.hookenv import config as config_get
26from charmhelpers.fetch import (27from charmhelpers.fetch import (
@@ -220,6 +221,24 @@
220 """Retrieve or generate mysql root password for service units."""221 """Retrieve or generate mysql root password for service units."""
221 return self.get_mysql_password(username=None, password=password)222 return self.get_mysql_password(username=None, password=password)
222223
224 def normalize_address(self, hostname):
225 """Ensure that address returned is an IP address (i.e. not fqdn)"""
226 if config_get('prefer-ipv6'):
227 # TODO: add support for ipv6 dns
228 return hostname
229
230 if hostname != unit_get('private-address'):
231 try:
232 return socket.gethostbyname(hostname)
233 except Exception:
234 # socket.gethostbyname doesn't support ipv6
235 log("Failed to normalize hostname '%s'" % (hostname),
236 level=WARNING)
237 return hostname
238
239 # Otherwise assume localhost
240 return '127.0.0.1'
241
223 def get_allowed_units(self, database, username, relation_id=None):242 def get_allowed_units(self, database, username, relation_id=None):
224 """Get list of units with access grants for database with username.243 """Get list of units with access grants for database with username.
225244
@@ -247,6 +266,7 @@
247266
248 if hosts:267 if hosts:
249 for host in hosts:268 for host in hosts:
269 host = self.normalize_address(host)
250 if self.grant_exists(database, username, host):270 if self.grant_exists(database, username, host):
251 log("Grant exists for host '%s' on db '%s'" %271 log("Grant exists for host '%s' on db '%s'" %
252 (host, database), level=DEBUG)272 (host, database), level=DEBUG)
@@ -262,21 +282,11 @@
262282
263 def configure_db(self, hostname, database, username, admin=False):283 def configure_db(self, hostname, database, username, admin=False):
264 """Configure access to database for username from hostname."""284 """Configure access to database for username from hostname."""
265 if config_get('prefer-ipv6'):
266 remote_ip = hostname
267 elif hostname != unit_get('private-address'):
268 try:
269 remote_ip = socket.gethostbyname(hostname)
270 except Exception:
271 # socket.gethostbyname doesn't support ipv6
272 remote_ip = hostname
273 else:
274 remote_ip = '127.0.0.1'
275
276 self.connect(password=self.get_mysql_root_password())285 self.connect(password=self.get_mysql_root_password())
277 if not self.database_exists(database):286 if not self.database_exists(database):
278 self.create_database(database)287 self.create_database(database)
279288
289 remote_ip = self.normalize_address(hostname)
280 password = self.get_mysql_password(username)290 password = self.get_mysql_password(username)
281 if not self.grant_exists(database, username, remote_ip):291 if not self.grant_exists(database, username, remote_ip):
282 if not admin:292 if not admin:
@@ -289,9 +299,11 @@
289299
290class PerconaClusterHelper(object):300class PerconaClusterHelper(object):
291301
292 # Going for the biggest page size to avoid wasted bytes. InnoDB page size is302 # Going for the biggest page size to avoid wasted bytes.
293 # 16MB303 # InnoDB page size is 16MB
304
294 DEFAULT_PAGE_SIZE = 16 * 1024 * 1024305 DEFAULT_PAGE_SIZE = 16 * 1024 * 1024
306 DEFAULT_INNODB_BUFFER_FACTOR = 0.50
295307
296 def human_to_bytes(self, human):308 def human_to_bytes(self, human):
297 """Convert human readable configuration options to bytes."""309 """Convert human readable configuration options to bytes."""
@@ -352,51 +364,27 @@
352 if 'max-connections' in config:364 if 'max-connections' in config:
353 mysql_config['max_connections'] = config['max-connections']365 mysql_config['max_connections'] = config['max-connections']
354366
355 # Total memory available for dataset
356 dataset_bytes = self.human_to_bytes(config['dataset-size'])
357 mysql_config['dataset_bytes'] = dataset_bytes
358
359 if 'query-cache-type' in config:
360 # Query Cache Configuration
361 mysql_config['query_cache_size'] = config['query-cache-size']
362 if (config['query-cache-size'] == -1 and
363 config['query-cache-type'] in ['ON', 'DEMAND']):
364 # Calculate the query cache size automatically
365 qcache_bytes = (dataset_bytes * 0.20)
366 qcache_bytes = int(qcache_bytes -
367 (qcache_bytes % self.DEFAULT_PAGE_SIZE))
368 mysql_config['query_cache_size'] = qcache_bytes
369 dataset_bytes -= qcache_bytes
370
371 # 5.5 allows the words, but not 5.1
372 if config['query-cache-type'] == 'ON':
373 mysql_config['query_cache_type'] = 1
374 elif config['query-cache-type'] == 'DEMAND':
375 mysql_config['query_cache_type'] = 2
376 else:
377 mysql_config['query_cache_type'] = 0
378
379 # Set a sane default key_buffer size367 # Set a sane default key_buffer size
380 mysql_config['key_buffer'] = self.human_to_bytes('32M')368 mysql_config['key_buffer'] = self.human_to_bytes('32M')
381369 total_memory = self.human_to_bytes(self.get_mem_total())
382 if 'preferred-storage-engine' in config:370
383 # Storage engine configuration371 log("Option 'dataset-size' has been deprecated, instead by default %d%% of system \
384 preferred_engines = config['preferred-storage-engine'].split(',')372 available RAM will be used for innodb_buffer_pool_size allocation" %
385 chunk_size = int(dataset_bytes / len(preferred_engines))373 (self.DEFAULT_INNODB_BUFFER_FACTOR * 100), level="WARN")
386 mysql_config['innodb_flush_log_at_trx_commit'] = 1374
387 mysql_config['sync_binlog'] = 1375 innodb_buffer_pool_size = config.get('innodb-buffer-pool-size', None)
388 if 'InnoDB' in preferred_engines:376
389 mysql_config['innodb_buffer_pool_size'] = chunk_size377 if innodb_buffer_pool_size:
390 if config['tuning-level'] == 'fast':378 innodb_buffer_pool_size = self.human_to_bytes(
391 mysql_config['innodb_flush_log_at_trx_commit'] = 2379 innodb_buffer_pool_size)
392 else:380
393 mysql_config['innodb_buffer_pool_size'] = 0381 if innodb_buffer_pool_size > total_memory:
394382 log("innodb_buffer_pool_size; {} is greater than system available memory:{}".format(
395 mysql_config['default_storage_engine'] = preferred_engines[0]383 innodb_buffer_pool_size,
396 if 'MyISAM' in preferred_engines:384 total_memory), level='WARN')
397 mysql_config['key_buffer'] = chunk_size385 else:
398386 innodb_buffer_pool_size = int(
399 if config['tuning-level'] == 'fast':387 total_memory * self.DEFAULT_INNODB_BUFFER_FACTOR)
400 mysql_config['sync_binlog'] = 0388
401389 mysql_config['innodb_buffer_pool_size'] = innodb_buffer_pool_size
402 return mysql_config390 return mysql_config

Subscribers

People subscribed via source and target branches