From fe9c66096ca94f8729b9d589cf6442b9c4fe6f7d Mon Sep 17 00:00:00 2001 From: Mayya Sharipova Date: Mon, 31 Aug 2020 06:28:14 -0400 Subject: [PATCH] Small refactoring of AsyncExecutionId (#61640) - don't do encoding of asynchExecutionId if it is already provided in the encoded form - create a new instance of AsyncExecutionId after checks for correctness are done --- .../xpack/core/async/AsyncExecutionId.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/async/AsyncExecutionId.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/async/AsyncExecutionId.java index 6c2f891ff95..27ab0b02160 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/async/AsyncExecutionId.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/async/AsyncExecutionId.java @@ -25,9 +25,13 @@ public final class AsyncExecutionId { private final String encoded; public AsyncExecutionId(String docId, TaskId taskId) { + this(docId, taskId, encode(docId, taskId)); + } + + private AsyncExecutionId(String docId, TaskId taskId, String encoded) { this.docId = docId; this.taskId = taskId; - this.encoded = encode(docId, taskId); + this.encoded = encoded; } /** @@ -98,15 +102,17 @@ public final class AsyncExecutionId { } catch (Exception e) { throw new IllegalArgumentException("invalid id: [" + id + "]", e); } - final AsyncExecutionId searchId; + String docId; + String taskId; try (StreamInput in = new ByteBufferStreamInput(byteBuffer)) { - searchId = new AsyncExecutionId(in.readString(), new TaskId(in.readString())); + docId = in.readString(); + taskId = in.readString(); if (in.available() > 0) { throw new IllegalArgumentException("invalid id: [" + id + "]"); } } catch (IOException e) { throw new IllegalArgumentException("invalid id: [" + id + "]", e); } - return searchId; + return new AsyncExecutionId(docId, new TaskId(taskId), id); } }