OrientDB Multi-Master Replication

| November 27, 2014

orientdb_logo_2x11Because Jelastic PaaS implements the cartridges packaging model, the list of supported servers has been significantly extended. In addition to the ability to prepare a package with any desired stack (either based on the already existing OpenShift’s one or one originally created by yourself), there are a number of ready-to-use cartridge templates available within our Templates repository. They can be easily installed to the Jelastic Cloud by an administrator, and OrientDB is one of these.
OrientDB is the first multi-model open-source NoSQL distributed database system, which combines the power of graphs and the flexibility of documents in one scalable and high-performance operational solution. Working with OrientDB, you receive the numerous features and possibilities due to its integrated blend of graphs relational behaviour and document-type storage. And in order to benefit even more, you are able to gain the improved reliability of your data due to its Multi-Master replication support.
It’s well known that replication is a basic security solution for any database server, aimed to increase its failover capabilities. With OrientDB, you can easily create a secure cluster with several replicated database servers in it and, in such a way, reduce the risks of downtime or data loss, increase accessibility, get a high level of performance and product confidence.
In this instruction, we’ll show you how to configure the replication between two OrientDB servers, where all of the records inside the same-named databases are replicated. However, your DB cluster may include any desired amount of nodes - just adjust every one of them based on the steps below (as Multi-Master replication mode means that all servers in a cluster are equal and able to write/read records of each other).
So, let’s get started!

Create an Environment

1. Log in to your Jelastic account and Create a new environment with the corresponding button at the top left corner of your dashboard.
create environment
2. You’ll see the topology dialog window opened. Disable the automatically added application server (as you won’t need it for this tutorial) and pick the OrientDB server instead.

Note: OrientDB is an optional node since it is based on cartridge packaging model. If you can’t find this server in the NoSQL section of your wizard, send a request to your hosting provider for its addition.

Increase the amount of OrientDB nodes using the + button in the central Horizontal scaling pane. Then, state the resource usage limits for this server with the help of cloudlet sliders, specify the desired environment name (for example, orientdb), and click Create to continue.
orientdb multi nodes
3. Once your environment is successfully created and has appeared at your dashboard, you can proceed to the next chapter of this guide.
orientdb hosting

Database Configuration

Now let’s configure each of the nodes in your cluster in order to set up a replication between them.
1. Click the Config button for your database server.
config orientdb
2. In the appeared Configuration Manager tab, navigate to the hazelcast.xml file within the conf/config directory and edit the code in its group and network sections in the following way:
    <port auto-increment="false">{port}</port>
        <multicast enabled="false">
Note that you should substitute the values in the curly brackets with your data:

    • {custom_name} - an arbitrary name for your replication group (must be the same for every node, e.g. root)
    • {custom_password} - the desired password for your replication group (must be the same for every node, e.g. abc123)
    • {port} - any unoccupied port (e.g. 3000)

hazelcast orientdb
3. Then, add the tcp-ip code subsection to the same file just after the closing multicast tag inside the join section.
<tcp-ip enabled="true">

  • {node_ip} - IP addresses of the included to cluster nodes, which you would like the replication to be configured for
  • {port} - port number, the same as you’ve specified for the auto-increment parameter in the previous step (3000 in our case)
Note: The required IP addresses can be found by means of selecting the gear icon next to each of your database nodes.
database ip

orientdb tcp ip
4. In order to save your time and not repeat the same operations for every node, use the Save for all instances option from the Save drop-down list above the editor.
save configs orient
In such a way, the performed configuration changes will be applied to all the nodes in your DB cluster.
5. After that, switch to the default-distributed-db-config.json file, located in the same folder, and set the preferred names (e.g. nodeN) for all of your replicated nodes within the servers parameter, substituting the default <NEW_NODE> string.

Take into consideration the required value format: entered names should be enclosed in quotation marks and separated with comma.

"servers" : [ "node1", "node2" ]orientdb servers
6. Save for all instances one more time and switch to the orientdb-dserver-config.xml file still in the conf/config directory.

Pay attention to the exact name of the required configuration file (as the current folder contains the similar one) - it should include the dserver word.

