Skip to content

Commit

Permalink
Fixing precommit, making nodeId optional in TaskId and addressing com…
Browse files Browse the repository at this point in the history
…ments

Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah committed Sep 6, 2023
1 parent f873f84 commit 7f6a1b6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
6 changes: 6 additions & 0 deletions libs/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ tasks.named("thirdPartyAudit").configure {
)
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${versions.protobuf}"
}
}

tasks.named("dependencyLicenses").configure {
mapping from: /jackson-.*/, to: 'jackson'
mapping from: /lucene-.*/, to: 'lucene'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import java.io.OutputStream;

/**
* Implementers can be written to a {@linkplain StreamOutput} and read from a {@linkplain StreamInput}. This allows them to be "thrown
* across the wire" using OpenSearch's internal protocol. If the implementer also implements equals and hashCode then a copy made by
* serializing and deserializing must be equal and have the same hashCode. It isn't required that such a copy be entirely unchanged.
* Implementers can be written to a {@linkplain OutputStream} and read from a {@linkplain byte[]}. This allows them to be "thrown
* across the wire" using OpenSearch's internal protocol with protobuf serialization/de-serialization.
*
* @opensearch.internal
*/
Expand All @@ -25,21 +24,6 @@ public interface ProtobufWriteable {
*/
void writeTo(OutputStream out) throws IOException;

/**
* Reference to a method that can write some object to a {@link OutputStream}.
*/
@FunctionalInterface
interface Writer<V> {

/**
* Write {@code V}-type {@code value} to the {@code out}put stream.
*
* @param out Output to write the {@code value} too
* @param value The value to add
*/
void write(final OutputStream out, V value) throws IOException;
}

/**
* Reference to a method that can read some object from a byte array stream.
*/
Expand Down
12 changes: 7 additions & 5 deletions libs/core/src/main/java/org/opensearch/core/tasks/TaskId.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public TaskId(String nodeId, long id) {
private TaskId() {
nodeId = "";
id = -1;
taskIdProto = TaskIdProto.TaskId.newBuilder().setNodeId(nodeId).setId(id).build();
taskIdProto = TaskIdProto.TaskId.newBuilder().setId(id).build();
}

public TaskId(String taskId) {
Expand All @@ -95,7 +95,7 @@ public TaskId(String taskId) {
} else {
nodeId = "";
id = -1L;
taskIdProto = TaskIdProto.TaskId.newBuilder().setNodeId(nodeId).setId(id).build();
taskIdProto = TaskIdProto.TaskId.newBuilder().setId(id).build();
}
}

Expand All @@ -121,15 +121,14 @@ public static TaskId readFromStream(StreamInput in) throws IOException {
*/
public static TaskId readFromBytes(byte[] in) throws IOException {
TaskIdProto.TaskId taskIdProto = TaskIdProto.TaskId.parseFrom(in);
String nodeId = taskIdProto.getNodeId();
if (nodeId.isEmpty()) {
if (!taskIdProto.hasNodeId()) {
/*
* The only TaskId allowed to have the empty string as its nodeId is the EMPTY_TASK_ID and there is only ever one of it and it
* never writes its taskId to save bytes on the wire because it is by far the most common TaskId.
*/
return EMPTY_TASK_ID;
}
return new TaskId(nodeId, taskIdProto.getId());
return new TaskId(taskIdProto.getNodeId(), taskIdProto.getId());
}

@Override
Expand All @@ -144,6 +143,9 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public void writeTo(OutputStream out) throws IOException {
if (!taskIdProto.hasNodeId()) {
return;
}
out.write(this.taskIdProto.toByteArray());
}

Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/main/proto/tasks/TaskIdProto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ package org.opensearch.core.tasks.proto;
option java_outer_classname = "TaskIdProto";

message TaskId {
string nodeId = 1;
optional string nodeId = 1;
int64 id = 2;
}

0 comments on commit 7f6a1b6

Please sign in to comment.