Skip to content

Commit b189596

Browse files
committed
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]
1 parent 8116345 commit b189596

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

server/src/main/java/org/elasticsearch/action/bulk/BulkShardRequest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ public String toString() {
115115

116116
@Override
117117
public String getDescription() {
118-
return "requests[" + items.length + "], index[" + index + "]";
118+
final StringBuilder stringBuilder = new StringBuilder().append("requests[").append(items.length).append("], index").append(shardId);
119+
final RefreshPolicy refreshPolicy = getRefreshPolicy();
120+
if (refreshPolicy == RefreshPolicy.IMMEDIATE || refreshPolicy == RefreshPolicy.WAIT_UNTIL) {
121+
stringBuilder.append(", refresh[").append(refreshPolicy).append(']');
122+
}
123+
return stringBuilder.toString();
119124
}
120125

121126
@Override

server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,22 +320,20 @@ public void testTransportBulkTasks() {
320320
shardTask = shardTasks.get(0);
321321
// and it should have the main task as a parent
322322
assertParentTask(shardTask, findEvents(BulkAction.NAME, Tuple::v1).get(0));
323-
assertEquals("requests[1], index[test]", shardTask.getDescription());
324323
} else {
325324
if (shardTasks.get(0).getParentTaskId().equals(shardTasks.get(1).getTaskId())) {
326325
// task 1 is the parent of task 0, that means that task 0 will control [s][p] and [s][r] tasks
327326
shardTask = shardTasks.get(0);
328327
// in turn the parent of the task 1 should be the main task
329328
assertParentTask(shardTasks.get(1), findEvents(BulkAction.NAME, Tuple::v1).get(0));
330-
assertEquals("requests[1], index[test]", shardTask.getDescription());
331329
} else {
332330
// otherwise task 1 will control [s][p] and [s][r] tasks
333331
shardTask = shardTasks.get(1);
334332
// in turn the parent of the task 0 should be the main task
335333
assertParentTask(shardTasks.get(0), findEvents(BulkAction.NAME, Tuple::v1).get(0));
336-
assertEquals("requests[1], index[test]", shardTask.getDescription());
337334
}
338335
}
336+
assertThat(shardTask.getDescription(), startsWith("requests[1], index[test]["));
339337

340338
// we should also get one [s][p] operation with shard operation as a parent
341339
assertEquals(1, numberOfEvents(BulkAction.NAME + "[s][p]", Tuple::v1));

server/src/test/java/org/elasticsearch/action/bulk/BulkShardRequestTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ public void testToString() {
3232
final ShardId shardId = new ShardId(index, "ignored", 0);
3333
BulkShardRequest r = new BulkShardRequest(shardId, RefreshPolicy.NONE, new BulkItemRequest[count]);
3434
assertEquals("BulkShardRequest [" + shardId + "] containing [" + count + "] requests", r.toString());
35+
assertEquals("requests[" + count + "], index[" + index + "][0]", r.getDescription());
36+
3537
r = new BulkShardRequest(shardId, RefreshPolicy.IMMEDIATE, new BulkItemRequest[count]);
3638
assertEquals("BulkShardRequest [" + shardId + "] containing [" + count + "] requests and a refresh", r.toString());
39+
assertEquals("requests[" + count + "], index[" + index + "][0], refresh[IMMEDIATE]", r.getDescription());
40+
3741
r = new BulkShardRequest(shardId, RefreshPolicy.WAIT_UNTIL, new BulkItemRequest[count]);
3842
assertEquals("BulkShardRequest [" + shardId + "] containing [" + count + "] requests blocking until refresh", r.toString());
43+
assertEquals("requests[" + count + "], index[" + index + "][0], refresh[WAIT_UNTIL]", r.getDescription());
3944
}
4045
}

0 commit comments

Comments
 (0)