This plugin is part of the Kuzzle Enterprise Plan. If you are interested, please contact us.

Planning a migration #

A migration that needs a copy closes the collection's writes for the time of the copy. This page helps you size that window, check the disk space, and know what happens if a node fails meanwhile.

How long writes stay closed #

Writes are closed from the lock to the switch: the grace delay (graceDelay, 5 s by default), then the copy, then a few hundred milliseconds for the switch. The copy time grows with the number of documents, their size, and the Elasticsearch hardware.

Measured on a laptop (8 CPU, Elasticsearch 8.17 single node in Docker, 3 Kuzzle nodes, batchSize 1000):

DocumentsDocument sizeGrace delayWrites closed
200,000~300 bytes, 7 fields0.5 s5.5 s (copy: 5 s)
1,000,000~300 bytes, 7 fields0.5 s25 s (copy: 24 s)
300,000~150 bytes, 6 fields5 s (default)12 to 14 s
1,000,000~150 bytes, 6 fields5 s (default)29 to 32 s

That is about 40,000 documents per second, so about 25 s of copy per million documents, plus the grace delay. Production clusters may be faster (more nodes, more shards) or slower (bigger documents, a busy cluster, slower disks): measure on a copy of your data before planning the window.

To measure, restore a snapshot of the collection on a staging platform and run the migration there. status gives lockedAt, copiedAt and finishedAt: writes are closed from lockedAt to finishedAt, and copiedAt − lockedAt includes the grace delay. status has no timestamp for the start of the copy itself: it is the time of the job <jobId> copying <total> documents log line, or of the first realtime message in the copying phase (see Following a migration).

Plan the migration like a short maintenance window for writers: clients should retry a 503 collection_locked later (see Client applications), or the writes should be paused while it runs.

Disk space #

A copy needs room for a second copy of the collection, primary shards plus replicas, below Elasticsearch's high disk watermark. start checks it before locking anything and refuses with not_enough_disk_space (412) otherwise.

The old indice is kept as an archive after the switch, so the space is only given back by purge.

During the copy the new indice has no replica; they are added at the end, and Elasticsearch builds them in the background after the switch (the cluster can be yellow for a while).

Cluster and node failures #

The job runs on one Kuzzle node, which holds a mutex in Redis. If that node stops, another node takes the job over from its last checkpoint (the last batch copied, not from scratch), writes still closed meanwhile:

  • Graceful stop (SIGTERM, a rolling upgrade): the node frees the mutex right before it exits, and the first node to check takes the job over, within resumeInterval (10 s by default).
  • Crash (killed, out of memory, host lost): the mutex expires mutexTtl after the node last extended it, which it does every third of mutexTtl; the first node to check then takes the job over: between 2/3 × mutexTtl and mutexTtl + resumeInterval after the crash, 20 to 40 s with the defaults (19 to 27 s measured).

To shorten it, lower both keys, see Configuration. A takeover shows in status (owner changes) and in the logs (taken over by node …), see Following a migration.

If every node stops, the job and the collection's write lock stay in Redis: the first node to start again takes the job over.

Kuzzle's cluster.minimumNodes setting applies to the whole API: if the cluster falls below it (for instance minimumNodes: 3 on a 3-node cluster that loses one node), every request is refused with api.process.not_enough_nodes (503), status and reads included. The job itself goes on in the background on the remaining nodes and completes, but nobody can follow it, and writes stay refused until the cluster is back. Keep minimumNodes below the node count if the API must stay up when a node is lost during a migration.