-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
88365d4
commit f229324
Showing
37 changed files
with
386 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.