Merge lp:~niedbalski/charm-helpers/fix-1425528 into lp:charm-helpers

Proposed by Jorge Niedbalski
Status: Merged
Merged at revision: 323
Proposed branch: lp:~niedbalski/charm-helpers/fix-1425528
Merge into: lp:charm-helpers
Diff against target: 134 lines (+61/-47)
2 files modified
charmhelpers/contrib/database/mysql.py (+25/-47)
tests/contrib/database/test_mysql.py (+36/-0)
To merge this branch: bzr merge lp:~niedbalski/charm-helpers/fix-1425528
Reviewer Review Type Date Requested Status
Jorge Niedbalski (community) Approve
Mario Splivalo (community) Approve
Felipe Reyes (community) Approve
Review via email: mp+250977@code.launchpad.net

Description of the change

-Fixes LP Bug: #1425528

To post a comment you must log in.
Revision history for this message
Felipe Reyes (freyes) wrote :

Thanks Jorge, LGTM

review: Approve
326. By Jorge Niedbalski

tuning-level option is not available on the percona-cluster charm

327. By Jorge Niedbalski

tuning-level option is not available on the percona-cluster charm

Revision history for this message
Mario Splivalo (mariosplivalo) wrote :

I made a mistake here - I overlooked the target and wrongly assumed we are discussing percona-cluster here, I am sorry!

Please see my inline comments.

review: Needs Fixing
Revision history for this message
Mario Splivalo (mariosplivalo) wrote :

And wrong again - next time will do review from bzr's qlog, not from launchpad.
This is, indeed, PerconaClusterHelper.

Looks fine to me! Thank you for accepting suggestions.

review: Approve
328. By Jorge Niedbalski

Adding a warn for "dataset-size" option deprecation

329. By Jorge Niedbalski

Adding a warn for "dataset-size" option deprecation

Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

