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
$addDatabaseNodeOp = new AddDatabaseNodeOperation("Northwind");

// Execute the operation by passing it to Maintenance.Server.Send
/** @var DatabasePutResult $result */
$result = $store->maintenance()->server()->send($addDatabaseNodeOp);

// Can access the new topology
$numberOfReplicas = count($result->getTopology()->getMembers());

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
$addDatabaseNodeOp = new AddDatabaseNodeOperation("Northwind", "C");

// Execute the operation by passing it to Maintenance.Server.Send
/** @var DatabasePutResult $result */
$result = $store->maintenance()->server()->send($addDatabaseNodeOp);

Syntax

AddDatabaseNodeOperation(?string $databaseName, ?string $nodeTag = null)
Parameters Type Description
$databaseName ?string Name of a database for which to add the node.
$nodeTag ?string Tag of node to add.
Default: a random node from the existing cluster topology will be added.
Object returned by Send operation:
DatabasePutResult
Type Description
$name string Database name
$topology DatabaseTopology The database topology
$nodesAddedTo StringArray New nodes added to the cluster topology.
Will be 0 for this operation.
$raftCommandIndex int Raft command index