galera_cluster_migrations 0.0.1.alpha1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +102 -2
- data/lib/galera_cluster_migrations.rb +2 -2
- data/lib/galera_cluster_migrations/capistrano.rb +0 -4
- data/lib/galera_cluster_migrations/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bc341370d48d39e1ebca83c4d827958921b7111
|
4
|
+
data.tar.gz: 48a1e9f27c5d19d359652db69647a62a0416565c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba9b5b5cb6fc36e458280263a296fa242575039c9d9e8f2d35f2c70086af4d5b01ba5a92379be8e4de65fc3515ec46d6ba7d7b6a7c5cd0e349a59e4fc169e060
|
7
|
+
data.tar.gz: 9ff4efb41bedd16edba5bd8c5feda733aa8a18fdacd982cf69f40a52e3bc74fd65744fff874d09b90565889b2730509c0fac18666e910cc38abb05939276c13d
|
data/README.md
CHANGED
@@ -1,6 +1,47 @@
|
|
1
1
|
# GaleraClusterMigrations
|
2
2
|
|
3
|
-
|
3
|
+
GaleraClusterMigrations helps to alleviate some of the woes of executing Rails
|
4
|
+
database migrations with [Galera Cluster](http://galeracluster.com). Galera
|
5
|
+
Cluster provides two options for executing DDL (Data Definition Language)
|
6
|
+
statements: Total Order Isolation (TOI) and Rolling Schema Upgrade (RSU).
|
7
|
+
Each has its advantages and disadvantages, but once your database reaches a
|
8
|
+
certain size you must start considering RSU for modifications on large tables.
|
9
|
+
|
10
|
+
## Total Order Isolation (TOI)
|
11
|
+
|
12
|
+
TOI is the default DDL replication method in Galera Cluster. When the master
|
13
|
+
node receives a DDL statement it sends out a replication event before starting
|
14
|
+
the DDL processing. Every node in the cluster will processs the replicated DDL
|
15
|
+
statement during the same "slot" in the cluster transaction stream. This
|
16
|
+
ensures that every node in the cluster will process the schema change at the
|
17
|
+
same time.
|
18
|
+
|
19
|
+
With this guarantee you don't have to worry about schema backwards
|
20
|
+
compatibility, but there are some drawbacks. The strict commit order will make
|
21
|
+
every transaction wait until DDL processing is over. Meaning that altering a
|
22
|
+
table will block any queries that are trying to access that table. For a table
|
23
|
+
with a large number or rows, altering a table or adding an index could take
|
24
|
+
several minutes, or longer, during which the table cannot be queried.
|
25
|
+
|
26
|
+
## Rolling Schema Upgrade (RSU)
|
27
|
+
|
28
|
+
To allow the rest of the cluster to continue operating at full speed Galera
|
29
|
+
Cluster offers the RSU method for DDL statements. During RSU the node executing
|
30
|
+
a DDL statement is desynchronized from replication for the duration of the DDL
|
31
|
+
processing. All incoming replication events are buffered and the node will not
|
32
|
+
send replication events to the other nodes in the cluster. When DDL processing
|
33
|
+
is over, the node will automatically join back into the cluster and process
|
34
|
+
missed transactions from the buffer. Once the node has rejoined and caught up
|
35
|
+
with the rest of the cluster, you must repeat the DDL statements on the next
|
36
|
+
node in the cluster.
|
37
|
+
|
38
|
+
The RSU method will not slow down the cluster; all other transactions can
|
39
|
+
complete at full speed on the two synced nodes. However, there are caveats that
|
40
|
+
must be considered when using RSU. The entire session will be processed with
|
41
|
+
RSU (i.e. any insert statements will not be replicated to the other nodes).
|
42
|
+
Second, upgrading the schema on all nodes is a manual operation. As a result
|
43
|
+
the schema changes must be backward compatible since queries will be processed
|
44
|
+
against and replicated to upgraded and non-upgraded nodes.
|
4
45
|
|
5
46
|
## Installation
|
6
47
|
|
@@ -18,7 +59,66 @@ Or install it yourself as:
|
|
18
59
|
|
19
60
|
## Usage
|
20
61
|
|
21
|
-
|
62
|
+
GaleraClusterMigrations contains 3 components:
|
63
|
+
|
64
|
+
1. An ActiveSupport concern that should be included in your database migrations,
|
65
|
+
2. A rake task for performing database migrations on a single cluster node,
|
66
|
+
3. And a capistrano task for remotely executing the rake task.
|
67
|
+
|
68
|
+
### To Use RSU within a Migration
|
69
|
+
|
70
|
+
The `GaleraClusterMigrations` ActiveSupport concern contains methods to enable
|
71
|
+
RSU and TOI. The `#with_rsu` method is the recommended way to run migrations
|
72
|
+
with RSU. It accepts a block and will enable RSU for the duration of the block
|
73
|
+
and then re-enable TOI.
|
74
|
+
|
75
|
+
The first step is to include the `GaleraClusterMigrations` module in your
|
76
|
+
migration and use the `#with_rsu` method to enable RSU for DDL statements
|
77
|
+
specified inside a block:
|
78
|
+
|
79
|
+
# db/migrate/20140710000000_add_foo_to_bars.rb
|
80
|
+
class AddFooToBars < ActiveRecord::Migration
|
81
|
+
include GaleraClusterMigrations
|
82
|
+
|
83
|
+
def change
|
84
|
+
with_rsu do
|
85
|
+
add_column :bars, :foo, :integer, default: 0
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
The `add_column` statement above will be executed in RSU mode when the migration
|
91
|
+
is run.
|
92
|
+
|
93
|
+
If you are using Capistrano, require `galera_cluster_migrations/capistrano` in
|
94
|
+
your `config/deploy.rb` file and use the `galera:migrate` task to run the
|
95
|
+
migration on each node:
|
96
|
+
|
97
|
+
# config/deploy.rb
|
98
|
+
...
|
99
|
+
require 'galera_cluster_migrations/capistrano'
|
100
|
+
...
|
101
|
+
|
102
|
+
You should also disable the default `deploy:migrate` task from running during
|
103
|
+
a deploy. Once the migration has been deployed to your cluster, execute the
|
104
|
+
migration on each node checking that the entire cluster is in the *Synced*
|
105
|
+
state before proceeding with the next node. Be sure to use the `HOSTFILTER`
|
106
|
+
option to specify a single node to migrate at a time.
|
107
|
+
|
108
|
+
$ cap production galera:migrate HOSTFILTER=db1.example.com
|
109
|
+
# check that db1 has rejoined the cluster and is Synced
|
110
|
+
$ cap production galera:migrate HOSTFILTER=db2.example.com
|
111
|
+
# check that db2 has rejoined the cluster and is Synced
|
112
|
+
$ cap production galera:migrate HOSTFILTER=db3.example.com
|
113
|
+
# check that db3 has rejoined the cluster and is Synced
|
114
|
+
|
115
|
+
You have now successfully upgraded the schema on every database node using
|
116
|
+
RSU! During this time the two nodes not processing the migration will be
|
117
|
+
available to process queries at full speed.
|
118
|
+
|
119
|
+
For migrations that you want to run using TOI there is nothing special required
|
120
|
+
to migrate the database. Write the database migration as you normally would and
|
121
|
+
migrate the database with `cap production deploy:migrate`.
|
22
122
|
|
23
123
|
## Contributing
|
24
124
|
|
@@ -7,7 +7,7 @@ module GaleraClusterMigrations
|
|
7
7
|
require 'galera_cluster_migrations/railtie' if defined?(Rails)
|
8
8
|
|
9
9
|
included do
|
10
|
-
def
|
10
|
+
def enable_rsu
|
11
11
|
say "Setting wsrep_OSU_method to RSU"
|
12
12
|
unless [:development, :test].include?(Rails.env)
|
13
13
|
execute "SET GLOBAL wsrep_OSU_method=RSU"
|
@@ -29,7 +29,7 @@ module GaleraClusterMigrations
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def enable_toi
|
33
33
|
say "Setting wsrep_OSU_method to TOI"
|
34
34
|
unless [:development, :test].include?(Rails.env)
|
35
35
|
execute "SET GLOBAL wsrep_OSU_method=TOI"
|
@@ -9,10 +9,6 @@ module GaleraClusterMigrations
|
|
9
9
|
def self.load_into(capistrano_config)
|
10
10
|
capistrano_config.load do
|
11
11
|
|
12
|
-
before(Capistrano::TASKS) do
|
13
|
-
Config.load(self)
|
14
|
-
end
|
15
|
-
|
16
12
|
namespace :galera do
|
17
13
|
desc <<-DESC
|
18
14
|
Run the migrate rake task. By default, it runs this in most recently \
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: galera_cluster_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Traywick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -99,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - '
|
102
|
+
- - '>='
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
107
|
rubygems_version: 2.2.2
|