Thanks for the reviews.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/database/mysql.py'
2--- charmhelpers/contrib/database/mysql.py 2015-02-25 18:42:20 +0000
3+++ charmhelpers/contrib/database/mysql.py 2015-02-26 15:29:30 +0000
4@@ -289,9 +289,11 @@
5
6 class PerconaClusterHelper(object):
7
8- # Going for the biggest page size to avoid wasted bytes. InnoDB page size is
9- # 16MB
10+ # Going for the biggest page size to avoid wasted bytes.
11+ # InnoDB page size is 16MB
12+
13 DEFAULT_PAGE_SIZE = 16 * 1024 * 1024
14+ DEFAULT_INNODB_BUFFER_FACTOR = 0.50
15
16 def human_to_bytes(self, human):
17 """Convert human readable configuration options to bytes."""
18@@ -352,51 +354,27 @@
19 if 'max-connections' in config:
20 mysql_config['max_connections'] = config['max-connections']
21
22- # Total memory available for dataset
23- dataset_bytes = self.human_to_bytes(config['dataset-size'])
24- mysql_config['dataset_bytes'] = dataset_bytes
25-
26- if 'query-cache-type' in config:
27- # Query Cache Configuration
28- mysql_config['query_cache_size'] = config['query-cache-size']
29- if (config['query-cache-size'] == -1 and
30- config['query-cache-type'] in ['ON', 'DEMAND']):
31- # Calculate the query cache size automatically
32- qcache_bytes = (dataset_bytes * 0.20)
33- qcache_bytes = int(qcache_bytes -
34- (qcache_bytes % self.DEFAULT_PAGE_SIZE))
35- mysql_config['query_cache_size'] = qcache_bytes
36- dataset_bytes -= qcache_bytes
37-
38- # 5.5 allows the words, but not 5.1
39- if config['query-cache-type'] == 'ON':
40- mysql_config['query_cache_type'] = 1
41- elif config['query-cache-type'] == 'DEMAND':
42- mysql_config['query_cache_type'] = 2
43- else:
44- mysql_config['query_cache_type'] = 0
45-
46 # Set a sane default key_buffer size
47 mysql_config['key_buffer'] = self.human_to_bytes('32M')
48-
49- if 'preferred-storage-engine' in config:
50- # Storage engine configuration
51- preferred_engines = config['preferred-storage-engine'].split(',')
52- chunk_size = int(dataset_bytes / len(preferred_engines))
53- mysql_config['innodb_flush_log_at_trx_commit'] = 1
54- mysql_config['sync_binlog'] = 1
55- if 'InnoDB' in preferred_engines:
56- mysql_config['innodb_buffer_pool_size'] = chunk_size
57- if config['tuning-level'] == 'fast':
58- mysql_config['innodb_flush_log_at_trx_commit'] = 2
59- else:
60- mysql_config['innodb_buffer_pool_size'] = 0
61-
62- mysql_config['default_storage_engine'] = preferred_engines[0]
63- if 'MyISAM' in preferred_engines:
64- mysql_config['key_buffer'] = chunk_size
65-
66- if config['tuning-level'] == 'fast':
67- mysql_config['sync_binlog'] = 0
68-
69+ total_memory = self.human_to_bytes(self.get_mem_total())
70+
71+ log("Option 'dataset-size' has been deprecated, instead by default %d%% of system \
72+ available RAM will be used for innodb_buffer_pool_size allocation" %
73+ (self.DEFAULT_INNODB_BUFFER_FACTOR * 100), level="WARN")
74+
75+ innodb_buffer_pool_size = config.get('innodb-buffer-pool-size', None)
76+
77+ if innodb_buffer_pool_size:
78+ innodb_buffer_pool_size = self.human_to_bytes(
79+ innodb_buffer_pool_size)
80+
81+ if innodb_buffer_pool_size > total_memory:
82+ log("innodb_buffer_pool_size; {} is greater than system available memory:{}".format(
83+ innodb_buffer_pool_size,
84+ total_memory), level='WARN')
85+ else:
86+ innodb_buffer_pool_size = int(
87+ total_memory * self.DEFAULT_INNODB_BUFFER_FACTOR)
88+
89+ mysql_config['innodb_buffer_pool_size'] = innodb_buffer_pool_size
90 return mysql_config
91
92=== modified file 'tests/contrib/database/test_mysql.py'
93--- tests/contrib/database/test_mysql.py 2015-02-11 21:41:57 +0000
94+++ tests/contrib/database/test_mysql.py 2015-02-26 15:29:30 +0000
95@@ -53,3 +53,39 @@
96
97 helper.grant_exists.assert_has_calls(calls)
98 self.assertEqual(units, set(['unit/0', 'unit/1', 'unit/2']))
99+
100+
101+class PerconaTests(unittest.TestCase):
102+
103+ def setUp(self):
104+ super(PerconaTests, self).setUp()
105+
106+ @mock.patch.object(mysql.PerconaClusterHelper, 'get_mem_total')
107+ @mock.patch.object(mysql, 'config_get')
108+ def test_parse_config_innodb_pool_fixed(self, config, mem):
109+ mem.return_value = "100G"
110+ config.return_value = {
111+ 'innodb-buffer-pool-size': "50%",
112+ }
113+
114+ helper = mysql.PerconaClusterHelper()
115+ mysql_config = helper.parse_config()
116+
117+ self.assertEqual(mysql_config.get('innodb_buffer_pool_size'),
118+ helper.human_to_bytes("50G"))
119+
120+ @mock.patch.object(mysql.PerconaClusterHelper, 'get_mem_total')
121+ @mock.patch.object(mysql, 'config_get')
122+ def test_parse_config_innodb_pool_not_set(self, config, mem):
123+ mem.return_value = "100G"
124+ config.return_value = {
125+ 'innodb-buffer-pool-size': '',
126+ }
127+
128+ helper = mysql.PerconaClusterHelper()
129+ mysql_config = helper.parse_config()
130+
131+ self.assertEqual(
132+ mysql_config.get('innodb_buffer_pool_size'),
133+ int(helper.human_to_bytes(mem.return_value) *
134+ helper.DEFAULT_INNODB_BUFFER_FACTOR))

Subscribers

People subscribed via source and target branches