Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.ray.runtime.task.ArgumentsBuilder;
import org.ray.runtime.task.TaskSpec;
import org.ray.runtime.util.ResourceUtil;
import org.ray.runtime.util.UniqueIdHelper;
import org.ray.runtime.util.UniqueIdUtil;
import org.ray.runtime.util.exception.TaskExecutionException;
import org.ray.runtime.util.logger.RayLog;

Expand Down Expand Up @@ -63,7 +63,7 @@ public AbstractRayRuntime(RayConfig rayConfig) {

@Override
public <T> RayObject<T> put(T obj) {
UniqueId objectId = UniqueIdHelper.computePutId(
UniqueId objectId = UniqueIdUtil.computePutId(
workerContext.getCurrentTask().taskId, workerContext.nextPutIndex());

put(objectId, obj);
Expand Down Expand Up @@ -222,7 +222,7 @@ public <T> RayActor<T> createActor(RayFunc actorFactoryFunc, Object[] args) {
private UniqueId[] genReturnIds(UniqueId taskId, int numReturns) {
UniqueId[] ret = new UniqueId[numReturns];
for (int i = 0; i < numReturns; i++) {
ret[i] = UniqueIdHelper.computeReturnId(taskId, i + 1);
ret[i] = UniqueIdUtil.computeReturnId(taskId, i + 1);
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.ray.api.id.UniqueId;
import org.ray.runtime.AbstractRayRuntime;
import org.ray.runtime.util.Serializer;
import org.ray.runtime.util.UniqueIdUtil;
import org.ray.runtime.util.exception.TaskExecutionException;

/**
Expand All @@ -15,9 +16,10 @@
*/
public class ObjectStoreProxy {

private static final int GET_TIMEOUT_MS = 1000;

private final AbstractRayRuntime runtime;
private final ObjectStoreLink store;
private final int getTimeoutMs = 1000;

public ObjectStoreProxy(AbstractRayRuntime runtime, ObjectStoreLink store) {
this.runtime = runtime;
Expand All @@ -26,7 +28,7 @@ public ObjectStoreProxy(AbstractRayRuntime runtime, ObjectStoreLink store) {

public <T> Pair<T, GetStatus> get(UniqueId objectId, boolean isMetadata)
throws TaskExecutionException {
return get(objectId, getTimeoutMs, isMetadata);
return get(objectId, GET_TIMEOUT_MS, isMetadata);
}

public <T> Pair<T, GetStatus> get(UniqueId id, int timeoutMs, boolean isMetadata)
Expand All @@ -46,12 +48,12 @@ public <T> Pair<T, GetStatus> get(UniqueId id, int timeoutMs, boolean isMetadata

public <T> List<Pair<T, GetStatus>> get(List<UniqueId> objectIds, boolean isMetadata)
throws TaskExecutionException {
return get(objectIds, getTimeoutMs, isMetadata);
return get(objectIds, GET_TIMEOUT_MS, isMetadata);
}

public <T> List<Pair<T, GetStatus>> get(List<UniqueId> ids, int timeoutMs, boolean isMetadata)
throws TaskExecutionException {
List<byte[]> objs = store.get(getIdBytes(ids), timeoutMs, isMetadata);
List<byte[]> objs = store.get(UniqueIdUtil.getIdBytes(ids), timeoutMs, isMetadata);
List<Pair<T, GetStatus>> ret = new ArrayList<>();
for (int i = 0; i < objs.size(); i++) {
byte[] obj = objs.get(i);
Expand All @@ -69,15 +71,6 @@ public <T> List<Pair<T, GetStatus>> get(List<UniqueId> ids, int timeoutMs, boole
return ret;
}

private static byte[][] getIdBytes(List<UniqueId> objectIds) {
int size = objectIds.size();
byte[][] ids = new byte[size][];
for (int i = 0; i < size; i++) {
ids[i] = objectIds.get(i).getBytes();
}
return ids;
}

public void put(UniqueId id, Object obj, Object metadata) {
store.put(id.getBytes(), Serializer.encode(obj), Serializer.encode(metadata));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.ray.runtime.generated.TaskLanguage;
import org.ray.runtime.task.FunctionArg;
import org.ray.runtime.task.TaskSpec;
import org.ray.runtime.util.UniqueIdHelper;
import org.ray.runtime.util.UniqueIdUtil;
import org.ray.runtime.util.logger.RayLog;

public class RayletClientImpl implements RayletClient {
Expand Down Expand Up @@ -50,7 +50,8 @@ public <T> WaitResult<T> wait(List<RayObject<T>> waitFor, int numReturns, int ti
ids.add(element.getId());
}

boolean[] ready = nativeWaitObject(client, getIdBytes(ids), numReturns, timeoutMs, false);
boolean[] ready = nativeWaitObject(client, UniqueIdUtil.getIdBytes(ids),
numReturns, timeoutMs, false);
List<RayObject<T>> readyList = new ArrayList<>();
List<RayObject<T>> unreadyList = new ArrayList<>();

Expand Down Expand Up @@ -89,9 +90,9 @@ public TaskSpec getTask() {
public void reconstructObjects(List<UniqueId> objectIds, boolean fetchOnly) {
if (RayLog.core.isInfoEnabled()) {
RayLog.core.info("Reconstructing objects for task {}, object IDs are {}",
UniqueIdHelper.computeTaskId(objectIds.get(0)), objectIds);
UniqueIdUtil.computeTaskId(objectIds.get(0)), objectIds);
}
nativeReconstructObjects(client, getIdBytes(objectIds), fetchOnly);
nativeReconstructObjects(client, UniqueIdUtil.getIdBytes(objectIds), fetchOnly);
}

@Override
Expand All @@ -107,7 +108,7 @@ public void notifyUnblocked() {

@Override
public void freePlasmaObjects(List<UniqueId> objectIds, boolean localOnly) {
byte[][] objectIdsArray = getIdBytes(objectIds);
byte[][] objectIdsArray = UniqueIdUtil.getIdBytes(objectIds);
nativeFreePlasmaObjects(client, objectIdsArray, localOnly);
}

Expand Down Expand Up @@ -242,15 +243,6 @@ private static ByteBuffer convertTaskSpecToFlatbuffer(TaskSpec task) {
return buffer;
}

private static byte[][] getIdBytes(List<UniqueId> objectIds) {
int size = objectIds.size();
byte[][] ids = new byte[size][];
for (int i = 0; i < size; i++) {
ids[i] = objectIds.get(i).getBytes();
}
return ids;
}

public void destroy() {
nativeDestroy(client);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.List;

import org.ray.api.id.UniqueId;


Expand All @@ -11,7 +13,7 @@
* Note: any changes to these methods must be synced with C++ helper functions
* in src/ray/id.h
*/
public class UniqueIdHelper {
public class UniqueIdUtil {
public static final int OBJECT_INDEX_POS = 0;
public static final int OBJECT_INDEX_LENGTH = 4;

Expand All @@ -37,7 +39,7 @@ private static UniqueId computeObjectId(UniqueId taskId, int index) {
System.arraycopy(taskId.getBytes(),0, objId, 0, UniqueId.LENGTH);
ByteBuffer wbb = ByteBuffer.wrap(objId);
wbb.order(ByteOrder.LITTLE_ENDIAN);
wbb.putInt(UniqueIdHelper.OBJECT_INDEX_POS, index);
wbb.putInt(UniqueIdUtil.OBJECT_INDEX_POS, index);

return new UniqueId(objId);
}
Expand All @@ -63,9 +65,18 @@ public static UniqueId computePutId(UniqueId taskId, int putIndex) {
public static UniqueId computeTaskId(UniqueId objectId) {
byte[] taskId = new byte[UniqueId.LENGTH];
System.arraycopy(objectId.getBytes(), 0, taskId, 0, UniqueId.LENGTH);
Arrays.fill(taskId, UniqueIdHelper.OBJECT_INDEX_POS,
UniqueIdHelper.OBJECT_INDEX_POS + UniqueIdHelper.OBJECT_INDEX_LENGTH, (byte) 0);
Arrays.fill(taskId, UniqueIdUtil.OBJECT_INDEX_POS,
UniqueIdUtil.OBJECT_INDEX_POS + UniqueIdUtil.OBJECT_INDEX_LENGTH, (byte) 0);

return new UniqueId(taskId);
}

public static byte[][] getIdBytes(List<UniqueId> objectIds) {
int size = objectIds.size();
byte[][] ids = new byte[size][];
for (int i = 0; i < size; i++) {
ids[i] = objectIds.get(i).getBytes();
}
return ids;
}
}
13 changes: 6 additions & 7 deletions java/test/src/main/java/org/ray/api/test/UniqueIdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import javax.xml.bind.DatatypeConverter;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.id.UniqueId;
import org.ray.runtime.util.UniqueIdHelper;
import org.ray.runtime.util.UniqueIdUtil;

public class UniqueIdTest {

Expand Down Expand Up @@ -53,17 +52,17 @@ public void testComputeReturnId() {
// Mock a taskId, and the lowest 4 bytes should be 0.
UniqueId taskId = UniqueId.fromHexString("00000000123456789ABCDEF123456789ABCDEF00");

UniqueId returnId = UniqueIdHelper.computeReturnId(taskId, 1);
UniqueId returnId = UniqueIdUtil.computeReturnId(taskId, 1);
Assert.assertEquals("01000000123456789abcdef123456789abcdef00", returnId.toString());

returnId = UniqueIdHelper.computeReturnId(taskId, 0x01020304);
returnId = UniqueIdUtil.computeReturnId(taskId, 0x01020304);
Assert.assertEquals("04030201123456789abcdef123456789abcdef00", returnId.toString());
}

@Test
public void testComputeTaskId() {
UniqueId objId = UniqueId.fromHexString("34421980123456789ABCDEF123456789ABCDEF00");
UniqueId taskId = UniqueIdHelper.computeTaskId(objId);
UniqueId taskId = UniqueIdUtil.computeTaskId(objId);

Assert.assertEquals("00000000123456789abcdef123456789abcdef00", taskId.toString());
}
Expand All @@ -73,10 +72,10 @@ public void testComputePutId() {
// Mock a taskId, the lowest 4 bytes should be 0.
UniqueId taskId = UniqueId.fromHexString("00000000123456789ABCDEF123456789ABCDEF00");

UniqueId putId = UniqueIdHelper.computePutId(taskId, 1);
UniqueId putId = UniqueIdUtil.computePutId(taskId, 1);
Assert.assertEquals("FFFFFFFF123456789ABCDEF123456789ABCDEF00".toLowerCase(), putId.toString());

putId = UniqueIdHelper.computePutId(taskId, 0x01020304);
putId = UniqueIdUtil.computePutId(taskId, 0x01020304);
Assert.assertEquals("FCFCFDFE123456789ABCDEF123456789ABCDEF00".toLowerCase(), putId.toString());
}

Expand Down