Add details to BulkShardRequest#getDescription() (#41711)

Today a bulk shard request appears as follows in the detailed task list:

    requests[42], index[my_index]

This change adds the shard index and refresh policy too:

    requests[42], index[my_index][2], refresh[IMMEDIATE]
This commit is contained in:
David Turner 2019-05-02 08:27:45 +02:00 committed by David Turner
parent 81163455a8
commit b189596631
3 changed files with 12 additions and 4 deletions

View File

@ -115,7 +115,12 @@ public class BulkShardRequest extends ReplicatedWriteRequest<BulkShardRequest> {
@Override
public String getDescription() {
return "requests[" + items.length + "], index[" + index + "]";
final StringBuilder stringBuilder = new StringBuilder().append("requests[").append(items.length).append("], index").append(shardId);
final RefreshPolicy refreshPolicy = getRefreshPolicy();
if (refreshPolicy == RefreshPolicy.IMMEDIATE || refreshPolicy == RefreshPolicy.WAIT_UNTIL) {
stringBuilder.append(", refresh[").append(refreshPolicy).append(']');
}
return stringBuilder.toString();
}
@Override

View File

@ -320,22 +320,20 @@ public class TasksIT extends ESIntegTestCase {
shardTask = shardTasks.get(0);
// and it should have the main task as a parent
assertParentTask(shardTask, findEvents(BulkAction.NAME, Tuple::v1).get(0));
assertEquals("requests[1], index[test]", shardTask.getDescription());
} else {
if (shardTasks.get(0).getParentTaskId().equals(shardTasks.get(1).getTaskId())) {
// task 1 is the parent of task 0, that means that task 0 will control [s][p] and [s][r] tasks
shardTask = shardTasks.get(0);
// in turn the parent of the task 1 should be the main task
assertParentTask(shardTasks.get(1), findEvents(BulkAction.NAME, Tuple::v1).get(0));
assertEquals("requests[1], index[test]", shardTask.getDescription());
} else {
// otherwise task 1 will control [s][p] and [s][r] tasks
shardTask = shardTasks.get(1);
// in turn the parent of the task 0 should be the main task
assertParentTask(shardTasks.get(0), findEvents(BulkAction.NAME, Tuple::v1).get(0));
assertEquals("requests[1], index[test]", shardTask.getDescription());
}
}
assertThat(shardTask.getDescription(), startsWith("requests[1], index[test]["));
// we should also get one [s][p] operation with shard operation as a parent
assertEquals(1, numberOfEvents(BulkAction.NAME + "[s][p]", Tuple::v1));

View File

@ -32,9 +32,14 @@ public class BulkShardRequestTests extends ESTestCase {
final ShardId shardId = new ShardId(index, "ignored", 0);
BulkShardRequest r = new BulkShardRequest(shardId, RefreshPolicy.NONE, new BulkItemRequest[count]);
assertEquals("BulkShardRequest [" + shardId + "] containing [" + count + "] requests", r.toString());
assertEquals("requests[" + count + "], index[" + index + "][0]", r.getDescription());
r = new BulkShardRequest(shardId, RefreshPolicy.IMMEDIATE, new BulkItemRequest[count]);
assertEquals("BulkShardRequest [" + shardId + "] containing [" + count + "] requests and a refresh", r.toString());
assertEquals("requests[" + count + "], index[" + index + "][0], refresh[IMMEDIATE]", r.getDescription());
r = new BulkShardRequest(shardId, RefreshPolicy.WAIT_UNTIL, new BulkItemRequest[count]);
assertEquals("BulkShardRequest [" + shardId + "] containing [" + count + "] requests blocking until refresh", r.toString());
assertEquals("requests[" + count + "], index[" + index + "][0], refresh[WAIT_UNTIL]", r.getDescription());
}
}