~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/slave/docs/user_example.rst

  • Committer: Lee Bieber
  • Date: 2011-03-29 22:31:41 UTC
  • mfrom: (2257.1.3 build)
  • Revision ID: kalebral@gmail.com-20110329223141-yxc22h3l2he58sk0
Merge Andrew - 743842: Build failure using GCC 4.6
Merge Stewart - 738022: CachedDirectory silently fails to add entries if stat() fails
Merge Olaf - Common fwd: add copyright, add more declaration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
How to use replication: An example
 
2
====================================
 
3
 
 
4
Simple replication setup (using a single master and a single slave) between two Drizzle servers is straightforward with the replication slave plugin. With Drizzle replication, you can also provision a new slave into an existing setup.
 
5
 
 
6
Replication setup begins with making certain that both master and slave share the same version of Drizzle to avoid any potential incompatibility issues.
 
7
 
 
8
Master Setup
 
9
-------------
 
10
 
 
11
Setting up the master is the first step. An important requirement is to start the master Drizzle database server with the --innodb.replication-log option. For example:
 
12
 
 
13
    master> sbin/drizzled --datadir=$PWD/var --innodb.replication-log &
 
14
 
 
15
 
 
16
For more complex setups, the --server-id option may be appropriate to use.
 
17
 
 
18
With the master running, you can optionally now create a backup of any databases to be imported on the new slave by using :doc:`../../clients/drizzledump`. This example, however, assumes that we are starting with a fresh database with no data.
 
19
 
 
20
Slave Setup
 
21
-------------
 
22
 
 
23
Starting the slave is almost as simple as starting the master. There are two Drizzle database server options required for the slave: --plugin-add=slave and --slave.config-file. For example: ::
 
24
 
 
25
        slave> sbin/drizzled --datadir=$PWD/var \
 
26
                                    --plugin-add=slave \
 
27
                                    --slave.config-file=/tmp/slave.cfg &
 
28
 
 
29
 
 
30
These options tell the server to load the slave plugin, and then tell the slave plugin where to find the slave host configuration file. This configuration file has options to specify the master host and a few options to control how the slave operates. You can read more about the available configuration options in the replication slave plugin documentation. Below is a simple example: ::
 
31
 
 
32
        master-host = dino
 
33
        master-port = 3306
 
34
        master-user = dino_slave
 
35
        master-pass = my_password
 
36
        io-thread-sleep = 10
 
37
        applier-thread-sleep = 10
 
38
 
 
39
The slave will immediately connect to the master host specified in the configuration file and begin pulling events from the InnoDB-based transaction log. By default, a freshly provisioned slave will begin pulling from the beginning of this transaction log. Once all replication messages have been pulled from the master and stored locally on the slave host, the IO thread will sleep and periodically awaken to check for more messages. This is straightforward for an initial replication setup. See below to learn about inserting another slave host into an already existing replication architecture.
 
40
 
 
41
Provisioning a New Slave Host
 
42
-------------------------------
 
43
 
 
44
The basic formula for creating a new slave host for an existing replication setup is:
 
45
 
 
46
   1. Make a backup of the master databases.
 
47
   2. Record the state of the master transaction log at the point the backup was made.
 
48
   3. Restore the backup on the new slave machine.
 
49
   4. Start the new slave and tell it to begin reading the transaction log from the point recorded in #2.
 
50
 
 
51
Steps #1 and #2 are covered with the drizzledump client program. If you use the --single-transaction option to drizzledump, it will place a comment near the beginning of the dump output with the InnoDB transaction log metadata. For example: ::
 
52
 
 
53
        master> drizzledump --all-databases --single-transaction > master.backup
 
54
        master> head -1 master.backup
 
55
        -- SYS_REPLICATION_LOG: COMMIT_ID = 33426, ID = 35074
 
56
 
 
57
The SYS_REPLICATION_LOG line provides the replication log metadata needed when starting a new slave. It has two pieces of information:
 
58
 
 
59
* **COMMIT_ID**:  This value is the commit sequence number recorded for the most recently executed transaction stored in the transaction log. We can use this value to determine proper commit order within the log. The unique transaction ID cannot be used since that value is assigned when the transaction is started, not when it is committed.
 
60
* **ID**:  This is the unique transaction identifier associated with the most recently executed transaction stored in the transaction log.
 
61
 
 
62
Next, steps #3 and #4 must be completed to start the new slave. First, you must start the slave WITHOUT the replication slave plugin enabled, to prevent it from reading from the master until the backup is imported. To start it without the plugin enabled, import your backup, then shutdown the server: ::
 
63
 
 
64
        slave> sbin/drizzled --datadir=$PWD/var &
 
65
        slave> drizzle < master.backup
 
66
        slave> drizzle --shutdown
 
67
 
 
68
Now that the backup is imported, restart the slave with the replication slave plugin enabled and use a new option, --slave.max-commit-id, to force the slave to begin reading the master's transaction log at the proper location:
 
69
 
 
70
        slave> sbin/drizzled --datadir=$PWD/var \
 
71
                                    --plugin-add=slave \
 
72
                                    --slave.config-file=/tmp/slave.cfg \
 
73
                                    --slave.max-commit-id=33426 &
 
74
 
 
75
 
 
76
We give the --slave.max-commit-id the value from the comment in the master dump file, which defines the maximum COMMIT_ID value (the latest transaction) represented by the slave's contents.
 
77
 
 
78
This is the full cycle for a simple replication example. Please see the other Drizzle slave plugin docs for more information on replication and configuration options.