KOVA
Docs

Replica sets

Copies of the same data. You write on the primary. The other members hold that data so one machine can fail.

Leave [replication] commented and the process is one writable node. Uncomment it when the fear is losing the machine. Every voting member stores every document of that set. Writes are not faster because you added members. Reads can go to a secondary. The driver's read preference chooses a host from the list hello returns. This process does not proxy that read.

Three members on one machine

Each member is its own process, its own KOVA_CONFIG, its own port, and its own data directory. Set port to the client port in that member's row. Do not point two processes at the same data/. The ports below are examples. Leave 27018 for the single server you already run.

[replication]
enabled = true
id = 1
bootstrap = true
set_name = "kova"
members = [
  { id = 1, client = "127.0.0.1:27218", raft = "127.0.0.1:27318" },
  { id = 2, client = "127.0.0.1:27219", raft = "127.0.0.1:27319" },
  { id = 3, client = "127.0.0.1:27220", raft = "127.0.0.1:27320", arbiter = true },
]
KeyMeaning
idThis process's member id. It must appear in members.
clientThe MongoDB address clients use. It matches port on that process.
raftA second TCP port, used only between Kova processes.
bootstrapThe process that commits the voter set. The others wait for that log. The same membership on more than one bootstrap is safe. Two different memberships split the set.
arbiterKeeps the oplog, stores no documents, and does not vote, so it cannot become primary.

A majority of voting members elects the primary. A node that is not the leader rejects writes with NotWritablePrimary (code 10107). Secondaries serve reads. Heartbeats and elections are the replication protocol inside the process.

What hello tells the driver

hello reports setName, isWritablePrimary, secondary, hosts, primary, and me. Point the driver at any member. It learns the primary from that reply.

The oplog and a follower that fell behind

find on local.oplog.rs returns entries after ts ($gt or $gte). ts is the log index. Inserts without _id receive one before the command is logged, so every replica stores the same id.

A committed auto-commit command is applied on the leader and on every follower. A transaction's begin and its staged statements stay on the primary. Commit ships one entry. Abort ships nothing. Details are on Transactions.

After 64 log entries the primary builds a snapshot of the page files. A follower whose log no longer overlaps installs that snapshot and applies only the later entries. The snapshot is the pages, the catalog, and the view routes, at one oplog index. The write-ahead log is not in it. An arbiter stores the oplog and does not install document pages. With no [replication] section the process does not build or ship a snapshot.

With shards

A replica set copies one notebook. A shard splits the notebook. The durable shape is several shards, and each shard is its own replica set: a primary and copies of that piece only. One process is the router, or a member of a set. It is not both. The router configuration is on Sharding.