use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.
the class IndexStatsIT method testMergeStats.
public void testMergeStats() {
createIndex("test1");
ensureGreen();
// clear all
IndicesStatsResponse stats = client().admin().indices().prepareStats().setDocs(false).setStore(false).setIndexing(false).setFlush(true).setRefresh(true).setMerge(true).clear().execute().actionGet();
assertThat(stats.getTotal().getDocs(), nullValue());
assertThat(stats.getTotal().getStore(), nullValue());
assertThat(stats.getTotal().getIndexing(), nullValue());
assertThat(stats.getTotal().getGet(), nullValue());
assertThat(stats.getTotal().getSearch(), nullValue());
for (int i = 0; i < 20; i++) {
client().prepareIndex("test1", "type1", Integer.toString(i)).setSource("field", "value").execute().actionGet();
client().prepareIndex("test1", "type2", Integer.toString(i)).setSource("field", "value").execute().actionGet();
client().admin().indices().prepareFlush().execute().actionGet();
}
client().admin().indices().prepareForceMerge().setMaxNumSegments(1).execute().actionGet();
stats = client().admin().indices().prepareStats().setMerge(true).execute().actionGet();
assertThat(stats.getTotal().getMerge(), notNullValue());
assertThat(stats.getTotal().getMerge().getTotal(), greaterThan(0L));
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.
the class IndexStatsIT method testFieldDataFieldsParam.
public void testFieldDataFieldsParam() throws Exception {
assertAcked(client().admin().indices().prepareCreate("test1").addMapping("type", "bar", "type=text,fielddata=true", "baz", "type=text,fielddata=true").get());
ensureGreen();
client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
refresh();
client().prepareSearch("_all").addSort("bar", SortOrder.ASC).addSort("baz", SortOrder.ASC).execute().actionGet();
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
IndicesStatsResponse stats = builder.execute().actionGet();
assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields(), is(nullValue()));
stats = builder.setFieldDataFields("bar").execute().actionGet();
assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields().containsField("bar"), is(true));
assertThat(stats.getTotal().fieldData.getFields().get("bar"), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields().containsField("baz"), is(false));
stats = builder.setFieldDataFields("bar", "baz").execute().actionGet();
assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields().containsField("bar"), is(true));
assertThat(stats.getTotal().fieldData.getFields().get("bar"), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields().containsField("baz"), is(true));
assertThat(stats.getTotal().fieldData.getFields().get("baz"), greaterThan(0L));
stats = builder.setFieldDataFields("*").execute().actionGet();
assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields().containsField("bar"), is(true));
assertThat(stats.getTotal().fieldData.getFields().get("bar"), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields().containsField("baz"), is(true));
assertThat(stats.getTotal().fieldData.getFields().get("baz"), greaterThan(0L));
stats = builder.setFieldDataFields("*r").execute().actionGet();
assertThat(stats.getTotal().fieldData.getMemorySizeInBytes(), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields().containsField("bar"), is(true));
assertThat(stats.getTotal().fieldData.getFields().get("bar"), greaterThan(0L));
assertThat(stats.getTotal().fieldData.getFields().containsField("baz"), is(false));
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.
the class IndexStatsIT method testFieldDataStats.
public void testFieldDataStats() {
assertAcked(client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 2)).addMapping("type", "field", "type=text,fielddata=true", "field2", "type=text,fielddata=true").get());
ensureGreen();
client().prepareIndex("test", "type", "1").setSource("field", "value1", "field2", "value1").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("field", "value2", "field2", "value2").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
NodesStatsResponse nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0L));
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), equalTo(0L));
// sort to load it to field data...
client().prepareSearch().addSort("field", SortOrder.ASC).execute().actionGet();
client().prepareSearch().addSort("field", SortOrder.ASC).execute().actionGet();
nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
// sort to load it to field data...
client().prepareSearch().addSort("field2", SortOrder.ASC).execute().actionGet();
client().prepareSearch().addSort("field2", SortOrder.ASC).execute().actionGet();
// now check the per field stats
nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(new CommonStatsFlags().set(CommonStatsFlags.Flag.FieldData, true).fieldDataFields("*")).execute().actionGet();
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getFields().get("field") + nodesStats.getNodes().get(1).getIndices().getFieldData().getFields().get("field"), greaterThan(0L));
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getFields().get("field") + nodesStats.getNodes().get(1).getIndices().getFieldData().getFields().get("field"), lessThan(nodesStats.getNodes().get(0).getIndices().getFieldData().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getFieldData().getMemorySizeInBytes()));
indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).setFieldDataFields("*").execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
assertThat(indicesStats.getTotal().getFieldData().getFields().get("field"), greaterThan(0L));
assertThat(indicesStats.getTotal().getFieldData().getFields().get("field"), lessThan(indicesStats.getTotal().getFieldData().getMemorySizeInBytes()));
client().admin().indices().prepareClearCache().setFieldDataCache(true).execute().actionGet();
nodesStats = client().admin().cluster().prepareNodesStats("data:true").setIndices(true).execute().actionGet();
assertThat(nodesStats.getNodes().get(0).getIndices().getFieldData().getMemorySizeInBytes() + nodesStats.getNodes().get(1).getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0L));
indicesStats = client().admin().indices().prepareStats("test").clear().setFieldData(true).execute().actionGet();
assertThat(indicesStats.getTotal().getFieldData().getMemorySizeInBytes(), equalTo(0L));
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project elasticsearch by elastic.
the class IndexStatsIT method testConcurrentIndexingAndStatsRequests.
/**
* Test that we can safely concurrently index and get stats. This test was inspired by a serialization issue that arose due to a race
* getting doc stats during heavy indexing. The race could lead to deleted docs being negative which would then be serialized as a
* variable-length long. Since serialization of negative longs using a variable-length format was unsupported
* ({@link org.elasticsearch.common.io.stream.StreamOutput#writeVLong(long)}), the stream would become corrupted. Here, we want to test
* that we can continue to get stats while indexing.
*/
public void testConcurrentIndexingAndStatsRequests() throws BrokenBarrierException, InterruptedException, ExecutionException {
final AtomicInteger idGenerator = new AtomicInteger();
final int numberOfIndexingThreads = Runtime.getRuntime().availableProcessors();
final int numberOfStatsThreads = 4 * numberOfIndexingThreads;
final CyclicBarrier barrier = new CyclicBarrier(1 + numberOfIndexingThreads + numberOfStatsThreads);
final AtomicBoolean stop = new AtomicBoolean();
final List<Thread> threads = new ArrayList<>(numberOfIndexingThreads + numberOfIndexingThreads);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean failed = new AtomicBoolean();
final AtomicReference<List<ShardOperationFailedException>> shardFailures = new AtomicReference<>(new CopyOnWriteArrayList<>());
final AtomicReference<List<Exception>> executionFailures = new AtomicReference<>(new CopyOnWriteArrayList<>());
// increasing the number of shards increases the number of chances any one stats request will hit a race
final CreateIndexRequest createIndexRequest = new CreateIndexRequest("test", Settings.builder().put("index.number_of_shards", 10).build());
client().admin().indices().create(createIndexRequest).get();
// start threads that will index concurrently with stats requests
for (int i = 0; i < numberOfIndexingThreads; i++) {
final Thread thread = new Thread(() -> {
try {
barrier.await();
} catch (final BrokenBarrierException | InterruptedException e) {
failed.set(true);
executionFailures.get().add(e);
latch.countDown();
}
while (!stop.get()) {
final String id = Integer.toString(idGenerator.incrementAndGet());
final IndexResponse response = client().prepareIndex("test", "type", id).setSource("{}", XContentType.JSON).get();
assertThat(response.getResult(), equalTo(DocWriteResponse.Result.CREATED));
}
});
thread.setName("indexing-" + i);
threads.add(thread);
thread.start();
}
// start threads that will get stats concurrently with indexing
for (int i = 0; i < numberOfStatsThreads; i++) {
final Thread thread = new Thread(() -> {
try {
barrier.await();
} catch (final BrokenBarrierException | InterruptedException e) {
failed.set(true);
executionFailures.get().add(e);
latch.countDown();
}
final IndicesStatsRequest request = new IndicesStatsRequest();
request.all();
request.indices(new String[0]);
while (!stop.get()) {
try {
final IndicesStatsResponse response = client().admin().indices().stats(request).get();
if (response.getFailedShards() > 0) {
failed.set(true);
shardFailures.get().addAll(Arrays.asList(response.getShardFailures()));
latch.countDown();
}
} catch (final ExecutionException | InterruptedException e) {
failed.set(true);
executionFailures.get().add(e);
latch.countDown();
}
}
});
thread.setName("stats-" + i);
threads.add(thread);
thread.start();
}
// release the hounds
barrier.await();
// wait for a failure, or for fifteen seconds to elapse
latch.await(15, TimeUnit.SECONDS);
// stop all threads and wait for them to complete
stop.set(true);
for (final Thread thread : threads) {
thread.join();
}
assertThat(shardFailures.get(), emptyCollectionOf(ShardOperationFailedException.class));
assertThat(executionFailures.get(), emptyCollectionOf(Exception.class));
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project graylog2-server by Graylog2.
the class Indices method getAll.
public Map<String, IndexStats> getAll(final IndexSet indexSet) {
final IndicesStatsRequest request = c.admin().indices().prepareStats(indexSet.getIndexWildcard()).request();
final IndicesStatsResponse response = c.admin().indices().stats(request).actionGet();
if (response.getFailedShards() > 0) {
LOG.warn("IndexStats response contains failed shards, response is incomplete: {}", (Object) response.getShardFailures());
}
return response.getIndices();
}
Aggregations