~hopem/charm-helpers/fix-ssl-disable

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/database/mysql.py

  • Committer: Jorge Niedbalski
  • Date: 2015-02-26 16:05:44 UTC
  • mfrom: (321.2.8 devel)
  • Revision ID: jorge.niedbalski@canonical.com-20150226160544-wrcnm2gyqvl0opeq
[niedbalski, r=freyes,mario-splivalo] Fixes bug LP: #1425528

Show diffs side-by-side

added added

removed removed

Lines of Context:
289
289
 
290
290
class PerconaClusterHelper(object):
291
291
 
292
 
    # Going for the biggest page size to avoid wasted bytes. InnoDB page size is
293
 
    # 16MB
 
292
    # Going for the biggest page size to avoid wasted bytes.
 
293
    # InnoDB page size is 16MB
 
294
 
294
295
    DEFAULT_PAGE_SIZE = 16 * 1024 * 1024
 
296
    DEFAULT_INNODB_BUFFER_FACTOR = 0.50
295
297
 
296
298
    def human_to_bytes(self, human):
297
299
        """Convert human readable configuration options to bytes."""
352
354
        if 'max-connections' in config:
353
355
            mysql_config['max_connections'] = config['max-connections']
354
356
 
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
357
        # Set a sane default key_buffer size
380
358
        mysql_config['key_buffer'] = self.human_to_bytes('32M')
381
 
 
382
 
        if 'preferred-storage-engine' in config:
383
 
            # Storage engine configuration
384
 
            preferred_engines = config['preferred-storage-engine'].split(',')
385
 
            chunk_size = int(dataset_bytes / len(preferred_engines))
386
 
            mysql_config['innodb_flush_log_at_trx_commit'] = 1
387
 
            mysql_config['sync_binlog'] = 1
388
 
            if 'InnoDB' in preferred_engines:
389
 
                mysql_config['innodb_buffer_pool_size'] = chunk_size
390
 
                if config['tuning-level'] == 'fast':
391
 
                    mysql_config['innodb_flush_log_at_trx_commit'] = 2
392
 
            else:
393
 
                mysql_config['innodb_buffer_pool_size'] = 0
394
 
 
395
 
            mysql_config['default_storage_engine'] = preferred_engines[0]
396
 
            if 'MyISAM' in preferred_engines:
397
 
                mysql_config['key_buffer'] = chunk_size
398
 
 
399
 
            if config['tuning-level'] == 'fast':
400
 
                mysql_config['sync_binlog'] = 0
401
 
 
 
359
        total_memory = self.human_to_bytes(self.get_mem_total())
 
360
 
 
361
        log("Option 'dataset-size' has been deprecated, instead by default %d%% of system \
 
362
        available RAM will be used for innodb_buffer_pool_size allocation" %
 
363
            (self.DEFAULT_INNODB_BUFFER_FACTOR * 100), level="WARN")
 
364
 
 
365
        innodb_buffer_pool_size = config.get('innodb-buffer-pool-size', None)
 
366
 
 
367
        if innodb_buffer_pool_size:
 
368
            innodb_buffer_pool_size = self.human_to_bytes(
 
369
                innodb_buffer_pool_size)
 
370
 
 
371
            if innodb_buffer_pool_size > total_memory:
 
372
                log("innodb_buffer_pool_size; {} is greater than system available memory:{}".format(
 
373
                    innodb_buffer_pool_size,
 
374
                    total_memory), level='WARN')
 
375
        else:
 
376
            innodb_buffer_pool_size = int(
 
377
                total_memory * self.DEFAULT_INNODB_BUFFER_FACTOR)
 
378
 
 
379
        mysql_config['innodb_buffer_pool_size'] = innodb_buffer_pool_size
402
380
        return mysql_config