Clustering
Operations API for managing Harper's replication system. For an overview of how replication works, see Replication Overview. For sharding configuration, see Sharding.
All clustering operations require super_user role.
Add Node
Adds a new Harper instance to the cluster. If subscriptions are provided, it creates the specified replication relationships between the nodes. Without subscriptions or sendsTo / receivesFrom, a fully replicating system is created (all data in all databases). sendsTo / receivesFrom instead scope controlled-flow replication to the databases they name.
Parameters:
-
operation(required) — must beadd_node -
hostnameorurl(required) — the hostname or URL of the node to add -
verify_tls(optional) — whether to verify the TLS certificate. Set tofalsetemporarily on fresh installs with self-signed certificates. Defaults totrue -
authorization(optional) — credentials for the node being added. Either an object withusernameandpassword, or an HTTPAuthorizationstyle string -
retain_authorization(optional) — iftrue, stores credentials and uses them on every reconnect. Generally not recommended; prefer certificate-based authentication. Defaults tofalse -
revoked_certificates(optional) — array of revoked certificate serial numbers that will not be accepted for any connections -
shard(optional) — shard number for this node. Only needed when using sharding -
start_time(optional) — ISO 8601 UTC datetime. If set, only data after this time is downloaded during initial synchronization instead of the entire database -
isLeader(optional) — identify the added node as a bootstrap source for this node. This does not grant primary ownership or write authority, or prevent full-copy requests to other peers for which this node has no resume cursor. Subsequent replication still follows the configured routes -
subscriptions(optional) — explicit table-level replication relationships. This is optional (and discouraged). Each subscription is an object with:database— database nametable— table namesubscribe— iftrue, transactions on the remote table are replicated locallypublish— iftrue, transactions on the local table are replicated to the remote node
-
sendsTo/receivesFrom(optional) Added in: v5.1.0 Changed in: v5.2.0 — database-scoped controlled-flow entries for this node (see Controlling Replication Flow). Each entry is an object{ database?, excludeTables? }, or (less usefully) a bare string naming a peer, intended to authorize all databases for that peer rather than match a database name. An entry can also carry atarget(onsendsTo) orsource(onreceivesFrom) naming the one peer it applies to; an entry with neither matches any peer. Only the peer-agnostic object form —{ database?, excludeTables? }, with notarget/source— is reliable today. Harper's reciprocaladd_node_backregistration to the added peer carries the array over without rewriting each entry's peer reference for the new direction, so a bare string or atarget/sourcevalue that's correct for your side of the connection ends up wrong on the peer's copy, and the peer's send-authority check silently rejects the subscription — replication doesn't happen (harper-pro#710 -add_node_backdoes not rewrite peer-qualifiedsendsTo/receivesFromentries). Use config routes for anything that needs to be scoped to one peer. Unlike a config route'sreplicates.sendsTo/replicates.receivesFrom, which describes the local node's own direction, these describe the added node's perspective:sendsTolists what the added node sends (what this node receives from it), andreceivesFromlists what the added node receives (what this node sends to it). If bothsubscriptionsandsendsTo/receivesFromare provided,subscriptionstakes precedence andsendsTo/receivesFromare ignored. To replicate all databases while excluding specific tables, use a wildcard entry (excludeTableswith nodatabase).Note: Because these entries aren't scoped to one peer, the resulting
hdb_nodesrecord for the added node isn't restricted to the connection that created it — any other node that also holds the listed database(s) can match against it too. This also doesn't change how the local node advertises itself to the rest of the cluster: a node's own directional (non-mesh)hdb_nodesself-record is derived solely from itsharper-config.yamlroutes, so replicatingsystemwithout collapsing to a full mesh requires directional routes in config, not justadd_node/set_nodescoping (see Replicating thesystemdatabase with controlled flow). Nor is the scoping durable: each node rewrites its ownhdb_nodesrow from itsharper-config.yamlroutes when it restarts or reloads components, and that row replicates, so directional entries anadd_nodecall wrote onto the added node's row are superseded — a node with no directional routes goes back to advertising the legacy full-mesh record. Use config routes for any constraint that has to survive a restart or adeploy_componentreload.Changed in v5.2: these parameters have been accepted since v5.1.0, but they only gate replication as described above from v5.2 on. Before v5.2,
add_nodewrote a blanket "sends everything" flag onto the added node's registry record alongside the entries, which authorized this node to receive every database from that node and leftsendsTo'sdatabasescoping inert; in the other direction, the send-authority check honored areceivesFromentry only when it named both this node and the database, so the peer-agnostic object form recommended above did not authorize sending. As of v5.2 the blanket flag is gone — replication from the added node is limited to the databases itssendsToentries name — and an entry that omits the peer or the database is treated as a wildcard by both checks. If you already calladd_node/set_nodewithsendsTo/receivesFrom, re-check that scoping before upgrading — it can change in either direction. Databases that were replicating only because of the blanket flag stop replicating on v5.2; conversely, a peer-agnosticreceivesFromentry that v5.1's send check ignored becomes an active wildcard on v5.2, so it newly authorizes any peer that subscribes for the database it names.
Request:
{
"operation": "add_node",
"hostname": "server-two",
"verify_tls": false,
"authorization": {
"username": "admin",
"password": "password"
}
}
Request (controlled flow, scoped per database):
{
"operation": "add_node",
"hostname": "server-two",
"sendsTo": [{ "database": "cardata", "excludeTables": ["raw_telemetry"] }],
"receivesFrom": [{ "database": "config" }, { "database": "system" }]
}
Read from the added node's perspective: server-two sends cardata (except raw_telemetry) to this node, and receives config and system from it.
Response:
{
"message": "Successfully added 'server-two' to cluster"
}
Note:
set_nodeis an alias foradd_node.
Update Node
Modifies an existing Harper instance in the cluster. Will attempt to add the node if it does not exist.
Parameters:
operation(required) — must beupdate_nodehostname(required) — hostname of the remote node to updaterevoked_certificates(optional) — array of revoked certificate serial numbers rejected when a new connection authenticates (already-open connections are not closed)shard(optional) — shard number to assign to this node. On the responding node's own hostname it must equal that node'sreplication.shard; any other value returns 400, since the node's own record follows its configuration. Changereplication.shardand restart instead. Setting a peer'sshardto a value other than itsreplication.shardleaves that peerheld(refusing sharded writes) until itsreplication.shardmatches, and restarting the peer beforehand rewrites its record fromreplication.shard.subscriptions(optional) — array of subscription objects (same structure asadd_node)sendsTo/receivesFrom(optional) — same structure and directional meaning as in Add Node above: they describe thehostnamenode's perspective, not this node's. See Add Node for the v5.1/v5.2 gating history and theadd_node_backpeer-rewrite caveat. As with Add Node, if bothsubscriptionsandsendsTo/receivesFromare provided,subscriptionstakes precedence andsendsTo/receivesFromare ignored.
Request:
{
"operation": "update_node",
"hostname": "server-two"
}
A request for an existing hostname record that carries revoked_certificates and/or shard and none of url, isLeader, retain_authorization, start_time, force_signing, subscriptions, sendsTo or receivesFrom is written to this node's record of hostname without contacting it, and replicates to the cluster from there. Any other request, including one for a hostname with no local record yet, runs the full add_node exchange with that node.
Response:
{
"message": "Successfully updated 'server-two'"
}
Remove Node
Removes a Harper node from the cluster and stops all replication to and from that node. Run it on any member, naming the node to remove.
Changed in: v5.5.0A node accepts writes locally and sends them to its peers afterward, so a live node can hold writes no peer has received yet: writes accepted just before removal, while a peer link was down, or, for a sharded table, writes to records it does not own. remove_node does not delete the node's membership until those writes are on its peers:
- The node being removed stops accepting local writes. A write to it returns
503("This node is being removed from its cluster"). Transactions it already started commit. This fence is persisted, so the node stays fenced across a restart, except a restart that could have lost its latest writes (below). Writes it receives from peers still apply. Thesystemdatabase is not fenced. remove_nodewaits until every peer the node sends a database to reports that it has committed all of the node's writes to that database. A peer that does not subscribe to the database from the node says so and is not waited for. A database the node sends to no peer (configured local-only) is not drained. For a sharded database, a peer on another shard reports the records it owns. Each peer confirms with the next delivery checkpoint the node sends it, every 30 seconds, so even a node with nothing left to send takes up to 30 seconds to remove.- Then the node's membership is deleted, as before. The removed node accepts local writes again once it receives the removal notice, or when it is added to a cluster again with
add_node.
The wait has a limit (timeout, five minutes by default). When it runs out, the removal fails with 504 and names each peer that has not confirmed. The node stays fenced and stays a member until the removal completes or is cancelled. An add_node or set_node run on the node, or naming it from another node, also lifts a fence that was not finalized. Run remove_node again to resume the wait, or cancel the removal with cancel: true, which lets the node accept writes again.
remove_node refuses a live removal without force when:
- the node cannot be reached (it keeps retrying until
timeout, since a restarting node is briefly unreachable), - the node runs a version that cannot fence its writes,
- the node is the only owner of a shard in a database's shard map, so its records exist nowhere else,
- a database is stored on LMDB, which keeps no origin floors to confirm delivery with,
- a database keeps its tables in more than one storage root (per-table
path), - the node's peers have yet to return its own writes after a start that could have lost the latest ones: one that followed an operating-system crash, power loss or reboot, or its first start on v5.5 (cluster record locks wait for the same thing), or
- no peer the node sends a database to subscribes to it, or, for a sharded database, no owner of one of its shards receives it from the node, so some of its writes exist only on that node.
In the last five cases the node accepts local writes again, even when an earlier remove_node that timed out left it fenced, unless that removal was finalized.
A node that restarts that way while fenced lifts its own fence at startup, unless its removal was finalized. A returned write is applied as one of the node's own, which a fence would refuse, and the node then sends it to the peers that never received it. Run remove_node again: it is refused until every peer has returned the node's writes, which usually takes seconds but waits for a peer that is down. In a database with both sharded and ordinary tables a peer on another shard is never asked, so a node's removal there needs force from its first such start onward.
force: true removes the node without fencing or waiting. Writes that only that node held are lost. Use it for a node that is permanently down.
Parameters:
operation(required) — must beremove_nodehostname(required) — hostname of the node to removetimeout(optional) Added in: v5.5.0 — milliseconds to wait for the node's writes to reach its peers; default300000force(optional) Added in: v5.5.0 — remove without fencing the node or waiting; writes only it holds may be lostcancel(optional) Added in: v5.5.0 — stop a removal that timed out: the node accepts local writes again and stays a member. Refused once the removal has been finalized, just before the membership is deleted; then runremove_nodeagain to complete it. If a removal completed but the removed node never received its notice (it was unreachable), it keeps refusing local writes: runremove_node_fenceon that node withnodeset to its own name,cancel: trueandforce: true.
Request:
{
"operation": "remove_node",
"hostname": "server-two"
}
Response:
{
"message": "Successfully removed 'server-two' from cluster; its writes reached 2 peers before it was removed"
}
Two operations carry the removal between nodes, authorized for cluster nodes and super users: remove_node_fence runs on the node being removed (fence, finalize or cancel), and get_received_origin_floors runs on each peer and reports what it has received from the node. remove_node calls them; you do not need to.
Cluster Status
Returns an array of status objects from the cluster, including active WebSocket connections and replication timing statistics.
Added in: v4.4.0 ; timing statistics added in v4.5.0
Parameters:
operation(required) — must becluster_status
Request:
{
"operation": "cluster_status"
}
Response:
{
"type": "cluster-status",
"connections": [
{
"replicateByDefault": true,
"replicates": true,
"url": "wss://server-2.domain.com:9933",
"name": "server-2.domain.com",
"subscriptions": null,
"database_sockets": [
{
"database": "data",
"connected": true,
"latency": 0.7,
"threadId": 1,
"nodes": ["server-2.domain.com"],
"lastCommitConfirmed": "Wed, 12 Feb 2025 19:09:34 GMT",
"lastReceivedRemoteTime": "Wed, 12 Feb 2025 16:49:29 GMT",
"lastReceivedLocalTime": "Wed, 12 Feb 2025 16:50:59 GMT",
"sendingMessage": "Wed, 12 Feb 2025 16:50:59 GMT"
}
]
}
],
"node_name": "server-1.domain.com",
"is_enabled": true,
"sharding": {}
}
database_sockets shows the actual WebSocket connections between nodes — one socket per database per node. Timing fields:
| Field | Description |
|---|---|
lastCommitConfirmed | Last time a receipt of confirmation was received for an outgoing commit |
lastReceivedRemoteTime | Timestamp (from the originating node) of the last received transaction |
lastReceivedLocalTime | Local time when the last transaction was received. A gap between this and lastReceivedRemoteTime suggests the node is catching up |
sendingMessage | Timestamp of the transaction actively being sent. Absent when waiting for the next transaction |
path | Which address this node dialed for the connection: public (the peer's url), private (a private network address), or public-fallback (the peer has a private address on this node's network, but it is not connecting). Each worker thread notices an outage and recovers on its own, so sockets to one peer that different threads handle can differ for the length of an outage. Absent while disconnected or before the peer has identified itself. Added in v5.4.0 |
While a database is taking its initial full copy, these timing fields hold the literal string "Copying" rather than a timestamp. Anything that parses them as dates needs to handle that value, since a node taking a full copy is exactly the node you are most likely to be watching.
Stuck Copies
Added in: v5.3.6A database_sockets entry has a stuckCopy object while a base copy of that database from that peer is not finishing. Otherwise the field is absent. The node receiving the copy reports it, on its socket to the source. Copies also run in reverse, so that can be a peer of the node that came back rather than the node itself. Run cluster_status on every node.
On the 5.3 line, state is only retrying or held. The refused state and everything below about refusals need schema-defined sharding, which starts in v5.4.0.
{
"database": "data",
"connected": false,
"stuckCopy": {
"state": "held",
"reason": "the copy made no durable progress from its start position",
"count": 5,
"since": "2026-11-03T14:20:11.204Z",
"retryAt": "2026-11-03T14:21:11.204Z"
}
}
| Field | Description |
|---|---|
state | retrying, held or, from v5.4.0, refused (below) |
reason | the copy made no durable progress from its start position for retrying and held. For refused, the sharding rule that refused the copy |
count | For retrying and held, how many times a copy has started from the same position. For refused, how many times in a row the copy was refused |
since | When the socket entered its current state. Another attempt or hold in the same state does not change it |
retryAt | When the socket reconnects after a hold. Present only while it waits out the hold, so it is absent once the reconnect opens, even if state is still held |
since and retryAt are ISO 8601 strings, unlike the GMT strings in the timing fields above.
The states:
retrying: a copy from this peer has started at least twice from the same position, with no durable progress in between. Reconnects follow the normal schedule.held: the session that made the fifth start from one position has closed. This node stops reconnecting that database to that peer for a while. Nothing in that database replicates from the peer during the hold, and the peer's copy stops too. The first hold lasts 60 seconds. After that, each reconnect makes one attempt. If it fails from the same position, the next hold is a random time between 60 seconds and a limit that doubles each time (2, 4, 8 minutes), up to 15 minutes.refusedAdded in: v5.4.0: this node refused the copy under its sharding rules. With the reasonOwned sharding slots require a complete co-owner or backup restore, this node owns slots and the peer cannot supply them. Typically the peer is not a complete co-owner, so make one reachable or restore a complete backup. Reconnects are held on the same schedule asheld. While every owner of a key refuses that peer, the peer answers a write to that key with503instead of accepting a write no owner would receive; the peer forgets the refusal when it restarts. With the reasona sharded origin requires its origin or a complete co-owner, the copy carried rows from a sharded origin that only that origin or a complete co-owner may send. Reconnects follow the normal schedule, because this usually follows a sharding map change.
The attempt limit, the hold bounds and the 60-second quiet period below are fixed. No setting changes them.
stuckCopy disappears in these cases:
- The copy makes durable progress, continues from a different position, or finishes. This also starts the hold schedule over.
- A later connection to the peer stays open for 60 seconds without starting or refusing a copy. This clears only the report. The start count and the hold limit stay, so if a copy later fails from the same position again, the socket shows
retryingwith the count carried on, and the next hold follows the schedule from where it left off. - A
refusedsocket settles when the session of a later, accepted copy closes. It clears, or becomesretryingif that copy also started twice from one position.
A missing stuckCopy does not show that a copy finished or that the two nodes hold the same data.
Each change of state, or of the refusal reason, logs one line beginning Replication of <database> from <node>:. The level is error when the socket is held, warn when it starts retrying or is refused, and info when the report clears, such as copy is progressing again. A held socket logs, for example, copy stopped after 5 attempts from one position; retrying in 60s: the copy made no durable progress from its start position. Further attempts or holds in the same state log nothing more.
Sharding Status
Added in: v5.4.0The top-level cluster_status.sharding field is keyed by database and describes active or attempted declarative tables. It is empty in the legacy-table example above. Each entry has:
| Field | Meaning |
|---|---|
version, digest | Installed map identity; absent if no map is installed. |
shards | One entry per shard in the installed map, ordered by shard: slots is the number of the map's slots the shard holds, and owners lists the names of the nodes assigned to it, in name order. A shard with no assigned node has owners: []. Absent if no map is installed. |
nodesOwningNoSlots | Names of cluster members, this node included, that own no slot of the installed map: nodes with no shard, or in a shard the map does not contain. Present with shards, as [] when there are none. |
shardsDigest | Digest of the configured shard set, or null when no list is configured. |
blocked | Whether a configuration/map error or a recovery phase other than ready blocks placement. |
state | quarantined for a startup quarantine, held for a live configuration/map error, the current recovery.phase while recovery is incomplete, or available. |
restartRequired | true for startup quarantine: repair the configuration and restart the full process. false does not mean recovery is complete. |
recovery | Bootstrap/recovery phase and reason, including a missing existing-owner completeness assertion in recovery.reason. origin-history-lost refuses a reused name without its audit; restore a complete backup or rejoin with a fresh root under a new node name. |
waitingOrigins | Origins waiting for a direct source or certified same-shard relay, with the missing source described. |
errors | Reasons, such as differing peer lists, a local shard outside its list, a missing required list/map, a refused peer map, or local shard membership disagrees with replication.shard when this node's own record and its replication.shard setting disagree about a shard in the installed map, so write admission refuses those slots. |
shards and nodesOwningNoSlots come from the installed map and the shard each node's record in the cluster membership table publishes, the same view that routes writes. The responding node does not read its own replication.shard setting to decide ownership, so with no installed map no owners are reported. They describe what this node sees. A listed owner can still be disconnected or refuse writes, for example when its record's shard differs from its own replication.shard setting (that node reports it in its own errors), and recovery and waitingOrigins track recovery agreement separately, so read them together. A node that has just joined can be missing from both lists until its record reaches the responding node.
"sharding": {
"data": {
"version": 1,
"digest": "5f0c...",
"state": "available",
"errors": [],
"shards": [
{ "shard": 0, "slots": 5, "owners": ["server-1.domain.com", "server-2.domain.com"] },
{ "shard": 1, "slots": 5, "owners": ["server-3.domain.com"] }
],
"nodesOwningNoSlots": ["server-4.domain.com"]
}
}
The top-level shard of the response is the responding node's own shard, including 0. It is absent when the node has no shard.
A clear status is not proof that an owner is connected; write admission also checks the required replication route. See configuration agreement and map recovery.
Shard map operations
The POST operations initialize_shard_map and verify_shard_map require super_user. The former installs a snapshot without moving records; the latter compares the actual legacy function against a proposed key policy without modifying data. Their request examples, parameters and result fields are in the linked procedures.
Configure Cluster
Bulk creates or resets subscriptions for any number of remote nodes. Resets and replaces any existing clustering setup.
Parameters:
operation(required) — must beconfigure_clusterconnections(required) — array of node objects following theadd_nodeschema
Request:
{
"operation": "configure_cluster",
"connections": [
{
"hostname": "server-two",
"verify_tls": false,
"authorization": {
"username": "admin",
"password": "password2"
}
},
{
"hostname": "server-three",
"verify_tls": false,
"authorization": {
"username": "admin",
"password": "password3"
}
}
]
}
Response:
{
"message": "Cluster successfully configured."
}
Cluster Set Routes
Adds routes to the replication.routes configuration. Behaves as a PATCH/upsert — adds new routes while leaving existing routes untouched.
Parameters:
operation(required) — must becluster_set_routesroutes(required) — array of route strings (wss://host:port) or objects withhostnameandportproperties
Request:
{
"operation": "cluster_set_routes",
"routes": [
"wss://server-two:9925",
{
"hostname": "server-three",
"port": 9930
}
]
}
Response:
{
"message": "cluster routes successfully set",
"set": ["wss://server-two:9925", { "hostname": "server-three", "port": 9930 }],
"skipped": []
}
Cluster Get Routes
Returns the replication routes from the Harper config file.
Parameters:
operation(required) — must becluster_get_routes
Request:
{
"operation": "cluster_get_routes"
}
Response:
["wss://server-two:9925", { "hostname": "server-three", "port": 9930 }]
Cluster Delete Routes
Removes routes from the Harper config file.
Parameters:
operation(required) — must becluster_delete_routesroutes(required) — array of route objects to remove
Request:
{
"operation": "cluster_delete_routes",
"routes": [
{
"hostname": "server-three",
"port": 9930
}
]
}
Response:
{
"message": "cluster routes successfully deleted",
"deleted": [{ "hostname": "server-three", "port": 9930 }],
"skipped": []
}