[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:
Stephanie Wang
2018-05-10 21:56:12 -07:00
committed by GitHub
parent 89e2eef3f3
commit a292d7ba32
2 changed files with 8 additions and 1 deletions
+5
View File
@@ -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
View File
@@ -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;
}