Skip to content

Commit 708c068

Browse files
authored
Explain why Elasticsearch doesn't support incremental resharding. (#29082)
I have seen this question a couple times already, most recently at https://twitter.com/dimosr7/status/973872744965332993 I tried to keep the explanation as simple as I could, which is not always easy as this is a matter of trade-offs.
1 parent 158bb23 commit 708c068

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

docs/reference/indices/split-index.asciidoc

+33-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ index may by split into an arbitrary number of shards greater than 1. The
3131
properties of the default number of routing shards will then apply to the
3232
newly split index.
3333

34+
[float]
35+
=== How does splitting work?
3436

3537
Splitting works as follows:
3638

@@ -47,6 +49,36 @@ Splitting works as follows:
4749
* Finally, it recovers the target index as though it were a closed index which
4850
had just been re-opened.
4951

52+
[float]
53+
=== Why doesn't Elasticsearch support incremental resharding?
54+
55+
Going from `N` shards to `N+1` shards, aka. incremental resharding, is indeed a
56+
feature that is supported by many key-value stores. Adding a new shard and
57+
pushing new data to this new shard only is not an option: this would likely be
58+
an indexing bottleneck, and figuring out which shard a document belongs to
59+
given its `_id`, which is necessary for get, delete and update requests, would
60+
become quite complex. This means that we need to rebalance existing data using
61+
a different hashing scheme.
62+
63+
The most common way that key-value stores do this efficiently is by using
64+
consistent hashing. Consistent hashing only requires `1/N`-th of the keys to
65+
be relocated when growing the number of shards from `N` to `N+1`. However
66+
Elasticsearch's unit of storage, shards, are Lucene indices. Because of their
67+
search-oriented data structure, taking a significant portion of a Lucene index,
68+
be it only 5% of documents, deleting them and indexing them on another shard
69+
typically comes with a much higher cost than with a key-value store. This cost
70+
is kept reasonable when growing the number of shards by a multiplicative factor
71+
as described in the above section: this allows Elasticsearch to perform the
72+
split locally, which in-turn allows to perform the split at the index level
73+
rather than reindexing documents that need to move, as well as using hard links
74+
for efficient file copying.
75+
76+
In the case of append-only data, it is possible to get more flexibility by
77+
creating a new index and pushing new data to it, while adding an alias that
78+
covers both the old and the new index for read operations. Assuming that the
79+
old and new indices have respectively +M+ and +N+ shards, this has no overhead
80+
compared to searching an index that would have +M+N+ shards.
81+
5082
[float]
5183
=== Preparing an index for splitting
5284

@@ -171,4 +203,4 @@ replicas and may decide to relocate the primary shard to another node.
171203

172204
Because the split operation creates a new index to split the shards to,
173205
the <<create-index-wait-for-active-shards,wait for active shards>> setting
174-
on index creation applies to the split index action as well.
206+
on index creation applies to the split index action as well.

0 commit comments

Comments
 (0)