Find the HTTP protocol setting in the <listeners> file section (approximately at the 73d code line) and edit the port-range variable value, stating it to 8080-8090.
orientdb listener
Save the changes for all nodes in the way you’ve done it recently.
7. In order to protect your database servers from the unauthorized access, let’s set the admin username and password for them.

Note: This step is optional, but highly recommended.

You can copy and use the default credentials from the orientdb-server-config.xml file (they were also sent to you via email after environment creation) or add your own, new ones. We'll use the custom root/qwerty credentials as an example. So, specify the desired values within the following line:
<user name="root" password="qwerty" resources="*"/>
Then, in the same file, scroll a bit down (approximately to the 100th line) and paste the received string inside the users section.
credentials orient
Depending on your preferences, the credentials could be identical (in this case use the Save for all instances option at any node you’ve performed the changes for) or different for each of your nodes (use Save only for the current instance for applying the changes at every instance).
8. Once all the required changes are saved, navigate to the beginning of the same file and uncomment the first nodeName parameter in the <handler class="com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin"> section.
This time you need to make the different changes for each node, modifying this parameter by means of entering the stated (in the 4th step) node names, inside the value variable. In accordance with the earlier specified settings in this instruction, the values should be:

  • for the first node:
    <parameter name="nodeName" value="node1"/>
  • for the second node:
    <parameter name="nodeName" value="node2"/>

You can switch between the nodes via the appropriate list in the top left part of the Configuration Manager tab (circled at the image below).
orientdb instance

Do not forget to save the changes separately, with the help of Save only for the current instance option instead of the previously used Save for all instances one.

7. Finally, find the server.sh script inside the bin directory, and change the default configuration file, used by your DB server, to orientdb-dserver-config.xml within the CONFIG_FILE variable.
orientdb replication

Note: If you can't find the mentioned folder in your Configuration Manager, please send a request to your hosting provider for OrientDB cartridge re-importing in order to get all the new functionality available.

Save new settings for all instances.
8. In order to run your cluster with all the new configurations applied, you need to Stop your environment and Start it again using the appropriate buttons next to it.
start orientdb

Replication Check Up

As soon as your servers are running, let’s check the data is replicated inside the set of your nodes. For that we’ll create the same-named DB at each of the instances and ensure that classes and records inside it are instantly copied to all nodes after the addition.
1. Open the first database node in browser in order to access its OrientDB Studio administration panel.
access orientdb
2. Enter your admin credentials (if you set them) in the appeared pop-up window and click the Create new database button.
create database orient
3. In the opened dialog frame, type the desired database name (e.g. jelastic) and specify your admin credentials. Optionally, select the preferred Type and Storage Type within the corresponding drop-down lists and click on Create database to finish.
orientdb new database
4. Repeat the first three steps for the rest of your DB servers in order to create a compound of the databases with the same name inside your cluster.

Note: that it’s an obligatory operation for the proper replication work; once created at a single node, the database won’t appear at others without restarting your environment.

database orient
5. After that, Connect to this newly created database at the random OrientDB instance by choosing it from the Database drop-down list and specifying your admin credentials (if there are any).
connect to db orient
6. Once inside, switch to the Schema tab and click on the New Class button.
orientdb schema
7. In the shown pop-up window, type the name of your new class (e.g. Repl-test) and define the remained options if necessary (or leave them blank). Click Save to finish.
new class orientdb
8. Now, let’s add a simple record to our class (click on the New Record button next to it).
orientdb add record
9. We’ll adjust this record to contain the additional custom field. You can add it through choosing the Add field option within the Actions list.
add fiels orientdb
Specify the desired field name (for instance, Name), set the string type for it and click Add field to proceed.
field string orient
10. Now, let’s set any name for our new record, e.g. John. Save the changes with the corresponding button.
create record orient database
11. Finally, connect to the same jelastic database at all the rest OrientDB nodes and check that the Repl-test class with your custom record exists at every one of them.
jelastic orient databasemulti master replica orient
Great! As you can see, replication works like a charm, so you can start using your DB cluster according to your needs without worrying about the data’s safety.
Register for a free 2-week trial now and check it out yourself!