From 94beb5eb3d9f804cbfe14904dce3552cb3e652ac Mon Sep 17 00:00:00 2001 From: Larry <554538252@qq.com> Date: Tue, 24 Oct 2023 19:51:56 +0800 Subject: [PATCH] [Core]Fix NullPointerException cause by raylet id is empty when get actor info in java worker (#40560) ## Why are these changes needed? Fix NullPointerException cause by raylet id is empty when get actor info in java worker. Calling get actor info API before the Actor is successfully scheduled will result in a NullPointerException. ![image](https://github.com/ray-project/ray/assets/11072802/a25f4728-ca8a-4841-b912-4ca757437dc2) --- .../src/main/java/io/ray/runtime/gcs/GcsClient.java | 11 +++++++---- .../java/io/ray/runtime/gcs/GlobalStateAccessor.java | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/java/runtime/src/main/java/io/ray/runtime/gcs/GcsClient.java b/java/runtime/src/main/java/io/ray/runtime/gcs/GcsClient.java index 3182825063e15..aa412cb57b206 100644 --- a/java/runtime/src/main/java/io/ray/runtime/gcs/GcsClient.java +++ b/java/runtime/src/main/java/io/ray/runtime/gcs/GcsClient.java @@ -120,16 +120,19 @@ public List getAllActorInfo(JobId jobId, ActorState actorState) { result -> { try { Gcs.ActorTableData info = Gcs.ActorTableData.parseFrom(result); + UniqueId nodeId = UniqueId.NIL; + if (!info.getAddress().getRayletId().isEmpty()) { + nodeId = + UniqueId.fromByteBuffer( + ByteBuffer.wrap(info.getAddress().getRayletId().toByteArray())); + } actorInfos.add( new ActorInfo( ActorId.fromBytes(info.getActorId().toByteArray()), ActorState.fromValue(info.getState().getNumber()), info.getNumRestarts(), new Address( - UniqueId.fromByteBuffer( - ByteBuffer.wrap(info.getAddress().getRayletId().toByteArray())), - info.getAddress().getIpAddress(), - info.getAddress().getPort()), + nodeId, info.getAddress().getIpAddress(), info.getAddress().getPort()), info.getName())); } catch (InvalidProtocolBufferException e) { throw new RayException("Failed to parse actor info.", e); diff --git a/java/runtime/src/main/java/io/ray/runtime/gcs/GlobalStateAccessor.java b/java/runtime/src/main/java/io/ray/runtime/gcs/GlobalStateAccessor.java index 80777820bfb6d..8f79bfe343cd3 100644 --- a/java/runtime/src/main/java/io/ray/runtime/gcs/GlobalStateAccessor.java +++ b/java/runtime/src/main/java/io/ray/runtime/gcs/GlobalStateAccessor.java @@ -161,7 +161,7 @@ private void destroyGlobalStateAccessor() { private native List nativeGetAllNodeInfo(long nativePtr); private native List nativeGetAllActorInfo( - long nativePtr, byte[] jobId, String actor_state_name); + long nativePtr, byte[] jobId, String actorStateName); private native byte[] nativeGetActorInfo(long nativePtr, byte[] actorId);