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
1=== modified file 'hooks/charmhelpers/contrib/database/mysql.py'
2--- hooks/charmhelpers/contrib/database/mysql.py 2015-02-25 20:48:34 +0000
3+++ hooks/charmhelpers/contrib/database/mysql.py 2015-02-26 20:05:56 +0000
4@@ -21,6 +21,7 @@
5 log,
6 DEBUG,
7 INFO,
8+ WARNING,
9 )
10 from charmhelpers.core.hookenv import config as config_get
11 from charmhelpers.fetch import (
12@@ -220,6 +221,24 @@
13 """Retrieve or generate mysql root password for service units."""
14 return self.get_mysql_password(username=None, password=password)
15
16+ def normalize_address(self, hostname):
17+ """Ensure that address returned is an IP address (i.e. not fqdn)"""
18+ if config_get('prefer-ipv6'):
19+ # TODO: add support for ipv6 dns
20+ return hostname
21+
22+ if hostname != unit_get('private-address'):
23+ try:
24+ return socket.gethostbyname(hostname)
25+ except Exception:
26+ # socket.gethostbyname doesn't support ipv6
27+ log("Failed to normalize hostname '%s'" % (hostname),
28+ level=WARNING)
29+ return hostname
30+
31+ # Otherwise assume localhost
32+ return '127.0.0.1'
33+
34 def get_allowed_units(self, database, username, relation_id=None):
35 """Get list of units with access grants for database with username.
36
37@@ -247,6 +266,7 @@
38
39 if hosts:
40 for host in hosts:
41+ host = self.normalize_address(host)
42 if self.grant_exists(database, username, host):
43 log("Grant exists for host '%s' on db '%s'" %
44 (host, database), level=DEBUG)
45@@ -262,21 +282,11 @@
46
47 def configure_db(self, hostname, database, username, admin=False):
48 """Configure access to database for username from hostname."""
49- if config_get('prefer-ipv6'):
50- remote_ip = hostname
51- elif hostname != unit_get('private-address'):
52- try:
53- remote_ip = socket.gethostbyname(hostname)
54- except Exception:
55- # socket.gethostbyname doesn't support ipv6
56- remote_ip = hostname
57- else:
58- remote_ip = '127.0.0.1'
59-
60 self.connect(password=self.get_mysql_root_password())
61 if not self.database_exists(database):
62 self.create_database(database)
63
64+ remote_ip = self.normalize_address(hostname)
65 password = self.get_mysql_password(username)
66 if not self.grant_exists(database, username, remote_ip):
67 if not admin:
68@@ -289,9 +299,11 @@
69
70 class PerconaClusterHelper(object):
71
72- # Going for the biggest page size to avoid wasted bytes. InnoDB page size is
73- # 16MB
74+ # Going for the biggest page size to avoid wasted bytes.
75+ # InnoDB page size is 16MB
76+
77 DEFAULT_PAGE_SIZE = 16 * 1024 * 1024
78+ DEFAULT_INNODB_BUFFER_FACTOR = 0.50
79
80 def human_to_bytes(self, human):
81 """Convert human readable configuration options to bytes."""
82@@ -352,51 +364,27 @@
83 if 'max-connections' in config:
84 mysql_config['max_connections'] = config['max-connections']
85
86- # Total memory available for dataset
87- dataset_bytes = self.human_to_bytes(config['dataset-size'])
88- mysql_config['dataset_bytes'] = dataset_bytes
89-
90- if 'query-cache-type' in config:
91- # Query Cache Configuration
92- mysql_config['query_cache_size'] = config['query-cache-size']
93- if (config['query-cache-size'] == -1 and
94- config['query-cache-type'] in ['ON', 'DEMAND']):
95- # Calculate the query cache size automatically
96- qcache_bytes = (dataset_bytes * 0.20)
97- qcache_bytes = int(qcache_bytes -
98- (qcache_bytes % self.DEFAULT_PAGE_SIZE))
99- mysql_config['query_cache_size'] = qcache_bytes
100- dataset_bytes -= qcache_bytes
101-
102- # 5.5 allows the words, but not 5.1
103- if config['query-cache-type'] == 'ON':
104- mysql_config['query_cache_type'] = 1
105- elif config['query-cache-type'] == 'DEMAND':
106- mysql_config['query_cache_type'] = 2
107- else:
108- mysql_config['query_cache_type'] = 0
109-
110 # Set a sane default key_buffer size
111 mysql_config['key_buffer'] = self.human_to_bytes('32M')
112-
113- if 'preferred-storage-engine' in config:
114- # Storage engine configuration
115- preferred_engines = config['preferred-storage-engine'].split(',')
116- chunk_size = int(dataset_bytes / len(preferred_engines))
117- mysql_config['innodb_flush_log_at_trx_commit'] = 1
118- mysql_config['sync_binlog'] = 1
119- if 'InnoDB' in preferred_engines:
120- mysql_config['innodb_buffer_pool_size'] = chunk_size
121- if config['tuning-level'] == 'fast':
122- mysql_config['innodb_flush_log_at_trx_commit'] = 2
123- else:
124- mysql_config['innodb_buffer_pool_size'] = 0
125-
126- mysql_config['default_storage_engine'] = preferred_engines[0]
127- if 'MyISAM' in preferred_engines:
128- mysql_config['key_buffer'] = chunk_size
129-
130- if config['tuning-level'] == 'fast':
131- mysql_config['sync_binlog'] = 0
132-
133+ total_memory = self.human_to_bytes(self.get_mem_total())
134+
135+ log("Option 'dataset-size' has been deprecated, instead by default %d%% of system \
136+ available RAM will be used for innodb_buffer_pool_size allocation" %
137+ (self.DEFAULT_INNODB_BUFFER_FACTOR * 100), level="WARN")
138+
139+ innodb_buffer_pool_size = config.get('innodb-buffer-pool-size', None)
140+
141+ if innodb_buffer_pool_size:
142+ innodb_buffer_pool_size = self.human_to_bytes(
143+ innodb_buffer_pool_size)
144+
145+ if innodb_buffer_pool_size > total_memory:
146+ log("innodb_buffer_pool_size; {} is greater than system available memory:{}".format(
147+ innodb_buffer_pool_size,
148+ total_memory), level='WARN')
149+ else:
150+ innodb_buffer_pool_size = int(
151+ total_memory * self.DEFAULT_INNODB_BUFFER_FACTOR)
152+
153+ mysql_config['innodb_buffer_pool_size'] = innodb_buffer_pool_size
154 return mysql_config

Subscribers

People subscribed via source and target branches