Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import CodeBlock from '@theme/CodeBlock';
No read balancing will occur.
The client will always send _Read_ requests to the [preferred node](../../../../client-api/configuration/load-balance/overview.mdx#the-preferred-node).
* **Failover**
The client will failover nodes in the order they appear in the [topology nodes list](../../../../studio/database/settings/manage-database-group.mdx#database-group-topology---actions).
The client will fail over to the nodes in the order of the [topology list](../../../../studio/database/settings/manage-database-group.mdx#the-database-group-view).
### `RoundRobin`

* **Read-balance**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import CodeBlock from '@theme/CodeBlock';
No read balancing will occur.
The client will always send _Read_ requests to the [preferred node](../../../../client-api/configuration/load-balance/overview.mdx#the-preferred-node).
* **Failover**
The client will failover nodes in the order they appear in the [topology nodes list](../../../../studio/database/settings/manage-database-group.mdx#database-group-topology---actions).
The client will fail over to the nodes in the order of the [topology list](../../../../studio/database/settings/manage-database-group.mdx#the-database-group-view).
### `RoundRobin`

* **Read-balance**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import CodeBlock from '@theme/CodeBlock';
No read balancing will occur.
The client will always send _Read_ requests to the [preferred node](../../../../client-api/configuration/load-balance/overview.mdx#the-preferred-node).
* **Failover**
The client will failover nodes in the order they appear in the [topology nodes list](../../../../studio/database/settings/manage-database-group.mdx#database-group-topology---actions).
The client will fail over to the nodes in the order of the [topology list](../../../../studio/database/settings/manage-database-group.mdx#the-database-group-view).
### `RoundRobin`

* **Read-balance**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import CodeBlock from '@theme/CodeBlock';
No read balancing will occur.
The client will always send _Read_ requests to the [preferred node](../../../../client-api/configuration/load-balance/overview.mdx#the-preferred-node).
* **Failover**
The client will failover nodes in the order they appear in the [topology nodes list](../../../../studio/database/settings/manage-database-group.mdx#database-group-topology---actions).
The client will fail over to the nodes in the order of the [topology list](../../../../studio/database/settings/manage-database-group.mdx#the-database-group-view).
### `RoundRobin`

* **Read-balance**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ see_also:
link: "studio/database/settings/client-configuration-per-database"
source: "docs"
path: "Studio > Database Management > Settings"
- title: "Database-group-topology"
link: "studio/database/settings/manage-database-group#database-group-topology---view"
- title: "Manage Database Group"
link: "studio/database/settings/manage-database-group#the-database-group-view"
source: "docs"
path: "Studio > Database Management > Settings"
---
Expand Down
91 changes: 48 additions & 43 deletions docs/client-api/configuration/load-balance/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,101 +6,106 @@ sidebar_position: 0
---

import Admonition from '@theme/Admonition';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CodeBlock from '@theme/CodeBlock';
import LanguageSwitcher from "@site/src/components/LanguageSwitcher";
import LanguageContent from "@site/src/components/LanguageContent";
import Panel from "@site/src/components/Panel";

# Load balancing client requests - Overview
<Admonition type="note" title="">

* A database can have multiple instances, each one residing on a different cluster node.
Each instance is a complete replica of the database.

* The [database-group-topology](../../../studio/database/settings/manage-database-group.mdx#database-group-topology---view) is the list of nodes that contain those database replicas.
* The [database group topology](../../../studio/database/settings/manage-database-group.mdx#the-database-group-view) is the list of nodes that contain the database's replicas.
The first node in this list is called the [preferred node](../../../client-api/configuration/load-balance/overview.mdx#the-preferred-node).

* The client is kept up-to-date with this topology list.
__The client decides which node from this list to access__ when making requests to the RavenDB cluster.
**The client decides which node from this list to access** when making requests to the RavenDB cluster.

* By default, the client will access the preferred node for all _Read & Write_ requests it makes.
This default behavior can be changed by configuring:
* [ReadBalanceBehavior](../../../client-api/configuration/load-balance/read-balance-behavior.mdx) - load balancing `Read` requests only
* [LoadBalanceBehavior](../../../client-api/configuration/load-balance/load-balance-behavior.mdx) - load balancing `Read & Write` requests
* In this page:
* [Keeping the client topology up-to-date](../../../client-api/configuration/load-balance/overview.mdx#keeping-the-client-topology-up-to-date)
* [Client logic for choosing a node](../../../client-api/configuration/load-balance/overview.mdx#client-logic-for-choosing-a-node)
* [The preferred node](../../../client-api/configuration/load-balance/overview.mdx#the-preferred-node)
* [Single-node session usage](../../../client-api/configuration/load-balance/overview.mdx#single-node-session-usage)


* In this article:
* [Keeping the client topology up-to-date](../../../client-api/configuration/load-balance/overview.mdx#keeping-the-client-topology-up-to-date)
* [Client logic for choosing a node](../../../client-api/configuration/load-balance/overview.mdx#client-logic-for-choosing-a-node)
* [The preferred node](../../../client-api/configuration/load-balance/overview.mdx#the-preferred-node)
* [Single-node session usage](../../../client-api/configuration/load-balance/overview.mdx#single-node-session-usage)

</Admonition>
## Keeping the client topology up-to-date

* Upon Document Store initialization, the client receives the __initial topology list__,
<Panel heading="Keeping the client topology up-to-date">

* Upon Document Store initialization, the client receives the **initial topology list**,
after which the client is kept updated at all times for any changes made to it.

* If the topology list has changed on the server, (or any other client configuration),
the client will learn about it upon making its __next request__ to the server,
* If the topology list (or any other client configuration) has changed on the server,
the client will learn about the change from the server's response to its **next request**,
and will update its configuration accordingly.

* In addition, every 5 minutes, the client will fetch the current topology from the server
if no requests were made within that time frame.

* Any client-configuration settings that are set on the server side __override__ the settings made on the client-side.
* Any client-configuration settings that are set on the server side **override** the settings made on the client side.

* For more information see [Topology in the client](../../../client-api/cluster/how-client-integrates-with-replication-and-cluster.mdx#cluster-topology-in-the-client).

</Panel>


## Client logic for choosing a node
<Panel heading="Client logic for choosing a node">

The client uses the following logic (from top to bottom) to determine which node to send the request to:
<Admonition type="info" title="">

* Use the __specified node__:
* Use the **specified node**:
A client can explicitly specify the target node when executing a [server-maintenance operation](../../../client-api/operations/what-are-operations.mdx#server-maintenance-operations).
Learn more in [switch operation to a different node](../../../client-api/operations/how-to/switch-operations-to-a-different-node.mdx).
* Else, if using-session-context is defined, use __LoadBalanceBehavior__:
Learn more in [Switch Operations to a Different Node](../../../client-api/operations/how-to/switch-operations-to-a-different-node.mdx).
* Else, if **LoadBalanceBehavior** is set to `UseSessionContext`, use the session context:
Per session, the client will select a node based on the [session context](../../../client-api/configuration/load-balance/load-balance-behavior.mdx#loadbalancebehavior-options).
All `Read & Write` requests made on the session will be directed to that node.
* Else, if defined, use __ReadBalanceBehavior__:
All `Read & Write` requests made on the session will be directed to the selected node.
* Else, if defined, use **ReadBalanceBehavior**:
`Read` requests: The client will select a node based on the [read balance options](../../../client-api/configuration/load-balance/read-balance-behavior.mdx#readbalancebehavior-options).
`Write` requests: All _Write_ requests will be directed to the preferred node.
* Else, use the __preferred node__:
`Write` requests: All _Write_ requests will be directed to the preferred node.
* Else, use the **preferred node**:
Use the [preferred node](../../../client-api/configuration/load-balance/overview.mdx#the-preferred-node) for both `Read & Write` requests.

</Admonition>

</Panel>

<Panel heading="The preferred node">

## The preferred node

* The preferred node is simply the __first__ node in the [topology nodes list](../../../studio/database/settings/manage-database-group.mdx#database-group-topology---view).
* __By default__, when no load balancing strategy is defined,
* The preferred node is the **first** node in the [topology list](../../../studio/database/settings/manage-database-group.mdx#the-database-group-view).
* **By default**, when no load balancing strategy is defined,
the client will send all `Read & Write` requests to this node.
* When the preferred node is in a failure state,
the cluster will update the topology, assigning another node to be the preferred one.
* When the preferred node is in a failure state,
the client will send its requests to the first node in the topology list that is not in a failure state.
If the failed node stays down, the cluster will change the node's state to `Rehab` and move it to the end of the list,
so the second node in the list will become the preferred node.
* Once the preferred node is back up and has caught up with all data,
it will be placed __last__ in the topology list.
* If all the nodes in the topology list are in a failure state then the first node in the list will be the 'preferred'.
The user would get an error, or recover if the error was transient.
the cluster will [randomly reorder](../../../server/clustering/distribution/distributed-database.mdx#nodes-order) the topology list of every database the recovered node hosts,
so the node may be placed anywhere in each list.
As a result, the preferred-node role of the node's databases will be spread among the cluster's nodes,
instead of remaining with the nodes that stayed up.
* If you set a [fixed order](../../../client-api/operations/server-wide/reorder-database-members.mdx) for the topology list, the cluster will restore the fixed order instead,
and the recovered node will return to its position in the fixed order.
* If all the nodes in the topology list are in a [failure state](../../../client-api/cluster/how-client-integrates-with-replication-and-cluster.mdx#failover-behavior),
the client will send each request to the next node in the list, in turn.
The request will fail, unless the node it is sent to has recovered (e.g., from a temporary network outage).
* The preferred node can be explicitly set by:
* Reordering the topology list from the [Database Group view](../../../studio/database/settings/manage-database-group.mdx#database-group-topology---actions).
* Reordering the topology list from the [Database Group view](../../../studio/database/settings/manage-database-group.mdx#reordering-nodes).
* Sending [ReorderDatabaseMembersOperation](../../../client-api/operations/server-wide/reorder-database-members.mdx) from the client code.
* The cluster may assign a different preferred node when removing/adding new nodes to the database-group.

* The cluster may assign a different preferred node when nodes join the database group or leave it.

</Panel>

## Single-node session usage
<Panel heading="Single-node session usage">

* When using a [single-node session](../../../client-api/session/cluster-transaction/overview.mdx#single-node),
a short delay in replicating changes to all nodes in the cluster is acceptable in most cases.
a short delay in replicating changes to all nodes in the cluster is acceptable in most cases.

* If `ReadBalanceBehavior` or `LoadBalanceBehavior` are defined,
then the next session you open may access a different node.
So if you need to ensure that the next request will be able to _immediately_ read what you just wrote,
then use [Write Assurance](../../../client-api/session/saving-changes.mdx#waiting-for-replication---write-assurance).



</Panel>
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ see_also:
link: "studio/database/settings/client-configuration-per-database"
source: "docs"
path: "Studio > Database Management > Settings"
- title: "Database-group-topology"
link: "studio/database/settings/manage-database-group#database-group-topology---view"
- title: "Manage Database Group"
link: "studio/database/settings/manage-database-group#the-database-group-view"
source: "docs"
path: "Studio > Database Management > Settings"
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,89 @@
import Admonition from '@theme/Admonition';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CodeBlock from '@theme/CodeBlock';
import Panel from "@site/src/components/Panel";
import ContentFrame from "@site/src/components/ContentFrame";

**ReorderDatabaseMembersOperation** allows you to change the order of nodes in the [Database Group Topology](../../../../studio/database/settings/manage-database-group.mdx).
<Admonition type="note" title="">

## Syntax
* `ReorderDatabaseMembersOperation` allows you to change the order of nodes in the
[Database Group Topology](../../../../studio/database/settings/manage-database-group.mdx).

<TabItem value="syntax" label="syntax">
<CodeBlock language="csharp">
{`public ReorderDatabaseMembersOperation(string database, List<string> order)
`}
</CodeBlock>
</TabItem>
* To make the [Cluster Observer](../../../../server/clustering/distribution/cluster-observer.mdx) keep the order you set,
set `fixedTopology` to `true`. Otherwise, the observer may later
[randomly reorder the nodes](../../../../server/clustering/distribution/distributed-database.mdx#nodes-order), for example when a node recovers.

| Parameters | | |
| ------------- | ------------- | ----- |
| **database** | string | Name of a database to operate on |
| **order** | List\&lt;string&gt; | List of node tags of all existing nodes in the database group, listed in the exact order that you wish to have. <br/> Throws `ArgumentException` is the reordered list doesn't correspond to the existing nodes of the database group |
* In this article:
* [Examples](../../../../client-api/operations/server-wide/reorder-database-members.mdx#examples)
* [Syntax](../../../../client-api/operations/server-wide/reorder-database-members.mdx#syntax)

</Admonition>

## Example I
<Panel heading="Examples">

<TabItem value="example_1" label="example_1">
<CodeBlock language="csharp">
{`// Assume that the current order of database group nodes is : ["A", "B", "C"]
<ContentFrame>

#### Example: Set a new order

```csharp
// Assume that the current order of database group nodes is : ["A", "B", "C"]

// Change the order of database group nodes to : ["C", "A", "B"]

store.Maintenance.Server.Send(new ReorderDatabaseMembersOperation("Northwind",
new List<string>
\{
{
"C", "A", "B"
\}));
`}
</CodeBlock>
</TabItem>
}));
```

</ContentFrame>

## Example II
<ContentFrame>

<TabItem value="example_2" label="example_2">
<CodeBlock language="csharp">
{`// Get the current DatabaseTopology from database record
#### Example: Reverse the current order

```csharp
// Get the current DatabaseTopology from database record
var topology = store.Maintenance.Server.Send(new GetDatabaseRecordOperation("Northwind")).Topology;

// Reverse the order of database group nodes
topology.Members.Reverse();
store.Maintenance.Server.Send(new ReorderDatabaseMembersOperation("Northwind", topology.Members));
`}
</CodeBlock>
</TabItem>
```

</ContentFrame>

<ContentFrame>

#### Example: Set a fixed order

```csharp
// Set the order of database group nodes to ["C", "A", "B"],
// and keep this order when the Cluster Observer reorders the nodes
store.Maintenance.Server.Send(new ReorderDatabaseMembersOperation("Northwind",
new List<string>
{
"C", "A", "B"
},
fixedTopology: true));
```

</ContentFrame>

</Panel>

<Panel heading="Syntax">

```csharp
public ReorderDatabaseMembersOperation(string database, List<string> order)

public ReorderDatabaseMembersOperation(string database, List<string> order, bool fixedTopology)
```
<br />

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| **database** | `string` | Name of a database to operate on |
| **order** | `List<string>` | List of node tags of all existing nodes in the database group, listed in the exact order that you wish to have. <br/> Throws `ArgumentException` if the reordered list doesn't correspond to the existing nodes of the database group |
| **fixedTopology** | `bool` | `true`: the Cluster Observer keeps the order in `order`. Whenever the observer reorders the nodes (for example, when it promotes a recovered node back to `Member`), the observer restores the order in `order`. <br/> `false` (the first constructor's value): the order may change later, and the server clears any fixed order set earlier. |

</Panel>
Loading
Loading