-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Throw exception for ray.get
of an evicted actor object
#3490
Merged
stephanie-wang
merged 12 commits into
ray-project:master
from
stephanie-wang:fix-actor-eviction
Dec 14, 2018
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9a88ff5
Add a flag for whether an object has been created before
stephanie-wang a97f45d
Add regression test
stephanie-wang 2d71bf3
doc
stephanie-wang 94607e6
Share object directory between object and node managers
stephanie-wang b7d7b0c
Treat evicted actor tasks as failed
stephanie-wang 25e4808
minor
stephanie-wang a161d85
Check return value
stephanie-wang 23e559d
Fix bug where object locations weren't getting updated on client death
stephanie-wang a303d13
Fix mac build
stephanie-wang 4a5691f
Merge branch 'master' into fix-actor-eviction
stephanie-wang 32f5e80
Use RayTaskError
stephanie-wang 883dfeb
Merge branch 'master' into fix-actor-eviction
stephanie-wang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,34 +8,43 @@ ObjectDirectory::ObjectDirectory(boost::asio::io_service &io_service, | |
|
||
namespace { | ||
|
||
std::vector<ClientID> UpdateObjectLocations( | ||
std::unordered_set<ClientID> &client_ids, | ||
const std::vector<ObjectTableDataT> &location_history, | ||
const ray::gcs::ClientTable &client_table) { | ||
/// Process a suffix of the object table log and store the result in | ||
/// client_ids. This assumes that client_ids already contains the result of the | ||
/// object table log up to but not including this suffix. This also stores a | ||
/// bool in has_been_created indicating whether the object has ever been | ||
/// created before. | ||
void UpdateObjectLocations(const std::vector<ObjectTableDataT> &location_history, | ||
const ray::gcs::ClientTable &client_table, | ||
std::unordered_set<ClientID> *client_ids, | ||
bool *has_been_created) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm that's true...I can't really think of a foolproof way around that except to fail the object after some number of attempts. |
||
// location_history contains the history of locations of the object (it is a log), | ||
// which might look like the following: | ||
// client1.is_eviction = false | ||
// client1.is_eviction = true | ||
// client2.is_eviction = false | ||
// In such a scenario, we want to indicate client2 is the only client that contains | ||
// the object, which the following code achieves. | ||
if (!location_history.empty()) { | ||
// If there are entries, then the object has been created. Once this flag | ||
// is set to true, it should never go back to false. | ||
*has_been_created = true; | ||
} | ||
for (const auto &object_table_data : location_history) { | ||
ClientID client_id = ClientID::from_binary(object_table_data.manager); | ||
if (!object_table_data.is_eviction) { | ||
client_ids.insert(client_id); | ||
client_ids->insert(client_id); | ||
} else { | ||
client_ids.erase(client_id); | ||
client_ids->erase(client_id); | ||
} | ||
} | ||
// Filter out the removed clients from the object locations. | ||
for (auto it = client_ids.begin(); it != client_ids.end();) { | ||
for (auto it = client_ids->begin(); it != client_ids->end();) { | ||
if (client_table.IsRemoved(*it)) { | ||
it = client_ids.erase(it); | ||
it = client_ids->erase(it); | ||
} else { | ||
it++; | ||
} | ||
} | ||
return std::vector<ClientID>(client_ids.begin(), client_ids.end()); | ||
} | ||
|
||
} // namespace | ||
|
@@ -45,26 +54,27 @@ void ObjectDirectory::RegisterBackend() { | |
gcs::AsyncGcsClient *client, const ObjectID &object_id, | ||
const std::vector<ObjectTableDataT> &location_history) { | ||
// Objects are added to this map in SubscribeObjectLocations. | ||
auto object_id_listener_pair = listeners_.find(object_id); | ||
auto it = listeners_.find(object_id); | ||
// Do nothing for objects we are not listening for. | ||
if (object_id_listener_pair == listeners_.end()) { | ||
if (it == listeners_.end()) { | ||
return; | ||
} | ||
// Update entries for this object. | ||
std::vector<ClientID> client_id_vec = | ||
UpdateObjectLocations(object_id_listener_pair->second.current_object_locations, | ||
location_history, gcs_client_->client_table()); | ||
UpdateObjectLocations(location_history, gcs_client_->client_table(), | ||
&it->second.current_object_locations, | ||
&it->second.has_been_created); | ||
// Copy the callbacks so that the callbacks can unsubscribe without interrupting | ||
// looping over the callbacks. | ||
auto callbacks = object_id_listener_pair->second.callbacks; | ||
auto callbacks = it->second.callbacks; | ||
// Call all callbacks associated with the object id locations we have | ||
// received. This notifies the client even if the list of locations is | ||
// empty, since this may indicate that the objects have been evicted from | ||
// all nodes. | ||
for (const auto &callback_pair : callbacks) { | ||
// It is safe to call the callback directly since this is already running | ||
// in the subscription callback stack. | ||
callback_pair.second(client_id_vec, object_id); | ||
callback_pair.second(object_id, it->second.current_object_locations, | ||
it->second.has_been_created); | ||
} | ||
}; | ||
RAY_CHECK_OK(gcs_client_->object_table().Subscribe( | ||
|
@@ -133,28 +143,51 @@ std::vector<RemoteConnectionInfo> ObjectDirectory::LookupAllRemoteConnections() | |
return remote_connections; | ||
} | ||
|
||
void ObjectDirectory::HandleClientRemoved(const ClientID &client_id) { | ||
for (auto &listener : listeners_) { | ||
const ObjectID &object_id = listener.first; | ||
if (listener.second.current_object_locations.count(client_id) > 0) { | ||
// If the subscribed object has the removed client as a location, update | ||
// its locations with an empty log so that the location will be removed. | ||
UpdateObjectLocations({}, gcs_client_->client_table(), | ||
&listener.second.current_object_locations, | ||
&listener.second.has_been_created); | ||
// Re-call all the subscribed callbacks for the object, since its | ||
// locations have changed. | ||
for (const auto &callback_pair : listener.second.callbacks) { | ||
// It is safe to call the callback directly since this is already running | ||
// in the subscription callback stack. | ||
callback_pair.second(object_id, listener.second.current_object_locations, | ||
listener.second.has_been_created); | ||
} | ||
} | ||
} | ||
} | ||
|
||
ray::Status ObjectDirectory::SubscribeObjectLocations(const UniqueID &callback_id, | ||
const ObjectID &object_id, | ||
const OnLocationsFound &callback) { | ||
ray::Status status = ray::Status::OK(); | ||
if (listeners_.find(object_id) == listeners_.end()) { | ||
listeners_.emplace(object_id, LocationListenerState()); | ||
auto it = listeners_.find(object_id); | ||
if (it == listeners_.end()) { | ||
it = listeners_.emplace(object_id, LocationListenerState()).first; | ||
status = gcs_client_->object_table().RequestNotifications( | ||
JobID::nil(), object_id, gcs_client_->client_table().GetLocalClientId()); | ||
} | ||
auto &listener_state = listeners_.find(object_id)->second; | ||
auto &listener_state = it->second; | ||
// TODO(hme): Make this fatal after implementing Pull suppression. | ||
if (listener_state.callbacks.count(callback_id) > 0) { | ||
return ray::Status::OK(); | ||
} | ||
listener_state.callbacks.emplace(callback_id, callback); | ||
// Immediately notify of object locations. This notifies the client even if | ||
// the list of locations is empty, since this may indicate that the objects | ||
// have been evicted from all nodes. | ||
std::vector<ClientID> client_id_vec(listener_state.current_object_locations.begin(), | ||
listener_state.current_object_locations.end()); | ||
io_service_.post( | ||
[callback, client_id_vec, object_id]() { callback(client_id_vec, object_id); }); | ||
// If we previously received some notifications about the object's locations, | ||
// immediately notify the caller of the current known locations. | ||
if (listener_state.has_been_created) { | ||
auto &locations = listener_state.current_object_locations; | ||
io_service_.post([callback, locations, object_id]() { | ||
callback(object_id, locations, /*has_been_created=*/true); | ||
}); | ||
} | ||
return status; | ||
} | ||
|
||
|
@@ -176,19 +209,32 @@ ray::Status ObjectDirectory::UnsubscribeObjectLocations(const UniqueID &callback | |
|
||
ray::Status ObjectDirectory::LookupLocations(const ObjectID &object_id, | ||
const OnLocationsFound &callback) { | ||
JobID job_id = JobID::nil(); | ||
ray::Status status = gcs_client_->object_table().Lookup( | ||
job_id, 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. | ||
std::unordered_set<ClientID> client_ids; | ||
std::vector<ClientID> locations_vector = UpdateObjectLocations( | ||
client_ids, location_history, gcs_client_->client_table()); | ||
// It is safe to call the callback directly since this is already running | ||
// in the GCS client's lookup callback stack. | ||
callback(locations_vector, 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, | ||
[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. | ||
std::unordered_set<ClientID> client_ids; | ||
bool has_been_created = false; | ||
UpdateObjectLocations(location_history, gcs_client_->client_table(), | ||
&client_ids, &has_been_created); | ||
// It is safe to call the callback directly since this is already running | ||
// in the GCS client's lookup callback stack. | ||
callback(object_id, client_ids, has_been_created); | ||
}); | ||
} else { | ||
// If we have locations cached due to a concurrent SubscribeObjectLocations | ||
// call, call the callback immediately with the cached locations. | ||
auto &locations = it->second.current_object_locations; | ||
bool has_been_created = it->second.has_been_created; | ||
io_service_.post([callback, object_id, locations, has_been_created]() { | ||
callback(object_id, locations, has_been_created); | ||
}); | ||
} | ||
return status; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we document this function. In particular the fact that we have output arguments.