Merge lp:~mariosplivalo/charms/trusty/percona-cluster/enable-binlogs into lp:~openstack-charmers-archive/charms/trusty/percona-cluster/next

Proposed by Mario Splivalo
Status: Work in progress
Proposed branch: lp:~mariosplivalo/charms/trusty/percona-cluster/enable-binlogs
Merge into: lp:~openstack-charmers-archive/charms/trusty/percona-cluster/next
Prerequisite: lp:~niedbalski/charms/trusty/percona-cluster/fix-1425528
Diff against target: 155 lines (+52/-4)
4 files modified
config.yaml (+11/-0)
hooks/percona_hooks.py (+14/-3)
hooks/percona_utils.py (+23/-1)
templates/my.cnf (+4/-0)
To merge this branch: bzr merge lp:~mariosplivalo/charms/trusty/percona-cluster/enable-binlogs
Reviewer Review Type Date Requested Status
Ryan Beisner (community) Needs Fixing
Billy Olsen Needs Fixing
OpenStack Charmers Pending
James Page Pending
Edward Hope-Morley Pending
Felipe Reyes Pending
Jorge Niedbalski Pending
Review via email: mp+274394@code.launchpad.net

This proposal supersedes a proposal from 2015-03-09.

Description of the change

This adds two charm configuration options - enable_binlogs and binlogs_path. Binlog_path defaults to /var/log/mysql/mysql.bin (it's because my.cnf which is packaged with mysql-common package suggests that location, and also because mysql charm defaults with binlogs at that location), while enable_binlogs defaults to 'False'.

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

Hi Mario,

This feature makes a lot of sense, and it worked for me, but please add unit tests for your patch, I also have minor comments in the diff.

Thanks,

review: Needs Fixing
Revision history for this message
James Page (james-page) wrote : Posted in a previous version of this proposal

bzr merge lp:~mariosplivalo/charms/trusty/percona-cluster/enable-binlogs
...
Text conflict in hooks/charmhelpers/contrib/database/mysql.py
1 conflicts encountered.

review: Needs Fixing
Revision history for this message
James Page (james-page) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Mario Splivalo (mariosplivalo) wrote : Posted in a previous version of this proposal

> bzr merge lp:~mariosplivalo/charms/trusty/percona-cluster/enable-binlogs
> ...
> Text conflict in hooks/charmhelpers/contrib/database/mysql.py
> 1 conflicts encountered.

I belive this is because of the prerequisite branch that needs merging first.

Revision history for this message
Mario Splivalo (mariosplivalo) wrote : Posted in a previous version of this proposal

Based on discussion with Ed, this will be changed in a manner so that a new function is introduced, 'configure_binlogs'. That one will be called from install hook, after mysql has been installed, and will restart mysql for the change to take place.
It will also be called from config_changed hook, but it won't restart mysql - it will log a WARNING inside logs to tell administrator/operator to manually restart mysql when appropriate.

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #11893 percona-cluster-next for mariosplivalo mp274394
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/11893/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #11062 percona-cluster-next for mariosplivalo mp274394
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/11062/

Revision history for this message
Billy Olsen (billy-olsen) wrote :

I'm a little confused. Based on the feedback from James and Ed, I wasn't expecting this creating of the directories in the render_config function - or am I missing something?

review: Needs Information
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #11231 percona-cluster-next for mariosplivalo mp274394
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/11231/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #12091 percona-cluster-next for mariosplivalo mp274394
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/12091/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #7421 percona-cluster-next for mariosplivalo mp274394
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/7421/

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

> I'm a little confused. Based on the feedback from James and Ed, I wasn't
> expecting this creating of the directories in the render_config function - or
> am I missing something?

You are right. I have isolated this into separate function, configure_binlogs_directory().

Revision history for this message
Billy Olsen (billy-olsen) wrote :

I think this is close, but the two calls to the configure_binlogs_directory() feels a bit kludgy - I think that needs a little rework or thought there.

review: Needs Fixing
61. By Mario Splivalo

Conflicts resolved (work from another workstation)

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #13811 percona-cluster-next for mariosplivalo mp274394
    UNIT FAIL: unit-test failed

UNIT Results (max last 2 lines):
make: *** [test] Error 1
ERROR:root:Make target returned non-zero.

Full unit test output: http://paste.ubuntu.com/13644697/
Build: http://10.245.162.77:8080/job/charm_unit_test/13811/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #14811 percona-cluster-next for mariosplivalo mp274394
    LINT FAIL: lint-test failed

LINT Results (max last 2 lines):
make: *** [lint] Error 1
ERROR:root:Make target returned non-zero.

Full lint test output: http://paste.ubuntu.com/13644698/
Build: http://10.245.162.77:8080/job/charm_lint_check/14811/

Revision history for this message
Ryan Beisner (1chb1n) wrote :

FYI, the percona cluster install hook is failing:

2015-12-03 14:28:13 INFO install Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
2015-12-03 14:28:13 INFO install Traceback (most recent call last):
2015-12-03 14:28:13 INFO install File "/var/lib/juju/agents/unit-mysql-0/charm/hooks/install.real", line 46, in <module>
2015-12-03 14:28:13 INFO install from percona_utils import (
2015-12-03 14:28:13 INFO install ImportError: cannot import name configure_binlogs

review: Needs Fixing
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #8132 percona-cluster-next for mariosplivalo mp274394
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/13657282/
Build: http://10.245.162.77:8080/job/charm_amulet_test/8132/

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

This is WIP, no idea why this was submitted...

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

> This is WIP, no idea why this was submitted...

Because it was set to 'Needs review' :( My fault.

Unmerged revisions

61. By Mario Splivalo

Conflicts resolved (work from another workstation)

60. By Mario Splivalo

Merged /next

59. By Mario Splivalo

Isolate creation of binlog directory into a separate function

58. By Mario Splivalo

Merged from /next

57. By Mario Splivalo

Fixed typos, as suggested by freyes

56. By Mario Splivalo

Fix lint errors

55. By Mario Splivalo

Remove call to lchownr as it won't change owner of the base directory.
Instead, use os.chown.

54. By Mario Splivalo

Fix directory creation

53. By Mario Splivalo

Make sure mysql can start even when binlog_path is pointing to
nonexistant path

52. By Mario Splivalo

Create binlog_directory, if missing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2015-10-29 12:30:18 +0000
3+++ config.yaml 2015-12-03 13:33:30 +0000
4@@ -152,3 +152,14 @@
5 description: |
6 A comma-separated list of nagios servicegroups. If left empty, the
7 nagios_context will be used as the servicegroup.
8+ enable-binlogs:
9+ default: False
10+ type: boolean
11+ description: Turns on MySQL binary logs. The placement of the logs is controlled with the binlogs_path config option.
12+ binlogs-path:
13+ default: /var/log/mysql/mysql-bin.log
14+ type: string
15+ description: |
16+ Location on the filesystem where binlogs are going to be placed.
17+ Default mimics what mysql-common would do for mysql (although not the
18+ best place for binlogs)
19
20=== modified file 'hooks/percona_hooks.py'
21--- hooks/percona_hooks.py 2015-11-16 10:14:55 +0000
22+++ hooks/percona_hooks.py 2015-12-03 13:33:30 +0000
23@@ -51,6 +51,7 @@
24 get_cluster_hosts,
25 configure_sstuser,
26 configure_mysql_root_password,
27+ configure_binlogs,
28 relation_clear,
29 assert_charm_supports_ipv6,
30 unit_sorted,
31@@ -61,6 +62,7 @@
32 notify_bootstrapped,
33 is_bootstrapped,
34 get_wsrep_value,
35+ configure_binlogs_directory,
36 assess_status,
37 )
38 from charmhelpers.contrib.database.mysql import (
39@@ -94,6 +96,8 @@
40 'op monitor interval="1s" timeout="30s" '
41 'OCF_CHECK_LEVEL="1"')
42
43+MYSQL_DATA_DIR = '/var/lib/mysql'
44+
45
46 @hooks.hook('install.real')
47 def install():
48@@ -107,8 +111,10 @@
49 configure_mysql_root_password(config('root-password'))
50 # Render base configuration (no cluster)
51 render_config()
52+ configure_binlogs_directory() # this creates binlogs dir if needed
53 apt_update(fatal=True)
54 apt_install(determine_packages(), fatal=True)
55+ configure_binlogs_directory() # this fixed the owner/permissions
56 configure_sstuser(config('sst-password'))
57
58
59@@ -125,7 +131,9 @@
60 'sst_password': config('sst-password'),
61 'innodb_file_per_table': config('innodb-file-per-table'),
62 'table_open_cache': config('table-open-cache'),
63- 'lp1366997_workaround': config('lp1366997-workaround')
64+ 'lp1366997_workaround': config('lp1366997-workaround'),
65+ 'binlogs_path': config('binlogs-path'),
66+ 'enable_binlogs': config('enable-binlogs')
67 }
68
69 if config('prefer-ipv6'):
70@@ -202,8 +210,7 @@
71 for r_id in relation_ids('shared-db'):
72 for unit in related_units(r_id):
73 shared_db_changed(r_id, unit)
74-
75-
76+
77 @hooks.hook('upgrade-charm')
78 def upgrade():
79 check_bootstrap = False
80@@ -240,6 +247,9 @@
81 # applies if min-cluster-size is provided and is used to avoid extraneous
82 # configuration changes and premature bootstrapping as the cluster is
83 # deployed.
84+
85+ configure_binlogs_directory()
86+
87 if is_sufficient_peers():
88 try:
89 # NOTE(jamespage): try with leadership election
90@@ -262,6 +272,7 @@
91 log("Leader unit - bootstrap required=%s" % (not bootstrapped),
92 DEBUG)
93 render_config_restart_on_changed(clustered, hosts,
94+
95 bootstrap=not bootstrapped)
96 elif bootstrapped:
97 log("Cluster is bootstrapped - configuring mysql on this node",
98
99=== modified file 'hooks/percona_utils.py'
100--- hooks/percona_utils.py 2015-10-10 16:07:05 +0000
101+++ hooks/percona_utils.py 2015-12-03 13:33:30 +0000
102@@ -6,9 +6,12 @@
103 import os
104 import shutil
105 import uuid
106+import pwd
107+import grp
108
109 from charmhelpers.core.host import (
110- lsb_release
111+ lsb_release,
112+ mkdir
113 )
114 from charmhelpers.core.hookenv import (
115 charm_dir,
116@@ -363,6 +366,25 @@
117 relation_set(relation_id=rid, **{'bootstrap-uuid': cluster_uuid})
118
119
120+def configure_binlogs_directory():
121+ # When this function is called before mysql is installed, we need to
122+ # create binlogs_path directory world-writable.
123+ # We need that directory as otherwise mysql won't start.
124+ binlogs_directory = os.path.dirname(config('binlogs-path'))
125+ if not os.path.isdir(binlogs_directory):
126+ mkdir(binlogs_directory, 'root', 'root', 0o777)
127+
128+ # This is called again after mysql has been installed (and from
129+ # config-changed hook, we need to set proper directory permissions
130+ try:
131+ uid = pwd.getpwnam('mysql').pw_uid
132+ gid = grp.getgrnam('mysql').gr_gid
133+ os.chown(binlogs_directory, uid, gid)
134+ os.chmod(binlogs_directory, 0o750)
135+ except KeyError:
136+ pass
137+
138+
139 def cluster_in_sync():
140 '''
141 Determines whether the current unit is in sync
142
143=== modified file 'templates/my.cnf'
144--- templates/my.cnf 2015-06-04 14:40:54 +0000
145+++ templates/my.cnf 2015-12-03 13:33:30 +0000
146@@ -25,6 +25,10 @@
147 # In order for Galera to work correctly binlog format should be ROW
148 binlog_format=ROW
149
150+{% if enable_binlogs -%}
151+log_bin={{ binlogs_path }}
152+{% endif -%}
153+
154 # MyISAM storage engine has only experimental support
155 default_storage_engine=InnoDB
156

Subscribers

People subscribed via source and target branches