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
=== modified file 'charmhelpers/contrib/database/mysql.py'
--- charmhelpers/contrib/database/mysql.py 2015-02-25 18:42:20 +0000
+++ charmhelpers/contrib/database/mysql.py 2015-02-26 15:29:30 +0000
@@ -289,9 +289,11 @@
289289
290class PerconaClusterHelper(object):290class PerconaClusterHelper(object):
291291
292 # Going for the biggest page size to avoid wasted bytes. InnoDB page size is292 # Going for the biggest page size to avoid wasted bytes.
293 # 16MB293 # InnoDB page size is 16MB
294
294 DEFAULT_PAGE_SIZE = 16 * 1024 * 1024295 DEFAULT_PAGE_SIZE = 16 * 1024 * 1024
296 DEFAULT_INNODB_BUFFER_FACTOR = 0.50
295297
296 def human_to_bytes(self, human):298 def human_to_bytes(self, human):
297 """Convert human readable configuration options to bytes."""299 """Convert human readable configuration options to bytes."""
@@ -352,51 +354,27 @@
352 if 'max-connections' in config:354 if 'max-connections' in config:
353 mysql_config['max_connections'] = config['max-connections']355 mysql_config['max_connections'] = config['max-connections']
354356
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 size357 # Set a sane default key_buffer size
380 mysql_config['key_buffer'] = self.human_to_bytes('32M')358 mysql_config['key_buffer'] = self.human_to_bytes('32M')
381359 total_memory = self.human_to_bytes(self.get_mem_total())
382 if 'preferred-storage-engine' in config:360
383 # Storage engine configuration361 log("Option 'dataset-size' has been deprecated, instead by default %d%% of system \
384 preferred_engines = config['preferred-storage-engine'].split(',')362 available RAM will be used for innodb_buffer_pool_size allocation" %
385 chunk_size = int(dataset_bytes / len(preferred_engines))363 (self.DEFAULT_INNODB_BUFFER_FACTOR * 100), level="WARN")
386 mysql_config['innodb_flush_log_at_trx_commit'] = 1364
387 mysql_config['sync_binlog'] = 1365 innodb_buffer_pool_size = config.get('innodb-buffer-pool-size', None)
388 if 'InnoDB' in preferred_engines:366
389 mysql_config['innodb_buffer_pool_size'] = chunk_size367 if innodb_buffer_pool_size:
390 if config['tuning-level'] == 'fast':368 innodb_buffer_pool_size = self.human_to_bytes(
391 mysql_config['innodb_flush_log_at_trx_commit'] = 2369 innodb_buffer_pool_size)
392 else:370
393 mysql_config['innodb_buffer_pool_size'] = 0371 if innodb_buffer_pool_size > total_memory:
394372 log("innodb_buffer_pool_size; {} is greater than system available memory:{}".format(
395 mysql_config['default_storage_engine'] = preferred_engines[0]373 innodb_buffer_pool_size,
396 if 'MyISAM' in preferred_engines:374 total_memory), level='WARN')
397 mysql_config['key_buffer'] = chunk_size375 else:
398376 innodb_buffer_pool_size = int(
399 if config['tuning-level'] == 'fast':377 total_memory * self.DEFAULT_INNODB_BUFFER_FACTOR)
400 mysql_config['sync_binlog'] = 0378
401379 mysql_config['innodb_buffer_pool_size'] = innodb_buffer_pool_size
402 return mysql_config380 return mysql_config
403381
=== modified file 'tests/contrib/database/test_mysql.py'
--- tests/contrib/database/test_mysql.py 2015-02-11 21:41:57 +0000
+++ tests/contrib/database/test_mysql.py 2015-02-26 15:29:30 +0000
@@ -53,3 +53,39 @@
5353
54 helper.grant_exists.assert_has_calls(calls)54 helper.grant_exists.assert_has_calls(calls)
55 self.assertEqual(units, set(['unit/0', 'unit/1', 'unit/2']))55 self.assertEqual(units, set(['unit/0', 'unit/1', 'unit/2']))
56
57
58class PerconaTests(unittest.TestCase):
59
60 def setUp(self):
61 super(PerconaTests, self).setUp()
62
63 @mock.patch.object(mysql.PerconaClusterHelper, 'get_mem_total')
64 @mock.patch.object(mysql, 'config_get')
65 def test_parse_config_innodb_pool_fixed(self, config, mem):
66 mem.return_value = "100G"
67 config.return_value = {
68 'innodb-buffer-pool-size': "50%",
69 }
70
71 helper = mysql.PerconaClusterHelper()
72 mysql_config = helper.parse_config()
73
74 self.assertEqual(mysql_config.get('innodb_buffer_pool_size'),
75 helper.human_to_bytes("50G"))
76
77 @mock.patch.object(mysql.PerconaClusterHelper, 'get_mem_total')
78 @mock.patch.object(mysql, 'config_get')
79 def test_parse_config_innodb_pool_not_set(self, config, mem):
80 mem.return_value = "100G"
81 config.return_value = {
82 'innodb-buffer-pool-size': '',
83 }
84
85 helper = mysql.PerconaClusterHelper()
86 mysql_config = helper.parse_config()
87
88 self.assertEqual(
89 mysql_config.get('innodb_buffer_pool_size'),
90 int(helper.human_to_bytes(mem.return_value) *
91 helper.DEFAULT_INNODB_BUFFER_FACTOR))

Subscribers

People subscribed via source and target branches