mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
Convert UniqueID::nil() to a constructor (#3564)
* Initialize UniqueID to nil * Return reference to static const variable
This commit is contained in:
parent
75ddf7cca4
commit
26ca40817e
10 changed files with 26 additions and 39 deletions
|
@ -121,7 +121,7 @@ Status Log<ID, Data>::Subscribe(const JobID &job_id, const ClientID &client_id,
|
|||
if (subscribe != nullptr) {
|
||||
// Parse the notification.
|
||||
auto root = flatbuffers::GetRoot<GcsTableEntry>(data.data());
|
||||
ID id = UniqueID::nil();
|
||||
ID id;
|
||||
if (root->id()->size() > 0) {
|
||||
id = from_flatbuf(*root->id());
|
||||
}
|
||||
|
|
|
@ -552,7 +552,7 @@ class ClientTable : private Log<UniqueID, ClientTableData> {
|
|||
: Log(contexts, client),
|
||||
// We set the client log's key equal to nil so that all instances of
|
||||
// ClientTable have the same key.
|
||||
client_log_key_(UniqueID::nil()),
|
||||
client_log_key_(),
|
||||
disconnected_(false),
|
||||
client_id_(client_id),
|
||||
local_client_() {
|
||||
|
@ -622,8 +622,6 @@ class ClientTable : private Log<UniqueID, ClientTableData> {
|
|||
|
||||
/// Get the information of all clients.
|
||||
///
|
||||
/// Note: The return value contains ClientID::nil() which should be filtered.
|
||||
///
|
||||
/// \return The client ID to client information map.
|
||||
const std::unordered_map<ClientID, ClientTableDataT> &GetAllClients() const;
|
||||
|
||||
|
|
|
@ -24,6 +24,11 @@ std::mt19937 RandomlySeededMersenneTwister() {
|
|||
return seeded_engine;
|
||||
}
|
||||
|
||||
UniqueID::UniqueID() {
|
||||
// Set the ID to nil.
|
||||
std::fill_n(id_, kUniqueIDSize, 255);
|
||||
}
|
||||
|
||||
UniqueID::UniqueID(const plasma::UniqueID &from) {
|
||||
std::memcpy(&id_, from.data(), kUniqueIDSize);
|
||||
}
|
||||
|
@ -50,11 +55,9 @@ UniqueID UniqueID::from_binary(const std::string &binary) {
|
|||
return id;
|
||||
}
|
||||
|
||||
const UniqueID UniqueID::nil() {
|
||||
UniqueID result;
|
||||
uint8_t *data = result.mutable_data();
|
||||
std::fill_n(data, kUniqueIDSize, 255);
|
||||
return result;
|
||||
const UniqueID &UniqueID::nil() {
|
||||
static const UniqueID nil_id;
|
||||
return nil_id;
|
||||
}
|
||||
|
||||
bool UniqueID::is_nil() const {
|
||||
|
@ -67,17 +70,11 @@ bool UniqueID::is_nil() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
const uint8_t *UniqueID::data() const {
|
||||
return id_;
|
||||
}
|
||||
const uint8_t *UniqueID::data() const { return id_; }
|
||||
|
||||
uint8_t *UniqueID::mutable_data() {
|
||||
return id_;
|
||||
}
|
||||
uint8_t *UniqueID::mutable_data() { return id_; }
|
||||
|
||||
size_t UniqueID::size() const {
|
||||
return kUniqueIDSize;
|
||||
}
|
||||
size_t UniqueID::size() const { return kUniqueIDSize; }
|
||||
|
||||
std::string UniqueID::binary() const {
|
||||
return std::string(reinterpret_cast<const char *>(id_), kUniqueIDSize);
|
||||
|
|
|
@ -14,11 +14,11 @@ namespace ray {
|
|||
|
||||
class RAY_EXPORT UniqueID {
|
||||
public:
|
||||
UniqueID() {}
|
||||
UniqueID();
|
||||
UniqueID(const plasma::UniqueID &from);
|
||||
static UniqueID from_random();
|
||||
static UniqueID from_binary(const std::string &binary);
|
||||
static const UniqueID nil();
|
||||
static const UniqueID &nil();
|
||||
size_t hash() const;
|
||||
bool is_nil() const;
|
||||
bool operator==(const UniqueID &rhs) const;
|
||||
|
@ -34,8 +34,7 @@ class RAY_EXPORT UniqueID {
|
|||
uint8_t id_[kUniqueIDSize];
|
||||
};
|
||||
|
||||
static_assert(std::is_standard_layout<UniqueID>::value,
|
||||
"UniqueID must be standard");
|
||||
static_assert(std::is_standard_layout<UniqueID>::value, "UniqueID must be standard");
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const UniqueID &id);
|
||||
|
||||
|
|
|
@ -86,27 +86,25 @@ ray::Status ObjectDirectory::ReportObjectAdded(
|
|||
const ObjectID &object_id, const ClientID &client_id,
|
||||
const object_manager::protocol::ObjectInfoT &object_info) {
|
||||
// Append the addition entry to the object table.
|
||||
JobID job_id = JobID::nil();
|
||||
auto data = std::make_shared<ObjectTableDataT>();
|
||||
data->manager = client_id.binary();
|
||||
data->is_eviction = false;
|
||||
data->num_evictions = object_evictions_[object_id];
|
||||
data->object_size = object_info.data_size;
|
||||
ray::Status status =
|
||||
gcs_client_->object_table().Append(job_id, object_id, data, nullptr);
|
||||
gcs_client_->object_table().Append(JobID::nil(), object_id, data, nullptr);
|
||||
return status;
|
||||
}
|
||||
|
||||
ray::Status ObjectDirectory::ReportObjectRemoved(const ObjectID &object_id,
|
||||
const ClientID &client_id) {
|
||||
// Append the eviction entry to the object table.
|
||||
JobID job_id = JobID::nil();
|
||||
auto data = std::make_shared<ObjectTableDataT>();
|
||||
data->manager = client_id.binary();
|
||||
data->is_eviction = true;
|
||||
data->num_evictions = object_evictions_[object_id];
|
||||
ray::Status status =
|
||||
gcs_client_->object_table().Append(job_id, object_id, data, nullptr);
|
||||
gcs_client_->object_table().Append(JobID::nil(), object_id, data, nullptr);
|
||||
// Increment the number of times we've evicted this object. NOTE(swang): This
|
||||
// is only necessary because the Ray redis module expects unique entries in a
|
||||
// log. We track the number of evictions so that the next eviction, if there
|
||||
|
@ -212,9 +210,8 @@ ray::Status ObjectDirectory::LookupLocations(const ObjectID &object_id,
|
|||
ray::Status status;
|
||||
auto it = listeners_.find(object_id);
|
||||
if (it == listeners_.end()) {
|
||||
JobID job_id = JobID::nil();
|
||||
status = gcs_client_->object_table().Lookup(
|
||||
job_id, object_id,
|
||||
JobID::nil(), object_id,
|
||||
[this, callback](gcs::AsyncGcsClient *client, const ObjectID &object_id,
|
||||
const std::vector<ObjectTableDataT> &location_history) {
|
||||
// Build the set of current locations based on the entries in the log.
|
||||
|
|
|
@ -451,7 +451,7 @@ class TestObjectManager : public TestObjectManagerBase {
|
|||
<< "\n";
|
||||
ClientTableDataT data;
|
||||
gcs_client_1->client_table().GetClient(client_id_1, data);
|
||||
RAY_LOG(DEBUG) << (ClientID::from_binary(data.client_id) == ClientID::nil());
|
||||
RAY_LOG(DEBUG) << (ClientID::from_binary(data.client_id).is_nil());
|
||||
RAY_LOG(DEBUG) << "Server 1 ClientID=" << ClientID::from_binary(data.client_id);
|
||||
RAY_LOG(DEBUG) << "Server 1 ClientIp=" << data.node_manager_address;
|
||||
RAY_LOG(DEBUG) << "Server 1 ClientPort=" << data.node_manager_port;
|
||||
|
|
|
@ -9,9 +9,7 @@ namespace ray {
|
|||
namespace raylet {
|
||||
|
||||
ActorRegistration::ActorRegistration(const ActorTableDataT &actor_table_data)
|
||||
: actor_table_data_(actor_table_data),
|
||||
execution_dependency_(ObjectID::nil()),
|
||||
frontier_() {}
|
||||
: actor_table_data_(actor_table_data) {}
|
||||
|
||||
const ClientID ActorRegistration::GetNodeManagerId() const {
|
||||
return ClientID::from_binary(actor_table_data_.node_manager_id);
|
||||
|
|
|
@ -358,9 +358,9 @@ static int PyTask_init(PyTask *self, PyObject *args, PyObject *kwds) {
|
|||
// ID of the driver that this task originates from.
|
||||
UniqueID driver_id;
|
||||
// ID of the actor this task should run on.
|
||||
UniqueID actor_id = ActorID::nil();
|
||||
UniqueID actor_id;
|
||||
// ID of the actor handle used to submit this task.
|
||||
UniqueID actor_handle_id = ActorHandleID::nil();
|
||||
UniqueID actor_handle_id;
|
||||
// How many tasks have been launched on the actor so far?
|
||||
int actor_counter = 0;
|
||||
// ID of the function this task executes.
|
||||
|
@ -374,9 +374,9 @@ static int PyTask_init(PyTask *self, PyObject *args, PyObject *kwds) {
|
|||
// The number of tasks that the parent task has called prior to this one.
|
||||
int parent_counter;
|
||||
// The actor creation ID.
|
||||
ActorID actor_creation_id = ActorID::nil();
|
||||
ActorID actor_creation_id;
|
||||
// The dummy object for the actor creation task (if this is an actor method).
|
||||
ObjectID actor_creation_dummy_object_id = ObjectID::nil();
|
||||
ObjectID actor_creation_dummy_object_id;
|
||||
// Max number of times to reconstruct this actor (only used for actor creation
|
||||
// task).
|
||||
int32_t max_actor_reconstructions;
|
||||
|
|
|
@ -206,7 +206,7 @@ class TestObjectManagerIntegration : public TestObjectManagerBase {
|
|||
<< "\n";
|
||||
ClientTableDataT data;
|
||||
gcs_client_2->client_table().GetClient(client_id_1, data);
|
||||
RAY_LOG(INFO) << (ClientID::from_binary(data.client_id) == ClientID::nil());
|
||||
RAY_LOG(INFO) << (ClientID::from_binary(data.client_id).is_nil());
|
||||
RAY_LOG(INFO) << "ClientID=" << ClientID::from_binary(data.client_id);
|
||||
RAY_LOG(INFO) << "ClientIp=" << data.node_manager_address;
|
||||
RAY_LOG(INFO) << "ClientPort=" << data.node_manager_port;
|
||||
|
|
|
@ -15,8 +15,6 @@ Worker::Worker(pid_t pid, const Language &language,
|
|||
: pid_(pid),
|
||||
language_(language),
|
||||
connection_(connection),
|
||||
assigned_task_id_(TaskID::nil()),
|
||||
actor_id_(ActorID::nil()),
|
||||
dead_(false),
|
||||
blocked_(false) {}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue