Skip to content
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

[2/N][VirtualClusetr] add GcsVirtualClusterTable #411

Merged
merged 1 commit into from
Dec 10, 2024
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
2 changes: 2 additions & 0 deletions src/ray/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ ray_cc_library(
"common_protocol.h",
"id.h",
"id_def.h",
"simple_id.h",
"virtual_cluster_id.h",
],
deps = [
":constants",
Expand Down
48 changes: 48 additions & 0 deletions src/ray/common/simple_id.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2017 The Ray Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "ray/common/id.h"

namespace ray {

template <typename T>
struct SimpleID {
static T FromBinary(const std::string &binary) {
T id;
id.id_ = binary;
return id;
}

size_t Hash() const {
// Note(ashione): hash code lazy calculation(it's invoked every time if hash code is
// default value 0)
if (!hash_) {
hash_ = MurmurHash64A(id_.data(), id_.size(), 0);
}
return hash_;
}

const std::string &Binary() const { return id_; }

bool operator==(const T &rhs) const { return id_ == rhs.id_; }
bool operator!=(const T &rhs) const { return !(*this == rhs); }

private:
std::string id_;
mutable size_t hash_ = 0;
};

} // namespace ray
43 changes: 43 additions & 0 deletions src/ray/common/virtual_cluster_id.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2017 The Ray Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "ray/common/simple_id.h"

namespace ray {

class VirtualClusterID : public SimpleID<VirtualClusterID> {
using SimpleID::SimpleID;
};

inline std::ostream &operator<<(std::ostream &os, const ray::VirtualClusterID &id) {
os << id.Binary();
return os;
}

} // namespace ray

namespace std {

template <>
struct hash<ray::VirtualClusterID> {
size_t operator()(const ray::VirtualClusterID &id) const { return id.Hash(); }
};
template <>
struct hash<const ray::VirtualClusterID> {
size_t operator()(const ray::VirtualClusterID &id) const { return id.Hash(); }
};

} // namespace std
1 change: 1 addition & 0 deletions src/ray/gcs/gcs_server/gcs_table_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ template class GcsTable<ActorID, TaskSpec>;
template class GcsTableWithJobId<ActorID, ActorTableData>;
template class GcsTableWithJobId<ActorID, TaskSpec>;
template class GcsTable<PlacementGroupID, PlacementGroupTableData>;
template class GcsTable<VirtualClusterID, VirtualClusterTableData>;

} // namespace gcs
} // namespace ray
18 changes: 18 additions & 0 deletions src/ray/gcs/gcs_server/gcs_table_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <utility>

#include "ray/common/asio/instrumented_io_context.h"
#include "ray/common/virtual_cluster_id.h"
#include "ray/gcs/store_client/in_memory_store_client.h"
#include "ray/gcs/store_client/observable_store_client.h"
#include "ray/gcs/store_client/redis_store_client.h"
Expand All @@ -33,6 +34,7 @@ using rpc::JobTableData;
using rpc::PlacementGroupTableData;
using rpc::ResourceUsageBatchData;
using rpc::TaskSpec;
using rpc::VirtualClusterTableData;
using rpc::WorkerTableData;

/// \class GcsTable
Expand Down Expand Up @@ -208,6 +210,15 @@ class GcsWorkerTable : public GcsTable<WorkerID, WorkerTableData> {
}
};

class GcsVirtualClusterTable
: public GcsTable<VirtualClusterID, VirtualClusterTableData> {
public:
explicit GcsVirtualClusterTable(std::shared_ptr<StoreClient> store_client)
: GcsTable(std::move(store_client)) {
table_name_ = TablePrefix_Name(TablePrefix::VIRTUAL_CLUSTER);
}
};

/// \class GcsTableStorage
///
/// This class is not meant to be used directly. All gcs table storage classes should
Expand All @@ -222,6 +233,7 @@ class GcsTableStorage {
placement_group_table_ = std::make_unique<GcsPlacementGroupTable>(store_client_);
node_table_ = std::make_unique<GcsNodeTable>(store_client_);
worker_table_ = std::make_unique<GcsWorkerTable>(store_client_);
virtual_cluster_table_ = std::make_unique<GcsVirtualClusterTable>(store_client_);
}

virtual ~GcsTableStorage() = default;
Expand Down Expand Up @@ -256,6 +268,11 @@ class GcsTableStorage {
return *worker_table_;
}

GcsVirtualClusterTable &VirtualClusterTable() {
RAY_CHECK(virtual_cluster_table_ != nullptr);
return *virtual_cluster_table_;
}

int GetNextJobID() {
RAY_CHECK(store_client_);
return store_client_->GetNextJobID();
Expand All @@ -269,6 +286,7 @@ class GcsTableStorage {
std::unique_ptr<GcsPlacementGroupTable> placement_group_table_;
std::unique_ptr<GcsNodeTable> node_table_;
std::unique_ptr<GcsWorkerTable> worker_table_;
std::unique_ptr<GcsVirtualClusterTable> virtual_cluster_table_;
};

/// \class RedisGcsTableStorage
Expand Down
1 change: 1 addition & 0 deletions src/ray/protobuf/gcs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ enum TablePrefix {
PLACEMENT_GROUP = 17;
KV = 18;
ACTOR_TASK_SPEC = 19;
VIRTUAL_CLUSTER = 20;
}

// The channel that Add operations to the Table should be published on, if any.
Expand Down