Skip to content

Conversation

@willholley
Copy link
Member

Overview

This adds a feature to populate the zone field in the nodes database by setting the
COUCHDB_ZONE environment variable. Setting the zone for a node was previously an awkward piece of cluster setup orchestration because it required editing the a document on each of the local "nodes" after CouchDB has started but before creating any other system databases.

This implementation reads the COUCHDB_ZONE environment variable when mem3 starts and, if present, updates the local node document with that zone string.

One nuance is that multiple nodes in the cluster might create the same first revision of a node document due to the seedlist feature, which pre-emptively adds the seeds to the nodes database. To prevent conflicts when the nodes database is replicated between peers, the zone is set using an additional update to the node document for the local node only.

Other things to note:

  • We generally don't expect COUCHDB_ZONE to change in the lifetime of a node, but the code does allow this.
  • If COUCHDB_ZONE is not set, no modifications to the node document are made.

Testing recommendations

Eunit tests are added to verify the node document is as expected. You can also test using:

COUCHDB_ZONE="zone1" ./dev/run

...

curl http://127.0.0.1:15984/_node/_local/_nodes/_all_docs?include_docs=true  

Related Issues or Pull Requests

Checklist

  • Code is written and works correctly
  • Changes are covered by tests
  • Any new configurable parameters are documented in rel/overlay/etc/default.ini
  • Documentation changes were made in the src/docs folder
  • Documentation changes were backported (separated PR) to affected branches

@willholley willholley force-pushed the placement-zone-join branch 3 times, most recently from 2f77912 to 31d381f Compare July 7, 2025 10:48
Value :: any(),
TupleList2 :: [Tuple].
set_value(Key, TupleList1, Value) ->
TupleList2 = [{Key, Value} | TupleList1],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couch_util:set_value/3 previously only worked
when replacing a value associated with an existing
key. This commit changes the semantics to be
"set or update". I've also added a typespec for
completeness.
@willholley willholley force-pushed the placement-zone-join branch from 940e5f1 to 9f87d3a Compare July 7, 2025 16:41
Copy link
Contributor

@nickva nickva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Thanks for also updating the docs

This adds a feature to populate the zone field
in the `nodes` database by setting the
`COUCHDB_ZONE` environment variable. The zone
is used in combination with [placement](https://docs.couchdb.org/en/stable/cluster/databases.html#placing-a-database-on-specific-nodes)
rules to specify that database shard replicas
must exist across specific nodes - most commonly
used to specify that a replica should exist in
multiple availability zones in a region.

Setting the zone was previously an awkward piece
of cluster setup orchestration because it required
editing the node document in the local "nodes"
database before creating any system databases.

This instead sets the zone when initially creating
the node document on startup, which should then
get replicated to other peers in the cluster.

One nuance is that multiple nodes in the cluster
might create the same first revision of the node document
due to the seedlist feature. To prevent conflicts
when the nodes database is replicated internally,
the zone is set using an additional update to the
document associated with the current node only.
@willholley willholley force-pushed the placement-zone-join branch from 9f87d3a to 88e23b5 Compare July 7, 2025 18:41
@willholley willholley merged commit 025ec26 into main Jul 8, 2025
24 checks passed
@willholley willholley deleted the placement-zone-join branch July 8, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants