[Object Spilling] Skip normal ray.get path when spilling objects. (#13831)

This commit is contained in:
SangBin Cho
2021-02-01 16:03:34 -08:00
committed by GitHub
parent e4d30430c0
commit 886217c333
7 changed files with 95 additions and 5 deletions
+17
View File
@@ -1058,6 +1058,23 @@ Status CoreWorker::Get(const std::vector<ObjectID> &ids, const int64_t timeout_m
return Status::OK();
}
Status CoreWorker::GetIfLocal(const std::vector<ObjectID> &ids,
std::vector<std::shared_ptr<RayObject>> *results) {
results->resize(ids.size(), nullptr);
absl::flat_hash_map<ObjectID, std::shared_ptr<RayObject>> result_map;
RAY_RETURN_NOT_OK(plasma_store_provider_->GetIfLocal(ids, &result_map));
for (size_t i = 0; i < ids.size(); i++) {
auto pair = result_map.find(ids[i]);
// The caller of this method should guarantee that the object exists in the plasma
// store when this method is called.
RAY_CHECK(pair != result_map.end());
RAY_CHECK(pair->second != nullptr);
(*results)[i] = pair->second;
}
return Status::OK();
}
Status CoreWorker::Contains(const ObjectID &object_id, bool *has_object) {
bool found = false;
bool in_plasma = false;
+14
View File
@@ -555,6 +555,20 @@ class CoreWorker : public rpc::CoreWorkerServiceHandler {
std::vector<std::shared_ptr<RayObject>> *results,
bool plasma_objects_only = false);
/// Get objects directly from the local plasma store, without waiting for the
/// objects to be fetched from another node. This should only be used
/// internally, never by user code.
/// NOTE: Caller of this method should guarantee that the object already exists in the
/// plasma store, thus it doesn't need to fetch from other nodes.
///
/// \param[in] ids The IDs of the objects to get.
/// \param[out] results The results will be stored here. A nullptr will be
/// added for objects that were not in the local store.
/// \return Status OK if all objects were found. Returns ObjectNotFound error
/// if at least one object was not in the local store.
Status GetIfLocal(const std::vector<ObjectID> &ids,
std::vector<std::shared_ptr<RayObject>> *results);
/// Return whether or not the object store contains the given object.
///
/// \param[in] object_id ID of the objects to check for.
@@ -225,6 +225,38 @@ Status CoreWorkerPlasmaStoreProvider::FetchAndGetFromPlasmaStore(
return Status::OK();
}
Status CoreWorkerPlasmaStoreProvider::GetIfLocal(
const std::vector<ObjectID> &object_ids,
absl::flat_hash_map<ObjectID, std::shared_ptr<RayObject>> *results) {
std::vector<plasma::ObjectBuffer> plasma_results;
{
std::lock_guard<std::mutex> guard(store_client_mutex_);
RAY_RETURN_NOT_OK(store_client_.Get(object_ids, /*timeout_ms=*/0, &plasma_results));
}
for (size_t i = 0; i < object_ids.size(); i++) {
if (plasma_results[i].data != nullptr || plasma_results[i].metadata != nullptr) {
const auto &object_id = object_ids[i];
std::shared_ptr<TrackedBuffer> data = nullptr;
std::shared_ptr<Buffer> metadata = nullptr;
if (plasma_results[i].data && plasma_results[i].data->Size()) {
// We track the set of active data buffers in active_buffers_. On destruction,
// the buffer entry will be removed from the set via callback.
data = std::make_shared<TrackedBuffer>(plasma_results[i].data, buffer_tracker_,
object_id);
buffer_tracker_->Record(object_id, data.get(), get_current_call_site_());
}
if (plasma_results[i].metadata && plasma_results[i].metadata->Size()) {
metadata = plasma_results[i].metadata;
}
const auto result_object =
std::make_shared<RayObject>(data, metadata, std::vector<ObjectID>());
(*results)[object_id] = result_object;
}
}
return Status::OK();
}
Status UnblockIfNeeded(const std::shared_ptr<raylet::RayletClient> &client,
const WorkerContext &ctx) {
if (ctx.CurrentTaskIsDirectCall()) {
@@ -143,6 +143,18 @@ class CoreWorkerPlasmaStoreProvider {
absl::flat_hash_map<ObjectID, std::shared_ptr<RayObject>> *results,
bool *got_exception);
/// Get objects directly from the local plasma store, without waiting for the
/// objects to be fetched from another node. This should only be used
/// internally, never by user code.
///
/// \param[in] ids The IDs of the objects to get.
/// \param[out] results The results will be stored here. A nullptr will be
/// added for objects that were not in the local store.
/// \return Status OK if the request to the local object store was
/// successful.
Status GetIfLocal(const std::vector<ObjectID> &ids,
absl::flat_hash_map<ObjectID, std::shared_ptr<RayObject>> *results);
Status Contains(const ObjectID &object_id, bool *has_object);
Status Wait(const absl::flat_hash_set<ObjectID> &object_ids, int num_objects,