Skip to content
Closed
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
30 changes: 19 additions & 11 deletions cpp/src/plasma/store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,17 @@ void PlasmaStore::disconnect_client(int client_fd) {

/// Send notifications about sealed objects to the subscribers. This is called
/// in seal_object. If the socket's send buffer is full, the notification will
/// be
/// buffered, and this will be called again when the send buffer has room.
/// be buffered, and this will be called again when the send buffer has room.
/// Since we call erase on pending_notifications_, all iterators get
/// invalidated, which is why we return a valid iterator to the next client to
/// be used in push_notification.
///
/// @param client_fd The client to send the notification to.
void PlasmaStore::send_notifications(int client_fd) {
auto& notifications = pending_notifications_[client_fd].object_notifications;
/// @param it Iterator that points to the client to send the notification to.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth being even more explicit and saying that we need to do this because send_notifications is used in a loop that iterates over pending_notifications_.

/// @return Iterator pointing to the next client.
PlasmaStore::NotificationMap::iterator PlasmaStore::send_notifications(
PlasmaStore::NotificationMap::iterator it) {
int client_fd = it->first;
auto& notifications = it->second.object_notifications;

int num_processed = 0;
bool closed = false;
Expand All @@ -599,7 +604,7 @@ void PlasmaStore::send_notifications(int client_fd) {
// TODO(pcm): Introduce status codes and check in case the file descriptor
// is added twice.
loop_->AddFileEvent(client_fd, kEventLoopWrite, [this, client_fd](int events) {
send_notifications(client_fd);
send_notifications(pending_notifications_.find(client_fd));
});
break;
} else {
Expand All @@ -622,15 +627,18 @@ void PlasmaStore::send_notifications(int client_fd) {
// Stop sending notifications if the pipe was broken.
if (closed) {
close(client_fd);
pending_notifications_.erase(client_fd);
return pending_notifications_.erase(it);
} else {
return ++it;
}
}

void PlasmaStore::push_notification(ObjectInfoT* object_info) {
for (auto& element : pending_notifications_) {
auto it = pending_notifications_.begin();
while (it != pending_notifications_.end()) {
auto notification = create_object_info_buffer(object_info);
element.second.object_notifications.emplace_back(std::move(notification));
send_notifications(element.first);
it->second.object_notifications.emplace_back(std::move(notification));
it = send_notifications(it);
}
}

Expand All @@ -654,7 +662,7 @@ void PlasmaStore::subscribe_to_updates(Client* client) {
for (const auto& entry : store_info_.objects) {
push_notification(&entry.second->info);
}
send_notifications(fd);
send_notifications(pending_notifications_.find(fd));
}

Status PlasmaStore::process_message(Client* client) {
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/plasma/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct Client {

class PlasmaStore {
public:
using NotificationMap = std::unordered_map<int, NotificationQueue>;

// TODO: PascalCase PlasmaStore methods.
PlasmaStore(EventLoop* loop, int64_t system_memory, std::string directory,
bool hugetlbfs_enabled);
Expand Down Expand Up @@ -161,7 +163,7 @@ class PlasmaStore {
/// @param client_fd The client file descriptor that is disconnected.
void disconnect_client(int client_fd);

void send_notifications(int client_fd);
NotificationMap::iterator send_notifications(NotificationMap::iterator it);

Status process_message(Client* client);

Expand Down Expand Up @@ -194,7 +196,7 @@ class PlasmaStore {
/// descriptor to an array of object_ids to send to that client.
/// TODO(pcm): Consider putting this into the Client data structure and
/// reorganize the code slightly.
std::unordered_map<int, NotificationQueue> pending_notifications_;
NotificationMap pending_notifications_;

std::unordered_map<int, std::unique_ptr<Client>> connected_clients_;
#ifdef PLASMA_GPU
Expand Down