Setting Up Master-Slave Replication Automatically

To set up master-slave replication automatically, run the maprcli command table replica autosetup command, which performs these steps.

Behavior of the maprcli command table replica autosetup

  1. Creates a table on the replication cluster. This table has the same column families as the source table.
  2. Declares the new table to be a replica of the source table.
  3. Declares the source table as an upstream source for the replica.
  4. Loads a copy of the source data into the replica.
  5. Starts replication.

Prerequisites

  • Configure one or more gateways in the destination cluster. See Configuring and Managing MapR Gateways.
  • If the source and destination clusters are both secured, set up security for replication between the clusters. See Configuring MapR Clusters for Replication Between Tables.
  • Run the maprcli table info command on the source table to verify that you have the following permissions:
    • readperm, which is required for reading from the table.
    • replperm, which is required for replicating from the table.
  • Run the maprcli table info command on the destination table (if it already exists) to verify that you have the following permissions:
    • bulkload, which is required for the initial copy of source data into the destination table.
    • replperm, which is required for receiving replicated updates from the source table.

Running the command

Here is the syntax of the command:
maprcli table replica autosetup -path <path to source table> -replica  <path to replica> 
For example, to set up replication from the customers table in the sanfrancisco cluster to a new customers table in the newyork cluster, you could use this command:
maprcli table replica autosetup -path /mapr/sanfrancisco/customers -replica /mapr/newyork/customers
To set up replication from the customersA table in the sanfrancisco cluster to a new customersB table in the same cluster, you could use this command:
maprcli table replica autosetup -path /mapr/sanfrancisco/customersA -replica /mapr/sanfrancisco/customersB
You can use these optional parameters in this command:
-columns
For binary tables
Provide a comma-separated list of column families or columns from a certain column family (column family:qualifier). For example, use the following syntax to replicate the column family purchases and the column stars in the reviews column family: -columns purchases,reviews:stars
Note: While the column families that you specify must already exist in the source table, the columns that you specify do not have to exist in the destination table for replication to succeed. If the column is added at a later date, replication for that column will start at that time.
For JSON tables
Provide a comma-delimited list of fields to replicate. Include the full field path for each field.

Example

Suppose your table contains documents that contain this general structure:

{
     "_id" : "ID",
     "a" :
          {
               "b" : 
                    {
                         "c" : "value",
                    },
               "e" : "value"
          }
}

To replicate fields a, c, and e, you would specify these field paths:

a,a.b.c,a.e
Do not use quotation marks and do not include spaces after commas.

Suppose now that a.b and a.e were custom column families. You want to replicate only the default column family and column family a.e. To do so, you would specify field paths like this:

",a.e"

The empty string before the comma indicates the default column family.

-synchronous
This parameter specifies whether replication is synchronous or asynchronous. Asynchronous is the default. The values are yes for synchronous and no for asynchronous.

What to do next

  • Be aware that changes to the structure of a source table are not replicated automatically to replicas. For example, if a new column family is added to the source table and the entire table is being replicated (i.e. the maprcli table replica add command did not specify column families or columns to replicate), the new column family is not automatically created at the replica.

    You can add the new column family to the replica only if the entire source table is being replicated, then updates to the new column family will immediately start being replicated. You do not need to carry out the next steps. Continue only if you are replicating a subset of column families and columns.

    If you are replicating a subset of column families and columns, follow these steps to add a new column family to the replica:
    1. Pause replication by running the maprcli table replica pause command.
    2. Add the new column family to the replica by running the maprcli table replica edit command.
    3. Copy the data for this column family from the source table into the replica by using the MapR-DB CopyTable utility. Use the -columns parameter to specify the name of the column family.
    4. Resume replication by running the maprcli table replica resume command.
  • Check for alarms related to replication and whether synchronous replication is switched temporarily to asynchronous replication by looking in MCS. See Table-Replication Alarms.