Switch Operations to a Different Node
-
By default, when working with multiple nodes,
all client requests will access the server node that is defined by the client configuration.
(Learn more in: Load balancing client requests). -
However, server maintenance operations can be executed on a specific node by using the
forNode
method.
(An exception is thrown if that node is not available). -
In this page:
Server maintenance operations - ForNode
- For reference, all server maintenance operations are listed here.
// Default node access can be defined on the store
$documentStore = new DocumentStore(
["ServerURL_1", "ServerURL_2", "..."],
"DefaultDB"
);
$conventions = new DocumentConventions();
// For example:
// With ReadBalanceBehavior set to: 'FastestNode':
// Client READ requests will address the fastest node
// Client WRITE requests will address the preferred node
$conventions->setReadBalanceBehavior(ReadBalanceBehavior::fastestNode());
$documentStore->setConventions($conventions);
$documentStore->initialize();
try {
// Use 'ForNode' to override the default node configuration
// The Maintenance.Server operation will be executed on the specified node
$dbNames = $documentStore->maintenance()->server()->forNode("C")
->send(new GetDatabaseNamesOperation(0, 25));
} finally {
$documentStore->close();
}
Syntax:
public function forNode(string $nodeTag): ServerOperationExecutor
Parameters | Type | Description |
---|---|---|
$nodeTag | string |
The tag of the node to operate on |
Return Value | |
---|---|
ServerOperationExecutor |
New instance of Server Operation Executor that is scoped to the requested node |