diff --git a/build/includes/summa_actor/batch_manager.hpp b/build/includes/summa_actor/batch_manager.hpp index 11cb442a8beb7098058486384a42aceb5dea67d6..049c077d5fc85610c27e6e9727672b6f8332e5b4 100644 --- a/build/includes/summa_actor/batch_manager.hpp +++ b/build/includes/summa_actor/batch_manager.hpp @@ -132,7 +132,8 @@ class Batch_Container { void printBatches(); /** - * @brief + * @brief Find the batch with the batch_id parameter + * update the batches assigned actor member variable to false * */ void updateBatchStatus_LostClient(int batch_id); diff --git a/build/includes/summa_actor/client.hpp b/build/includes/summa_actor/client.hpp index 22081f50a6885ea383d9b4186af96370783c560a..54f4498944e0fa08e8fec879a31a09ff92774a62 100644 --- a/build/includes/summa_actor/client.hpp +++ b/build/includes/summa_actor/client.hpp @@ -10,6 +10,7 @@ class Client { int id; int batches_solved; bool connected; + bool assigned_batch; caf::actor client_actor; std::string hostname; int current_batch_id; @@ -53,12 +54,23 @@ class Client { */ std::string getHostname(); + /** + * See if the client is assigned a batch or not + */ + bool getAssignedBatch(); + // Setters /** * @brief Sets the batch_id of the batch the client is currently computing */ void updateCurrentBatchID(int batch_id); + /** + * Sets the assigned_batch variable to true or false + */ + void setAssignedBatch(bool boolean); + + // methods /** * @brief Increments the lost_likley_hood indicator variable @@ -123,6 +135,11 @@ class Client_Container { */ Client getClient(int index); + /** + * Find the client by client_id and set its assigned batch to the boolean argument + */ + void setAssignedBatch(int client_id, bool boolean); + // Methods /** * @brief add a client to the client vector @@ -187,5 +204,13 @@ class Client_Container { */ int findClientByID(int client_id); + /** + * Removes client from client container that has lost connection + */ void removeLostClient(int index); + + /** + * Look for an idle client + */ + std::optional<int> findIdleClientID(); }; \ No newline at end of file diff --git a/build/source/actors/summa_actor/client.cpp b/build/source/actors/summa_actor/client.cpp index 8dd9c0888387d8f876e3da1a8606613e9b9764ce..1888939c9be643a5d909e179e18432d44a28fc36 100644 --- a/build/source/actors/summa_actor/client.cpp +++ b/build/source/actors/summa_actor/client.cpp @@ -7,6 +7,7 @@ Client::Client(int id, caf::actor client_actor, std::string hostname) { this->client_actor = client_actor; this->hostname = hostname; this->connected = true; + this->assigned_batch = false; } // Getters @@ -30,9 +31,18 @@ std::string Client::getHostname() { return this->hostname; } +bool Client::getAssignedBatch() { + return this->assigned_batch; +} + // Setters void Client::updateCurrentBatchID(int batch_id) { this->current_batch_id = batch_id; + this->assigned_batch = true; +} + +void Client::setAssignedBatch(bool boolean) { + this->assigned_batch = boolean; } // Methods @@ -65,6 +75,11 @@ void Client_Container::addClient(caf::actor client_actor, std::string hostname) } +void Client_Container::setAssignedBatch(int client_id, bool boolean) { + int index = findClientByID(client_id); + this->client_list[index].setAssignedBatch(boolean); +} + int Client_Container::getNumClients() { return this->num_clients; } @@ -77,7 +92,7 @@ Client Client_Container::getClient(int index) { return this->client_list[index]; } -// Needs to be used direclty after getClient so same index is used +// Needs to be used directly after getClient so same index is used bool Client_Container::checkForLostClient(int index) { this->client_list[index].incrementLostPotential(); if (this->lost_client_threshold < this->client_list[index].getLostPotentialIndicator()) { @@ -135,6 +150,15 @@ void Client_Container::removeLostClient(int index) { this->num_clients--; } +std::optional<int> Client_Container::findIdleClientID() { + for(int i = 0; i < this->num_clients; i++) { + if (!this->client_list[i].getAssignedBatch()) { + return this->client_list[i].getID(); + } + } + + return {}; +} diff --git a/build/source/actors/summa_actor/summa_server.cpp b/build/source/actors/summa_actor/summa_server.cpp index 776570a3572f5ccca70bdf3a6324129c1b40e6b3..e773578fc81c65ac5d612843202043c00aab451f 100644 --- a/build/source/actors/summa_actor/summa_server.cpp +++ b/build/source/actors/summa_actor/summa_server.cpp @@ -77,7 +77,7 @@ behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Sett * @param batch */ [=](done_batch, actor client_actor, int client_id, Batch& batch) { - aout(self) << "Recieved Completed Batch From Client\n"; + aout(self) << "Received Completed Batch From Client\n"; aout(self) << batch.toString() << "\n\n"; @@ -97,7 +97,9 @@ behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Sett if (self->state.batch_container->getBatchesRemaining() > 0) { aout(self) << "no more batches left to assign\n"; - aout(self) << "we are not done yet. Clients could Fail\n"; + aout(self) << "Keeping Client connected because other clients could Fail\n"; + + self->state.client_container->setAssignedBatch(client_id, false); } else { aout(self) << "Telling Clients To Exit\n"; @@ -121,15 +123,19 @@ behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Sett [=](check_on_clients) { for (int i = 0; i < self->state.client_container->getNumClients(); i++) { Client client = self->state.client_container->getClient(i); - if(self->state.client_container->checkForLostClient(i)) { - // Client May Be Lost + + if(self->state.client_container->checkForLostClient(i)) { // Client is lost aout(self) << "Client " << client.getID() << " is considered lost\n"; self->state.batch_container->updateBatchStatus_LostClient(client.getCurrentBatchID()); self->state.client_container->removeLostClient(i); - } else { + // now see if we have any idle clients + self->state.client_container->findIdleClientID(); + + + } else { // No loss send another heartbeat self->send(client.getActor(), heartbeat_v); } }