[ID Refactor] Shorten the length of JobID to 4 bytes (#5110)

* WIP

* Fix

* Add jobid test

* Fix

* Add python part

* Fix

* Fix tes

* Remove TODOs

* Fix C++ tests

* Lint

* Fix

* Fix exporting functions in multiple ray.init

* Fix java test

* Fix lint

* Fix linting

* Address comments.

* FIx

* Address and fix linting

* Refine and fix

* Fix

* address

* Address comments.

* Fix linting

* Fix

* Address

* Address comments.

* Address

* Address

* Fix

* Fix

* Fix

* Fix lint

* Fix

* Fix linting

* Address comments.

* Fix linting

* Address comments.

* Fix linting

* address comments.

* Fix
This commit is contained in:
Qing Wang
2019-07-11 14:25:16 +08:00
committed by GitHub
parent 88365d4112
commit f2293243cc
37 changed files with 385 additions and 132 deletions
@@ -0,0 +1,62 @@
package org.ray.api.id;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
/**
* Represents the id of a Ray job.
*/
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 JobId NIL = genNil();
/**
* Create a JobID instance according to the given bytes.
*/
private JobId(byte[] id) {
super(id);
}
/**
* Create a JobId from a given hex string.
*/
public static JobId fromHexString(String hex) {
return new JobId(hexString2Bytes(hex));
}
/**
* Creates a JobId from the given ByteBuffer.
*/
public static JobId fromByteBuffer(ByteBuffer bb) {
return new JobId(byteBuffer2Bytes(bb));
}
public static JobId fromInt(int value) {
byte[] bytes = new byte[JobId.LENGTH];
ByteBuffer wbb = ByteBuffer.wrap(bytes);
wbb.order(ByteOrder.LITTLE_ENDIAN);
wbb.putInt(value);
return new JobId(bytes);
}
/**
* Generate a nil JobId.
*/
private static JobId genNil() {
byte[] b = new byte[LENGTH];
Arrays.fill(b, (byte) 0xFF);
return new JobId(b);
}
@Override
public int size() {
return LENGTH;
}
}
@@ -1,6 +1,7 @@
package org.ray.api.runtimecontext;
import java.util.List;
import org.ray.api.id.JobId;
import org.ray.api.id.UniqueId;
/**
@@ -11,7 +12,7 @@ public interface RuntimeContext {
/**
* Get the current Job ID.
*/
UniqueId getCurrentJobId();
JobId getCurrentJobId();
/**
* Get the current actor ID.