mirror of
https://github.com/wassname/ray.git
synced 2026-07-07 17:49:12 +08:00
[xray] Fix UniqueID hashing for object and task IDs. (#2017)
* Skip object prefix in UniqueIDHasher, choose shard based on hash * lint
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
#ifndef RAY_CONSTANTS_H_
|
||||
#define RAY_CONSTANTS_H_
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
/// Length of Ray IDs in bytes.
|
||||
constexpr int64_t kUniqueIDSize = 20;
|
||||
|
||||
/// An ObjectID's bytes are split into the task ID itself and the index of the
|
||||
/// object's creation. This is the maximum width of the object index in bits.
|
||||
constexpr int kObjectIdIndexSize = 32;
|
||||
static_assert(kObjectIdIndexSize % CHAR_BIT == 0,
|
||||
"ObjectID prefix not a multiple of bytes");
|
||||
|
||||
/// The maximum number of objects that can be returned by a task when finishing
|
||||
/// execution. An ObjectID's bytes are split into the task ID itself and the
|
||||
/// index of the object's creation. A positive index indicates an object
|
||||
|
||||
+3
-1
@@ -1,5 +1,6 @@
|
||||
#include "ray/id.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <random>
|
||||
|
||||
#include "ray/constants.h"
|
||||
@@ -83,7 +84,8 @@ bool UniqueID::operator==(const UniqueID &rhs) const {
|
||||
|
||||
size_t UniqueID::hash() const {
|
||||
size_t result;
|
||||
std::memcpy(&result, id_, sizeof(size_t));
|
||||
// Skip the bytes for the object prefix.
|
||||
std::memcpy(&result, id_ + (kObjectIdIndexSize / CHAR_BIT), sizeof(size_t));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user