Change behaviour of indices segments api to allow no indices
Using '_cat/segments' or the indices segments api without matching any index now returns empty result instead of throwing IndexMissingException. Closes #9219
This commit is contained in:
parent
de41981373
commit
41befaf6b5
|
@ -24,6 +24,14 @@
|
|||
---
|
||||
"Test cat segments output":
|
||||
|
||||
- do:
|
||||
cat.segments:
|
||||
v: false
|
||||
|
||||
- match:
|
||||
$body: |
|
||||
/^$/
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: index1
|
||||
|
@ -39,7 +47,7 @@
|
|||
refresh: true
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: yellow
|
||||
wait_for_status: green
|
||||
- do:
|
||||
cat.segments:
|
||||
v: false
|
||||
|
@ -57,7 +65,7 @@
|
|||
number_of_replicas: "0"
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: yellow
|
||||
wait_for_status: green
|
||||
wait_for_relocating_shards: 0
|
||||
|
||||
- do:
|
||||
|
@ -68,7 +76,7 @@
|
|||
refresh: true
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: yellow
|
||||
wait_for_status: green
|
||||
|
||||
|
||||
- do:
|
||||
|
@ -85,3 +93,28 @@
|
|||
- match:
|
||||
$body: |
|
||||
/^(index2 .+ \n?)$/
|
||||
|
||||
---
|
||||
"Test cat segments on closed index behaviour":
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: index1
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: "1"
|
||||
number_of_replicas: "0"
|
||||
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
- do:
|
||||
indices.close:
|
||||
index: index1
|
||||
|
||||
- do:
|
||||
catch: forbidden
|
||||
cat.segments:
|
||||
index: index1
|
||||
v: false
|
||||
|
|
|
@ -1,5 +1,75 @@
|
|||
---
|
||||
"segments test":
|
||||
"no segments test":
|
||||
- do:
|
||||
indices.segments:
|
||||
allow_no_indices: true
|
||||
|
||||
- match: { _shards.total: 0}
|
||||
- match: { indices: {}}
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
indices.segments:
|
||||
allow_no_indices: false
|
||||
|
||||
---
|
||||
"basic segments test":
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: index1
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: "1"
|
||||
number_of_replicas: "0"
|
||||
- do:
|
||||
index:
|
||||
index: index1
|
||||
type: type
|
||||
body: { foo: bar }
|
||||
refresh: true
|
||||
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
- do:
|
||||
indices.segments:
|
||||
index: index1
|
||||
|
||||
- match: { _shards.total: 1}
|
||||
- match: { indices.index1.shards.0.0.routing.primary: true}
|
||||
- match: { indices.index1.shards.0.0.segments._0.num_docs: 1}
|
||||
|
||||
---
|
||||
"closed segments test":
|
||||
|
||||
- do:
|
||||
indices.create:
|
||||
index: index1
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: "1"
|
||||
number_of_replicas: "0"
|
||||
- do:
|
||||
index:
|
||||
index: index1
|
||||
type: type
|
||||
body: { foo: bar }
|
||||
refresh: true
|
||||
|
||||
- do:
|
||||
indices.close:
|
||||
index: index1
|
||||
|
||||
- do:
|
||||
catch: forbidden
|
||||
indices.segments:
|
||||
index: index1
|
||||
|
||||
- do:
|
||||
indices.segments:
|
||||
index: index1
|
||||
ignore_unavailable: true
|
||||
|
||||
- match: { _shards.total: 0}
|
||||
|
|
|
@ -37,7 +37,6 @@ public class IndicesSegmentsRequest extends BroadcastOperationRequest<IndicesSeg
|
|||
|
||||
public IndicesSegmentsRequest(String... indices) {
|
||||
super(indices);
|
||||
indicesOptions(IndicesOptions.fromOptions(false, false, true, false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,11 +19,15 @@
|
|||
|
||||
package org.elasticsearch.action.admin.indices.segments;
|
||||
|
||||
import org.elasticsearch.action.ListenableActionFuture;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.engine.Segment;
|
||||
import org.elasticsearch.indices.IndexClosedException;
|
||||
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -56,4 +60,33 @@ public class IndicesSegmentsRequestTests extends ElasticsearchSingleNodeTest {
|
|||
List<Segment> segments = rsp.getIndices().get("test").iterator().next().getShards()[0].getSegments();
|
||||
assertNotNull(segments.get(0).ramTree);
|
||||
}
|
||||
|
||||
/**
|
||||
* with the default IndicesOptions inherited from BroadcastOperationRequest this will raise an exception
|
||||
*/
|
||||
@Test(expected=org.elasticsearch.indices.IndexClosedException.class)
|
||||
public void testRequestOnClosedIndex() {
|
||||
client().admin().indices().prepareClose("test").get();
|
||||
client().admin().indices().prepareSegments("test").get();
|
||||
}
|
||||
|
||||
/**
|
||||
* setting the "ignoreUnavailable" option prevents IndexClosedException
|
||||
*/
|
||||
public void testRequestOnClosedIndexIgnoreUnavailable() {
|
||||
client().admin().indices().prepareClose("test").get();
|
||||
IndicesOptions defaultOptions = new IndicesSegmentsRequest().indicesOptions();
|
||||
IndicesOptions testOptions = IndicesOptions.fromOptions(true, true, true, false, defaultOptions);
|
||||
IndicesSegmentResponse rsp = client().admin().indices().prepareSegments("test").setIndicesOptions(testOptions).get();
|
||||
assertEquals(0, rsp.getIndices().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* by default IndicesOptions setting IndicesSegmentsRequest should not throw exception when no index present
|
||||
*/
|
||||
public void testAllowNoIndex() {
|
||||
client().admin().indices().prepareDelete("test").get();
|
||||
IndicesSegmentResponse rsp = client().admin().indices().prepareSegments().get();
|
||||
assertEquals(0, rsp.getIndices().size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -362,7 +362,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest
|
|||
verify(count(indices), false);
|
||||
verify(clearCache(indices), false);
|
||||
verify(_flush(indices),false);
|
||||
verify(segments(indices), true);
|
||||
verify(segments(indices), false);
|
||||
verify(stats(indices), false);
|
||||
verify(optimize(indices), false);
|
||||
verify(refresh(indices), false);
|
||||
|
@ -437,7 +437,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest
|
|||
verify(count(indices), false, 1);
|
||||
verify(clearCache(indices), false);
|
||||
verify(_flush(indices),false);
|
||||
verify(segments(indices), true);
|
||||
verify(segments(indices), false);
|
||||
verify(stats(indices), false);
|
||||
verify(optimize(indices), false);
|
||||
verify(refresh(indices), false);
|
||||
|
|
Loading…
Reference in New Issue