diff --git a/services/backup/docker-server/contents/server/src/Reactors/server/SendLogReactor.h b/services/backup/docker-server/contents/server/src/Reactors/server/SendLogReactor.h --- a/services/backup/docker-server/contents/server/src/Reactors/server/SendLogReactor.h +++ b/services/backup/docker-server/contents/server/src/Reactors/server/SendLogReactor.h @@ -3,6 +3,7 @@ #include "Constants.h" #include "ServerReadReactorBase.h" #include "ServiceBlobClient.h" +#include "Tools.h" #include "../_generated/backup.grpc.pb.h" #include "../_generated/backup.pb.h" @@ -42,9 +43,11 @@ std::string value; std::mutex reactorStateMutex; std::condition_variable blobDoneCV; + std::mutex blobDoneCVMutex; std::shared_ptr putReactor; ServiceBlobClient blobClient; + void storeInDatabase(); std::string generateHolder(); std::string generateLogID(); @@ -60,6 +63,7 @@ std::unique_ptr readRequest(backup::SendLogRequest request) override; void doneCallback() override; + void terminateCallback() override; }; void SendLogReactor::storeInDatabase() { @@ -159,6 +163,20 @@ throw std::runtime_error("send log - invalid state"); } +void SendLogReactor::terminateCallback() { + const std::lock_guard lock(this->reactorStateMutex); + + if (this->persistenceMethod == PersistenceMethod::DB || + this->putReactor == nullptr) { + return; + } + this->putReactor->scheduleSendingDataChunk(std::make_unique("")); + std::unique_lock lock2(this->blobDoneCVMutex); + this->blobDoneCV.wait(lock2); + // store in db only when we successfully upload chunks + this->storeInDatabase(); +} + void SendLogReactor::doneCallback() { // we make sure that the blob client's state is flushed to the main memory // as there may be multiple threads from the pool taking over here