Skip to content

Commit 63d710d

Browse files
authored
TSDB: Do not allow index splits for time series indices (#81125)
Index _split operation may have some issues with time series indices, as the splits must respect and adjust the time boundaries. This PR forbids users to execute the split operation on time series indices, until we revisit this approach in the future.
1 parent 7dd32fb commit 63d710d

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/tsdb/80_index_resize.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
setup:
22
- skip:
3-
version: " - 7.99.99"
4-
reason: introduced in 8.0.0
3+
version: " - 8.00.99"
4+
reason: introduced in 8.1.0
55
features: "arbitrary_key"
66

77
# Force allocating all shards to a single node so that we can shrink later.
@@ -82,11 +82,11 @@ setup:
8282
---
8383
split:
8484
- skip:
85-
version: all
86-
reason: shard splitting doesn't work yet
87-
features: "arbitrary_key"
85+
version: " - 8.00.99"
86+
reason: index-split check introduced in 8.1.0
8887

8988
- do:
89+
catch: /index-split is not supported because the destination index \[test\] is in time series mode/
9090
indices.split:
9191
index: test
9292
target: test_split
@@ -95,19 +95,6 @@ split:
9595
index.number_of_replicas: 0
9696
index.number_of_shards: 6
9797

98-
- do:
99-
search:
100-
index: test_split
101-
body:
102-
fields:
103-
- field: _tsid
104-
query:
105-
query_string:
106-
query: '+@timestamp:"2021-04-28T18:51:04.467Z" +k8s.pod.name:cat'
107-
108-
- match: {hits.total.value: 1}
109-
- match: {hits.hits.0.fields._tsid: [{k8s.pod.uid: 947e4ced-1786-4e53-9e0c-5c447e959507, metricset: pod}]}
110-
11198
---
11299
shrink:
113100
- skip:

server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.cluster.metadata.IndexMetadata;
2828
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
2929
import org.elasticsearch.cluster.metadata.MetadataCreateIndexService;
30+
import org.elasticsearch.cluster.routing.IndexRouting;
3031
import org.elasticsearch.cluster.service.ClusterService;
3132
import org.elasticsearch.common.inject.Inject;
3233
import org.elasticsearch.common.settings.Settings;
@@ -124,6 +125,11 @@ protected void masterOperation(
124125
return;
125126
}
126127

128+
// Index splits are not allowed for time-series indices
129+
if (resizeRequest.getResizeType() == ResizeType.SPLIT) {
130+
IndexRouting.fromIndexMetadata(sourceMetadata).checkIndexSplitAllowed();
131+
}
132+
127133
IndicesStatsRequestBuilder statsRequestBuilder = client.admin()
128134
.indices()
129135
.prepareStats(sourceIndex)

server/src/main/java/org/elasticsearch/cluster/routing/IndexRouting.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ private static int effectiveRoutingToHash(String effectiveRouting) {
110110
return Murmur3HashFunction.hash(effectiveRouting);
111111
}
112112

113+
/**
114+
* Check if the _split index operation is allowed for an index
115+
* @throws IllegalArgumentException if the operation is not allowed
116+
*/
117+
public void checkIndexSplitAllowed() {}
118+
113119
private abstract static class IdAndRoutingOnly extends IndexRouting {
114120
private final boolean routingRequired;
115121

@@ -295,6 +301,11 @@ public int getShard(String id, @Nullable String routing) {
295301
throw new IllegalArgumentException(error("get"));
296302
}
297303

304+
@Override
305+
public void checkIndexSplitAllowed() {
306+
throw new IllegalArgumentException(error("index-split"));
307+
}
308+
298309
@Override
299310
public void collectSearchShards(String routing, IntConsumer consumer) {
300311
throw new IllegalArgumentException(error("searching with a specified routing"));

0 commit comments

Comments
 (0)