Cluster Administration

    For a general introduction to the ArangoDB Cluster, please refer to the chapter.

    There is also a detailedCluster Administration Coursefor download.

    Clusters can be deployed by ArangoDB aswith full hosting, management, and monitoring.

    Please check the following talks as well:

    For an introduction about Synchronous Replication in Cluster, please referto the Cluster Architecture section.

    Synchronous replication can be enabled per collection. When creating acollection you may specify the number of replicas using thereplicationFactor parameter. The default value is set to whicheffectively disables synchronous replication among DB-Servers.

    Whenever you specify a replicationFactor greater than 1 when creating acollection, synchronous replication will be activated for this collection. The Cluster will determine suitable leaders and followers for every requested shard (numberOfShards) within the Cluster.

    Example:

    In the above case, any write operation will require 3 replicas toreport success from now on.

    Preparing growth

    You may create a collection with higher replication factor thanavailable DB-Servers. When additional DB-Servers become available the shards are automatically replicated to the newly available DB-Servers.

    To create a collection with higher replication factor thanavailable DB-Servers please set the option enforceReplicationFactor to false, when creating the collection from ArangoShell (the option is not availablefrom the web interface), e.g.:

    1. db._create("test", { replicationFactor: 4 }, { enforceReplicationFactor: false });

    The default value for enforceReplicationFactor is true.

    Note: multiple replicas of the same shard can never coexist on the sameDBServer instance.

    For an introduction about Sharding in Cluster, please refer to the section.

    1. db._create("sharded_collection", {"numberOfShards": 4});

    To configure a custom hashing for another attribute (default is _key):

    The example above, where ‘country’ has been used as shardKeys can be usefulto keep data of every country in one shard, which would result in betterperformance for queries working on a per country base.

    It is also possible to specify multiple shardKeys.

    Note however that if you change the shard keys from their default ["_key"],then finding a document in the collection by its primary key involves a requestto every single shard. However this can be mitigated: All CRUD APIs and AQLsupport taking the shard keys as a lookup hint. Just make sure that the shardkey attributes are present in the documents you send, or in case of AQL, thatyou use a document reference or an object for the UPDATE, REPLACE or REMOVEoperation which includes the shard key attributes:

    1. FOR doc IN sharded_collection
    2. FILTER doc._key == "123"
    3. UPDATE doc WITH { } IN sharded_collection
    1. UPDATE { _key: "123", country: "…" } WITH { } IN sharded_collection

    Using a string with just the document key as key expression instead will beprocessed without shard hints and thus perform slower:

    If custom shard keys are used, you can no longer specify the primary key valuefor a new document, but must let the server generated one automatically. Thisrestriction comes from the fact that ensuring uniqueness of the primary keywould be very inefficient if the user could specify the document key.

    Unique indexes (hash, skiplist, persistent) on sharded collections areonly allowed if the fields used to determine the shard key are alsoincluded in the list of attribute paths for the index:

    shardKeysindexKeys
    aaallowed
    abnot allowed
    aa, ballowed
    a, banot allowed
    a, bbnot allowed
    a, ba, ballowed
    a, ba, b, callowed
    a, b, ca, bnot allowed
    a, b, ca, b, callowed

    On which DB-Server in a Cluster a particular shard is kept is undefined.There is no option to configure an affinity based on certain shard keys.

    Sharding strategy

    Strategy to use for the collection. Since ArangoDB 3.4 there aredifferent sharding strategies to select from when creating a new collection. The selected shardingStrategy value will remainfixed for the collection and cannot be changed afterwards. This isimportant to make the collection keep its sharding settings andalways find documents already distributed to shards using the sameinitial sharding algorithm.

    The available sharding strategies are:

    • community-compat: default sharding used by ArangoDBCommunity Edition before version 3.4
    • enterprise-compat: default sharding used by ArangoDBEnterprise Edition before version 3.4
    • enterprise-smart-edge-compat: default sharding used by smart edgecollections in ArangoDB Enterprise Edition before version 3.4
    • hash: default sharding used for new collections starting from version 3.4(excluding smart edge collections)

    If no sharding strategy is specified, the default will be hash forall collections, and enterprise-hash-smart-edge for all smart edgecollections (requires the Enterprise Edition of ArangoDB).Manually overriding the sharding strategy does not yet provide abenefit, but it may later in case other sharding strategies are added.

    The OneShardfeature does not have its own sharding strategy, it uses hash instead.

    A shard can be moved from a DB-Server to another, and the entire shard distributioncan be rebalanced using the corresponding buttons in the web .

    Replacing/Removing a Coordinator

    Coordinators are effectively stateless and can be replaced, added andremoved without more consideration than meeting the necessities of theparticular installation.

    Ca. 15 seconds later the cluster UI on any other Coordinator will markthe Coordinator in question as failed. Almost simultaneously, a trash binicon will appear to the right of the name of the Coordinator. Clickingthat icon will remove the Coordinator from the Coordinator registry.

    Any new Coordinator instance that is informed of where to find any/allAgent(s), —cluster.agency-endpoint <some agent endpoint> will beintegrated as a new Coordinator into the cluster. You may also justrestart the Coordinator as before and it will reintegrate itself intothe cluster.

    DB-Servers are where the data of an ArangoDB cluster is stored. Theydo not publish a web UI and are not meant to be accessed by any otherentity than Coordinators to perform client requests or other _DB-Servers_to uphold replication and resilience.

    The clean way of removing a DB-Server is to first relieve it of allits responsibilities for shards. This applies to followers as well asleaders of shards. The requirement for this operation is that nocollection in any of the databases has a replicationFactor greater orequal to the current number of DB-Servers minus one. For the purpose ofcleaning out for example would work as follows, whenissued to any Coordinator of the cluster:

    curl <coord-ip:coord-port>/_admin/cluster/cleanOutServer -d '{"server":"DBServer004"}'

    After the DB-Server has been cleaned out, you will find a trash binicon to the right of the name of the DB-Server on any Coordinators’UI. Clicking on it will remove the DB-Server in question from thecluster.

    Firing up any DB-Server from a clean data directory by specifying theany of all Agency endpoints will integrate the new DB-Server into thecluster.

    To distribute shards onto the new DB-Server either click on theDistribute Shards button at the bottom of the Shards page in everydatabase.

    The clean out process can be monitored using the following script,which periodically prints the amount of shards that still need to be moved.It is basically a countdown to when the process finishes.

    Save below code to a file named serverCleanMonitor.js:

    1. var dblist = db._databases();
    2. var internal = require("internal");
    3. var arango = internal.arango;
    4. var server = ARGUMENTS[0];
    5. var sleep = ARGUMENTS[1] | 0;
    6. if (!server) {
    7. print("\nNo server name specified. Provide it like:\n\narangosh <options> -- DBServerXXXX");
    8. process.exit();
    9. }
    10. if (sleep <= 0) sleep = 10;
    11. console.log("Checking shard distribution every %d seconds...", sleep);
    12. var count;
    13. for (dbase in dblist) {
    14. var sd = arango.GET("/_db/" + dblist[dbase] + "/_admin/cluster/shardDistribution");
    15. var collections = sd.results;
    16. for (collection in collections) {
    17. var current = collections[collection].Current;
    18. for (shard in current) {
    19. if (current[shard].leader == server) {
    20. ++count;
    21. }
    22. }
    23. }
    24. }
    25. console.log("Shards to be moved away from node %s: %d", server, count);
    26. if (count == 0) break;
    27. internal.wait(sleep);
    28. } while (count > 0);

    This script has to be executed in the arangoshby issuing the following command:

    1. arangosh --server.username <username> --server.password <password> --javascript.execute <path/to/serverCleanMonitor.js> -- DBServer<number>

    The output should be similar to the one below:

    The current status is logged every 10 seconds. You may adjust theinterval by passing a number after the DB-Server name, e.g.arangosh <options> — DBServer0002 60 for every 60 seconds.

    Once the count is all shards of the underlying DB-Server have been movedand the cleanOutServer process has finished.