mirror of
https://github.com/vale981/ray
synced 2025-03-06 02:21:39 -05:00
[Java] ID length fix (#6454)
This commit is contained in:
parent
f5d10eea0b
commit
cd250ba0bc
5 changed files with 28 additions and 14 deletions
|
@ -6,7 +6,10 @@ import java.util.Arrays;
|
|||
import java.util.Random;
|
||||
|
||||
public class ActorId extends BaseId implements Serializable {
|
||||
public static final int LENGTH = 8;
|
||||
|
||||
private static final int UNIQUE_BYTES_LENGTH = 4;
|
||||
|
||||
public static final int LENGTH = JobId.LENGTH + UNIQUE_BYTES_LENGTH;
|
||||
|
||||
public static final ActorId NIL = nil();
|
||||
|
||||
|
|
|
@ -10,10 +10,7 @@ import java.util.Arrays;
|
|||
*/
|
||||
public class JobId extends BaseId implements Serializable {
|
||||
|
||||
// Note that the max value of a job id is NIL which value is (2^32 - 1).
|
||||
public static final Long MAX_VALUE = (long) Math.pow(2, 32) - 1;
|
||||
|
||||
public static final int LENGTH = 4;
|
||||
public static final int LENGTH = 2;
|
||||
|
||||
public static final JobId NIL = genNil();
|
||||
|
||||
|
@ -39,11 +36,17 @@ public class JobId extends BaseId implements Serializable {
|
|||
}
|
||||
|
||||
public static JobId fromInt(int value) {
|
||||
byte[] bytes = new byte[JobId.LENGTH];
|
||||
if (value > Math.pow(256, JobId.LENGTH)) {
|
||||
throw new IllegalArgumentException(
|
||||
"The integer value is invalid for a JobId. Value: " + value);
|
||||
}
|
||||
byte[] bytes = new byte[Integer.BYTES];
|
||||
ByteBuffer wbb = ByteBuffer.wrap(bytes);
|
||||
wbb.order(ByteOrder.LITTLE_ENDIAN);
|
||||
wbb.putInt(value);
|
||||
return new JobId(bytes);
|
||||
wbb.flip();
|
||||
wbb.limit(JobId.LENGTH);
|
||||
return JobId.fromByteBuffer(wbb);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,16 +2,16 @@ package org.ray.api.id;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Represents the id of a Ray task.
|
||||
*/
|
||||
public class TaskId extends BaseId implements Serializable {
|
||||
|
||||
public static final int LENGTH = 14;
|
||||
private static final int UNIQUE_BYTES_LENGTH = 8;
|
||||
|
||||
public static final int LENGTH = ActorId.LENGTH + UNIQUE_BYTES_LENGTH;
|
||||
|
||||
public static final TaskId NIL = genNil();
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@ public class GcsClientTest extends BaseTest {
|
|||
public void testNextJob() {
|
||||
TestUtils.skipTestUnderSingleProcess();
|
||||
RayConfig config = TestUtils.getRuntime().getRayConfig();
|
||||
// The value of job id of this driver in cluster should be `1L`.
|
||||
// The value of job id of this driver in cluster should be 1.
|
||||
Assert.assertEquals(config.getJobId(), JobId.fromInt(1));
|
||||
|
||||
GcsClient gcsClient = TestUtils.getRuntime().getGcsClient();
|
||||
for (int i = 2; i < 100; ++i) {
|
||||
for (int i = 2; i < 100; ++i) {
|
||||
Assert.assertEquals(gcsClient.nextJobId(), JobId.fromInt(i));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package org.ray.api.test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import org.ray.api.Ray;
|
||||
import org.ray.api.RayActor;
|
||||
import org.ray.api.annotation.RayRemote;
|
||||
import org.ray.api.id.ActorId;
|
||||
import org.ray.api.id.JobId;
|
||||
import org.ray.api.id.UniqueId;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
@ -13,10 +14,17 @@ import org.testng.annotations.Test;
|
|||
|
||||
public class RuntimeContextTest extends BaseTest {
|
||||
|
||||
private static JobId JOB_ID = JobId.fromHexString("00112233");
|
||||
private static JobId JOB_ID = getJobId();
|
||||
private static String RAYLET_SOCKET_NAME = "/tmp/ray/test/raylet_socket";
|
||||
private static String OBJECT_STORE_SOCKET_NAME = "/tmp/ray/test/object_store_socket";
|
||||
|
||||
private static JobId getJobId() {
|
||||
// Must be stable across different processes.
|
||||
byte[] bytes = new byte[JobId.LENGTH];
|
||||
Arrays.fill(bytes, (byte) 127);
|
||||
return JobId.fromByteBuffer(ByteBuffer.wrap(bytes));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public void setUp() {
|
||||
System.setProperty("ray.job.id", JOB_ID.toString());
|
||||
|
|
Loading…
Add table
Reference in a new issue