Rolling upgrades in Elasticsearch - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When performing rolling upgrades in Elasticsearch, we want to know how the time to complete the upgrade changes as the cluster size grows.
We ask: How does the upgrade process scale with more nodes?
Analyze the time complexity of this rolling upgrade process.
POST /_cluster/settings
{
"transient": {
"cluster.routing.allocation.enable": "none"
}
}
// Upgrade one node at a time
// After upgrade, re-enable allocation and wait for shard relocation
POST /_cluster/settings
{
"transient": {
"cluster.routing.allocation.enable": "all"
}
}
This snippet shows disabling shard allocation, upgrading nodes one by one, then re-enabling allocation to let shards move.
Look at what repeats during the upgrade.
- Primary operation: Upgrading each node sequentially.
- How many times: Once per node in the cluster.
As the number of nodes increases, the total upgrade time grows because each node is upgraded one after another.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 nodes | 10 upgrade steps |
| 100 nodes | 100 upgrade steps |
| 1000 nodes | 1000 upgrade steps |
Pattern observation: The total steps increase directly with the number of nodes.
Time Complexity: O(n)
This means the upgrade time grows linearly with the number of nodes in the cluster.
[X] Wrong: "Upgrading multiple nodes at once will always make the process faster without any risk."
[OK] Correct: Upgrading many nodes simultaneously can cause cluster instability and longer recovery times, which may slow down the overall process.
Understanding how rolling upgrades scale helps you explain real-world system maintenance and reliability, a key skill for managing distributed systems.
"What if we upgraded two nodes at the same time instead of one? How would the time complexity change?"
Practice
rolling upgrade in Elasticsearch?Solution
Step 1: Understand rolling upgrade concept
A rolling upgrade updates nodes one at a time to keep the cluster running.Step 2: Compare options
Only To upgrade nodes one by one without stopping the entire cluster describes upgrading nodes one by one without stopping the cluster.Final Answer:
To upgrade nodes one by one without stopping the entire cluster -> Option CQuick Check:
Rolling upgrade = upgrade nodes individually [OK]
- Thinking all nodes upgrade at once
- Confusing rolling upgrade with cluster shutdown
- Assuming data is deleted during upgrade
Solution
Step 1: Identify correct syntax to disable shard allocation
The correct way is to update cluster settings with PUT and set allocation to "none".Step 2: Check options
Only PUT /_cluster/settings {"persistent": {"cluster.routing.allocation.enable": "none"}} uses the correct HTTP method, endpoint, and JSON body.Final Answer:
PUT /_cluster/settings {"persistent": {"cluster.routing.allocation.enable": "none"}} -> Option AQuick Check:
Disable shard allocation = PUT cluster settings with allocation none [OK]
- Using wrong HTTP method like POST or GET
- Wrong endpoint or missing persistent key
- Trying to delete shards instead of disabling allocation
1. Disable shard allocation
2. Upgrade node 1
3. Upgrade node 2
4. Enable shard allocation
What is the expected cluster behavior after step 4?
Solution
Step 1: Understand shard allocation states
Disabling shard allocation prevents shard movement during upgrade; enabling it allows rebalancing.Step 2: Analyze cluster behavior after enabling allocation
After enabling, the cluster redistributes shards to balance load.Final Answer:
The cluster will rebalance shards across all nodes -> Option BQuick Check:
Enable allocation = rebalance shards [OK]
- Thinking cluster stops accepting data
- Assuming shards get deleted
- Believing shards remain stuck after enabling allocation
Solution
Step 1: Understand shard allocation role during upgrade
Disabling allocation prevents shards from moving and keeps data safe during node restarts.Step 2: Consequence of not disabling allocation
If not disabled, shards may relocate while nodes restart, risking data loss or cluster instability.Final Answer:
Shards may move during upgrade causing data loss or instability -> Option AQuick Check:
Not disabling allocation risks shard movement and instability [OK]
- Expecting upgrade to fail with syntax error
- Assuming cluster disables allocation automatically
- Thinking upgrade is safe without disabling allocation
Solution
Step 1: Identify correct upgrade steps
Best practice is to disable shard allocation first to prevent shard moves, then upgrade nodes one by one.Step 2: Finalize upgrade process
After upgrading all nodes, enable shard allocation to rebalance shards and verify cluster health to confirm stability.Final Answer:
Disable shard allocation -> Upgrade nodes one by one -> Enable shard allocation -> Verify cluster health -> Option DQuick Check:
Disable allocation, upgrade nodes, enable allocation, check health [OK]
- Upgrading all nodes at once causing downtime
- Enabling allocation before upgrade completion
- Restarting cluster unnecessarily
