GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing docs.voltdb.com — 11.3. Using Cross Datacenter Replication Documentation11.3. Using Cross Datacenter ReplicationThe following sections provide step-by-step instructions for setting up and running cross datacenter replication (XDCR) between two VoltDB clusters. The sections describe how to:
Later sections discuss other aspects of managing XDCR, including:
ImportantXDCR is a separately licensed feature. If your current VoltDB license does not include a key for XDCR you will not be able to complete the tasks described in this section. See your VoltDB sales representative for more information on licensing XDCR. 11.3.1. Designing Your Schema for Active ReplicationIf you plan to use XDCR or active DR, you need to design your database schema appropriately. Specifically you must:
11.3.1.1. Enabling Active Replication in the SchemaTo manage XDCR, VoltDB stores a small amount (8 bytes) of extra metadata with every row of data that is shared. To allocate this additional space, you must tell VoltDB you will be using active DR. You do this with the SET DR=ACTIVE statement in your schema: SET DR=ACTIVE; You must execute the SET DR=ACTIVE before there is any data in the tables that will be replicated. Consequently, it is easiest to include it at the beginning of your schema. However, it can be executed at any time — even after one or more tables are declared as DR tables with the DR TABLE statement — as long as the DR tables are empty. 11.3.1.2. Identifying the DR Tables in the SchemaNext, you must identify which tables you wish to share between the two databases. Only the selected tables are copied. You identify the tables in the schema for both databases with the DR TABLE statement. For example, the following statements identify two tables to be replicated, the Customers and Orders tables: SET DR=ACTIVE;
CREATE TABLE customers (
customerID INTEGER NOT NULL,
firstname VARCHAR(128),
LASTNAME varchar(128)
);
CREATE TABLE orders (
orderID INTEGER NOT NULL,
customerID INTEGER NOT NULL,
placed TIMESTAMP
);
DR TABLE customers;
DR TABLE orders;You can identify any regular table, whether partitioned or not, as a DR table, as long as the table is empty. That is, the table must have no data in it when you issue the DR TABLE statement. The important point to remember is that the schema definitions for the tables participating in DR, including the DR TABLE statements, must be identical on the two clusters. 11.3.2. Configuring the Database ClustersThe next step is to configure and initialize the database root directories. The two database clusters can have different physical configurations (that is, different numbers of nodes, different sites per host, or a different K factor). Identical cluster configurations guarantee the most efficient replication, because the databases do not need to repartition the incoming binary logs. Differing configurations, on the other hand, may incrementally increase the time needed to apply the binary logs. When initializing the database root directories, you must also enable and configure DR in the configuration file, including:
11.3.2.1. Choosing Unique IDsYou enable DR in the configuration file using the To manage the DR process VoltDB needs to uniquely identify the clusters. You provide this unique identifier as a
number between 0 and 127 when you configure the clusters. For example, if we assign ID=1 to a cluster in New York and
ID=2 to another in Chicago, their respective configuration files must contain the following New York Cluster <dr id="1" /> Chicago Cluster <dr id="2" /> 11.3.2.2. Identifying the DR ConnectionsFor each database cluster, you must also the specify the source of replication in the For example, say the New York cluster has nodes NYserverA, NYserverB, and NYserverC. While the Chicago cluster has CHIserverX, CHIserverY, and CHIserverZ. The configuration files for the two clusters might look like this: New York Cluster <dr id="1">
<connection source="CHIserverX,CHIserverY" />
</dr>Chicago Cluster <dr id="2">
<connection source="NYserverA,NYserverB,NYserverC" />
</dr>Note that both clusters must have a connection defined for active replication to start. Once the configuration files have the necessary declarations, you can initialize the root directories on all cluster nodes using the appropriate configuration files: New York Cluster $ voltdb init -D ~/nydb --config=nyconfig.xml Chicago Cluster $ voltdb init -D ~/chidb --config=chiconfig.xml 11.3.3. Starting the Database ClustersOnce the servers are initialized with the necessary configuration, you can start the database clusters. However, it is important to note that as soon as both databases start, they will attempt to contact each other, verify that the DR table schema match, and then start the DR process. Often the easiest method for starting the databases is to:
Using this approach, DR will not start until step #3 is complete and both clusters are fully configured. An alternative approach is to initialize both databases leaving the source attribute of the <connection> element empty. For example: <dr id="2">
<connection source="" />
</dr>You can then start and load the schema on both databases and perform any other preparatory work you require. Then edit the configuration files filling in the source attribute for each cluster to point at the other. Then use the voltadmin update command to update the configuration on the running databases. As soon as the source attribute is defined and the schema match, the DR process will begin. NoteAlthough the source attribute can be modified on a running database, the unique cluster ID cannot be changed after the database starts. So it is important to include the <dr> element with the unique ID when initializing the database root directories. 11.3.4. Loading a Matching Schema and Starting ReplicationAs soon as the databases start with DR enabled, they will attempt to contact the cooperating database to start replication. Each cluster will issue warnings until the schema for both databases match. This is normal and gives you time to load a matching schema. The key point is that once matching schema are loaded on both databases, replication will begin automatically. When replication starts, the following actions occur:
If any errors occur during the snapshot transmission, replication stops and must be restarted from the beginning. However, once the third step is reached, replication proceeds independently for each unique partition and, in a K safe environment, the DR process becomes durable across node failures and rejoins as well as cluster shutdowns and restarts. 11.3.5. Updating the Schema During Active ReplicationSQL statements such as DELETE, INSERT, and UPDATE are transmitted through the DR binary logs, but schema changes are not. So you must be careful to only make changes to the schema of DR tables while the XDCR clusters are paused and quiesced. If not, a schema change to one cluster will likely break replication. The process for changing the schema for DR tables in XDCR is the following:
11.3.6. Stopping ReplicationIf, for any reason, you need to break replication between the two databases, all you need to do is issue the voltadmin dr reset command to either cluster. For example, if one cluster goes down and will not be brought back online for an extended period, you will want to issue a voltadmin dr reset command on the remaining cluster to tell it to stop queuing binary logs. If not, the logs will be saved on disk, waiting for the other cluster to return, until you run out of disk space. For similar reasons, if you break replication while both databases are running, you should issue the voltadmin dr reset command to both clusters. Although using dr reset on one cluster is sufficient to break the DR process, the cluster that does not receive the reset command will continue to queue binary logs until it, too, is reset. 11.3.7. Understanding Conflict ResolutionOne aspect of database replication that is unique to cross datacenter replication (XDCR) is the need to prepare for and manage conflicts between the two databases. Conflict resolution is not an issue for passive replication since changes travel in only one direction. However, with XDCR it is possible for changes to be made to the same data at approximately the same time on the two databases. Those changes are then sent to the other database, resulting in possible inconsistencies or invalid transactions. For example, say clusters A and B are processing transactions as shown in Figure 11.6, “Transaction Order and Conflict Resolution”. Cluster A executes a transaction that modifies a specific record and this transaction is included in the binary log A1. By the time cluster B receives the binary log and processes A1, cluster B has already processed its own transactions B1 and B2. Those transactions may have modified the same record as the transaction in A1, or another record that would conflict with the change in A1, such as a matching unique index entry. Figure 11.6. Transaction Order and Conflict Resolution ![]() Under these conditions, cluster B cannot simply apply the changes in A1 because doing so could violate the uniqueness constraints of the schema and, more importantly, is likely to result in the content of the two database clusters diverging. Instead, cluster B must decide which change takes priority. That is, what resolution to the conflict is most likely to produce meaningful results or match the intent of the business application. This decision making process is called conflict resolution. No matter what the resolution, it is important that the database administrators are notified of the conflict, why it occurred, and what action was taken. The following sections explain:
11.3.7.1. Designing Your Application to Avoid ConflictsVoltDB uses well-defined rules for resolving conflicts. However, the best protection against conflicts and the problems they can cause is to design your application to avoid conflicts in the first place. There are at least two things you can do in your client applications to avoid conflicts:
11.3.7.2. How Conflicts are ResolvedEven with the best application design possible, errors in program logic or operation may occur that result in conflicting records being written to the two databases. When a conflict does occur, VoltDB follows specific rules for resolving the issue. The conflict resolution rules are:
Let's look at a simple example to see how these rules work. Assume that the database stores user records, using a numeric user ID as the primary key and containing columns for the user's name and password. A user logs on simultaneously in two locations and performs two separate updates: one on cluster A changing their name and one on cluster B changing the password. These updates are almost simultaneous. However, cluster A timestamps its transaction as occurring at 10:15.00.003 and cluster B timestamps its transaction at 10:15.00.001. The binary logs from the two transactions include the type of action, the contents of the record before and after the change, and the timestamps — both of the last previous transaction and the timestamp of the new transaction. (Note that the timestamp includes both the time and the cluster ID where the transaction occurred.) So the two binary logs might look like the following. Binary Log A1:
Binary Log B1:
When the binary log A1 arrives at cluster B, the DR process performs the following steps:
Note that when the UPDATE from A1 is applied, the change to the password in B1 is overwritten and the password is reset to "abalone". Which at first looks like a problem. However, when the binary log B1 arrives at cluster A, the same steps are followed. But when cluster A reaches steps #4 and 5, it finds that the new timestamp from B1 is older than the current timestamp, and so the action is rejected and the record is left unchanged. As a result both databases end up with the same value for the record. Essentially, the password change is dropped. If the transaction on cluster B had been to delete the user record rather than change the password, then the outcome would be different, but still consistent. In that case, when binary log A1 reaches cluster B, it would not be able to find the matching record in step #1. This is recognized as a DELETE action having occurred. Since DELETE always wins, the incoming UPDATE is rejected. Similarly, when binary log B1 reaches cluster A, the previous timestamps do not match but, even though the incoming action in B1 has an older timestamp than the UPDATE action in A1, B1 "wins" because it is a delete action and the record is deleted from cluster A. Again, the result is consistent across the two databases. The real problem with conflicts is when there is no primary key on the database table. Primary keys uniquely identify a record. Without a primary key, there is no way for VoltDB to tell, even if there are one or more unique indexes on the table, whether two records are the same record modified or two different records with the same unique key values. As a result, if there is a conflict between two transactions without a primary key, VoltDB has no way to resolve the conflict and simply rejects the incoming action. Going back to our example, if the user table had a unique index on the user ID rather than a primary key, and both cluster A and cluster B update the user record at approximately the same time, when binary log A1 arrives at cluster B, it would look for the record based on all columns in the record and fail to find a match. However, when it attempts to insert the record, it will encounter a constraint violation on the unique index. Again, since there is no primary key, VoltDB cannot resolve the conflict and rejects the incoming action, leaving the record with the changed password. On cluster A, the same process occurs and the password change in B1 gets rejected, leaving cluster A with a changed name column and database B with a changed password column — the databases diverge. 11.3.7.3. What Types of Conflict Can OccurThe preceding section uses a simple case of conflicting UPDATE transactions to illustrate the steps involved in conflict resolution. However, there are several different types of conflict that can occur. First, there are three possible actions that the binary log can contain: INSERT, UPDATE, or DELETE. There are also three types of conflicts that can be generated:
A missing row means that the binary log contains an UPDATE or DELETE action, but the affected row cannot be found in the consumer database. (A missing row conflict cannot occur for INSERT actions, since INSERT assumes no such row exists.) In the case of a missing row conflict, VoltDB assumes a DELETE action has removed the affected row. Since the rule is that DELETE wins, this means the incoming action is rejected. Note that if the table does not have a primary key, the assumption that a DELETE action removed the row is not guaranteed to be true, since it is possible an UPDATE changed the row. Without a primary key, there is no way for the DR process to find the matching row when some columns may have changed, so it assumes it was deleted. As a result, an UPDATE could occur on one cluster and a DELETE on the other. This is why assigning primary keys is recommended for DR tables when using XDCR. If the matching primary key is found, it is still possible that the contents of the row have been changed. In which case, the timestamps will not match and a timestamp mismatch conflict occurs. Again, this can happen for UPDATE and DELETE actions where an existing row is being modified. If the incoming action is a DELETE, it takes precedence and the row is deleted. If not, if the incoming action has the later of the two timestamps, it is accepted. If the existing record has the later timestamp, the incoming action is rejected. Finally, whether the timestamps match or not, with an INSERT or UPDATE action, it is possible that applying the action would violate one of more unique index constraints. This can happen because another row has been updated with matching values for the unique index or another record has been inserted with similar values. Whatever the cause, VoltDB cannot apply the incoming action so it is rejected. Note that for a single action there can be more than one unique index that applies to the table, so there can be multiple constraint violations as well as a possible incorrect timestamp. When a conflict occurs, all conflicts associated with the action are included in the conflict log. To summarize, the following chart shows the conflicts that can occur with each type of action and the result for tables with a primary key.
11.3.7.4. Reporting ConflictsVoltDB makes a record of every conflict that occurs when processing the DR binary logs. These conflict logs include:
By default, these logs are written as comma-separated value (CSV) files on the cluster where the conflicts occur.
These files are usually written to a subfolder of the voltdbroot directory
( The DR process writes the conflicts as export data to the export stream VOLTDB_XDCR_CONFLICTS. You do not need to explicitly configure export — the DR process automatically declares the necessary export tables, establishes a default export configuration for the file connector, and enables the export stream. However, if you want the data to be sent to a different location or using a different export connector, you can do this by configuring the export stream yourself. For example, if you want to export the XDCR conflicts to a Kafka stream where they can be used for automatic notifications, you can change the export properties in the configuration file. The following configuration file code writes the conflict logs to the Kafka topic sysops on the broker kafkabroker.mycompany.com: <export>
<configuration enabled="true" type="kafka"
stream="VOLTDB_XDCR_CONFLICTS">
<property name="broker">kafkabroker.mycompany.com</property>
<property name="topic">sysops</property>
</configuration>
</export>Each action in the binary log can generate one or more conflicts. When this occurs, VoltDB logs the conflict(s) as multiple rows in the conflict report. Each row is identified by the type of action (INSERT, UPDATE, DELETE) as well as the type of information the row contains:
For an INSERT action, there is no EXPECTED row. For either an INSERT or an UPDATE action there is no DELETE row. And for a DELETE action there is no NEW row. The order of the rows in the report is as follows:
Table 11.1, “Structure of the XDCR Conflict Logs” describes the structure and content of the conflict log records in the export stream. Table 11.1. Structure of the XDCR Conflict Logs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||