Adding a Database Node
-
When creating a database, you can specify the number of replicas for that database.
This determines the number of database instances in the database-group. -
The number of replicas can be dynamically increased even after the database is up and running,
by adding more nodes to the database-group. -
The nodes added must already exist in the cluster topology.
-
Once a new node is added to the database-group,
the cluster assigns a mentor node (from the existing database-group nodes) to update the new node. -
In this page:
Add database node - random
- Use
AddDatabaseNodeOperation
to add another database-instance to the database-group. - The node added will be a random node from the existing cluster nodes.
// Create the AddDatabaseNodeOperation
// Add a random node to 'Northwind' database-group
const addDatabaseNodeOp = new AddDatabaseNodeOperation("Northwind");
// Execute the operation by passing it to maintenance.server.send
const result = await documentStore.maintenance.server.send(addDatabaseNodeOp);
// Can access the new topology
const numberOfReplicas = getAllNodesFromTopology(result.topology).length;
Add database node - specific
- You can specify the node tag to add.
- This node must already exist in the cluster topology.
// Create the AddDatabaseNodeOperation
// Add node C to 'Northwind' database-group
const addDatabaseNodeOp = new AddDatabaseNodeOperation("Northwind", "C"));
// Execute the operation by passing it to maintenance.server.send
const result = await documentStore.maintenance.server.send(addDatabaseNodeOp);
Syntax
const addDatabaseNodeOp = new AddDatabaseNodeOperation(databaseName, nodeTag?);
Parameters | Type | Description |
---|---|---|
databaseName | string |
Name of a database for which to add the node. |
nodeTag | string |
Tag of node to add. Default: If not passed then a random node from the existing cluster topology will be added. |
Object returned by send operation has: | Type | Description |
---|---|---|
raftCommandIndex | number |
Index of the raft command that was executed |
name | string |
Database name |
topology | DatabaseTopology |
The database topology |
nodesAddedTo | string[] |
New nodes added to the cluster topology. Will be 0 for this operation. |