theworkinggroup-mysql-replication-helper 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +21 -1
- data/Rakefile +4 -4
- data/VERSION.yml +2 -2
- data/bin/replication-helper +25 -0
- data/lib/mysql_replication_helper.rb +3 -0
- data/lib/mysql_replication_helper/error_handler.rb +7 -6
- data/test/mysql_replication_helper/error_handler_test.rb +11 -3
- metadata +8 -9
- data/LICENSE +0 -20
data/README.rdoc
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
= mysql-replication-helper
|
2
2
|
|
3
|
-
|
3
|
+
This is a script that mitigates the errors generated by a Master/Slave MySQL
|
4
|
+
replication configuration.
|
5
|
+
|
6
|
+
A slave database engine needs to be updated in tandem with the master to
|
7
|
+
account for changes such as:
|
8
|
+
|
9
|
+
* Adding a new database
|
10
|
+
* Adding a new user
|
11
|
+
* Adding views which reference particular users
|
12
|
+
|
13
|
+
The replication helper facilitates this by identifying typical errors and
|
14
|
+
fixing them.
|
15
|
+
|
16
|
+
== Installing
|
17
|
+
|
18
|
+
% gem sources -a http://gems.github.com
|
19
|
+
% sudo gem install theworkinggroup-mysql-replication-helper
|
20
|
+
|
21
|
+
== Starting
|
22
|
+
|
23
|
+
% replication-helper --daemon
|
4
24
|
|
5
25
|
== Copyright
|
6
26
|
|
data/Rakefile
CHANGED
@@ -7,8 +7,10 @@ begin
|
|
7
7
|
gem.name = "mysql-replication-helper"
|
8
8
|
gem.summary = %Q{MySQL Replication Helper}
|
9
9
|
gem.email = "github@tadman.ca"
|
10
|
-
gem.homepage = "http://github.com/
|
11
|
-
gem.authors = [
|
10
|
+
gem.homepage = "http://github.com/theworkinggroup/mysql-replication-helper"
|
11
|
+
gem.authors = [ 'Scott Tadman' ]
|
12
|
+
gem.executables = %w[ replication-helper ]
|
13
|
+
gem.add_dependency 'daemons'
|
12
14
|
|
13
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
16
|
end
|
@@ -36,7 +38,6 @@ rescue LoadError
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
41
|
task :default => :test
|
41
42
|
|
42
43
|
require 'rake/rdoctask'
|
@@ -53,4 +54,3 @@ Rake::RDocTask.new do |rdoc|
|
|
53
54
|
rdoc.rdoc_files.include('README*')
|
54
55
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
56
|
end
|
56
|
-
|
data/VERSION.yml
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# replication-helper MySQL replication helper agent
|
4
|
+
#
|
5
|
+
# chkconfig: - 65 34
|
6
|
+
# description: MySQL replication helper agent
|
7
|
+
# processname: replication-helper
|
8
|
+
# config: /etc/replication-helper.conf
|
9
|
+
# pidfile: /var/run/replication-helper.pid
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'daemons'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
|
17
|
+
require 'mysql_replication_helper'
|
18
|
+
|
19
|
+
daemon_script_path = File.expand_path('../lib/mysql_replication_helper/daemon_launcher.rb', File.dirname(__FILE__))
|
20
|
+
|
21
|
+
if (!File.exist?(daemon_script_path))
|
22
|
+
daemon_script_path = Gem.required_location('mysql_replication_helper','mysql_replication_helper/daemon_launcher.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
Daemons.run(daemon_script_path)
|
@@ -1,9 +1,5 @@
|
|
1
1
|
module MysqlReplicationHelper
|
2
|
-
|
3
|
-
def initialize(options = nil)
|
4
|
-
@options = options || { }
|
5
|
-
end
|
6
|
-
|
2
|
+
module ErrorHandler
|
7
3
|
def sql_to_recover_from(error)
|
8
4
|
case (error)
|
9
5
|
when /^Error 'Unknown database '([^\']+)'' on query/
|
@@ -17,7 +13,12 @@ module MysqlReplicationHelper
|
|
17
13
|
"GRANT ALL PRIVILEGES ON `#{$3}`.* TO `#{$1}`@`#{$2}`",
|
18
14
|
"START SLAVE"
|
19
15
|
]
|
16
|
+
when /^Error 'View '[^\']+' references invalid table\(s\) or column\(s\) or function\(s\) or definer\/invoker of view lack rights to use them' on query. Default database: '([^\']+)'. Query: 'CREATE .*? DEFINER=`([^\`]+)`@`([^\`]+)`/
|
17
|
+
[
|
18
|
+
"GRANT ALL PRIVILEGES ON `#{$1}`.* TO `#{$2}`@`#{$3}`",
|
19
|
+
"START SLAVE"
|
20
|
+
]
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
23
|
-
end
|
24
|
+
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
2
|
|
3
|
+
class TestHandler
|
4
|
+
include MysqlReplicationHelper::ErrorHandler
|
5
|
+
end
|
6
|
+
|
3
7
|
class MysqlReplicationHelper::ErrorHandlerTest < Test::Unit::TestCase
|
4
8
|
def test_responses
|
5
|
-
handler =
|
9
|
+
handler = TestHandler.new
|
6
10
|
|
7
11
|
[
|
8
12
|
[
|
@@ -10,8 +14,12 @@ class MysqlReplicationHelper::ErrorHandlerTest < Test::Unit::TestCase
|
|
10
14
|
[ "CREATE DATABASE `example_db`", "START SLAVE" ]
|
11
15
|
],
|
12
16
|
[
|
13
|
-
"Error 'There is no '
|
14
|
-
[ "CREATE USER `
|
17
|
+
"Error 'There is no 'example_user'@'example_host' registered' on query. Default database: 'example_db'.",
|
18
|
+
[ "CREATE USER `example_user`@`example_host`", "GRANT ALL PRIVILEGES ON `example_db`.* TO `example_user`@`example_host`", "START SLAVE" ]
|
19
|
+
],
|
20
|
+
[
|
21
|
+
"Error 'View 'example_db.example_table' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them' on query. Default database: 'example_db'. Query: 'CREATE ALGORITHM=UNDEFINED DEFINER=`example_user`@`example_host` SQL SECURITY DEFINER VIEW",
|
22
|
+
[ "GRANT ALL PRIVILEGES ON `example_db`.* TO `example_user`@`example_host`", "START SLAVE" ]
|
15
23
|
]
|
16
24
|
].each do |test_case|
|
17
25
|
assert_equal test_case[1], handler.sql_to_recover_from(test_case[0])
|
metadata
CHANGED
@@ -1,39 +1,38 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: theworkinggroup-mysql-replication-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Scott Tadman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
13
|
-
default_executable:
|
12
|
+
date: 2009-04-24 00:00:00 -07:00
|
13
|
+
default_executable: replication-helper
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description:
|
17
17
|
email: github@tadman.ca
|
18
|
-
executables:
|
19
|
-
|
18
|
+
executables:
|
19
|
+
- replication-helper
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- LICENSE
|
24
23
|
- README.rdoc
|
25
24
|
files:
|
26
|
-
- LICENSE
|
27
25
|
- README.rdoc
|
28
26
|
- Rakefile
|
29
27
|
- VERSION.yml
|
28
|
+
- bin/replication-helper
|
30
29
|
- lib/mysql_replication_helper.rb
|
31
30
|
- lib/mysql_replication_helper/error_handler.rb
|
32
31
|
- test/mysql_replication_helper/error_handler_test.rb
|
33
32
|
- test/mysql_replication_helper_test.rb
|
34
33
|
- test/test_helper.rb
|
35
34
|
has_rdoc: true
|
36
|
-
homepage: http://github.com/
|
35
|
+
homepage: http://github.com/theworkinggroup/mysql-replication-helper
|
37
36
|
post_install_message:
|
38
37
|
rdoc_options:
|
39
38
|
- --charset=UTF-8
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 tadman
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|