Skip to content

[xray] Fix UniqueID hashing for object and task IDs. #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ray/constants.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/ray/id.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ray/id.h"

#include <limits.h>
#include <random>

#include "ray/constants.h"
Expand Down Expand Up @@ -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;
}

Expand Down