diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/blob/BlobGetClientReactor.h b/services/backup/docker-server/contents/server/src/Reactors/client/blob/BlobGetClientReactor.h --- a/services/backup/docker-server/contents/server/src/Reactors/client/blob/BlobGetClientReactor.h +++ b/services/backup/docker-server/contents/server/src/Reactors/client/blob/BlobGetClientReactor.h @@ -40,8 +40,7 @@ std::unique_ptr BlobGetClientReactor::readResponse(blob::GetResponse &response) { if (!this->dataChunks->write(std::move(*response.mutable_datachunk()))) { - throw std::runtime_error( - "error reading compaction data from the blob service"); + throw std::runtime_error("error reading data from the blob service"); } return nullptr; } diff --git a/services/backup/docker-server/contents/server/src/Reactors/server/PullBackupReactor.h b/services/backup/docker-server/contents/server/src/Reactors/server/PullBackupReactor.h --- a/services/backup/docker-server/contents/server/src/Reactors/server/PullBackupReactor.h +++ b/services/backup/docker-server/contents/server/src/Reactors/server/PullBackupReactor.h @@ -63,12 +63,10 @@ throw std::runtime_error( "get reactor cannot be initialized when backup item is missing"); } - if (this->getReactor == nullptr) { - this->getReactor = std::make_shared( - holder, this->dataChunks); - this->getReactor->request.set_holder(holder); - this->blobClient.get(this->getReactor); - } + this->getReactor.reset( + new reactor::BlobGetClientReactor(holder, this->dataChunks)); + this->getReactor->request.set_holder(holder); + this->blobClient.get(this->getReactor); } void PullBackupReactor::initialize() { @@ -100,7 +98,9 @@ const std::lock_guard lock(this->reactorStateMutex); switch (this->state) { case State::COMPACTION: { - this->initializeGetReactor(this->backupItem->getCompactionHolder()); + if (this->getReactor == nullptr) { + this->initializeGetReactor(this->backupItem->getCompactionHolder()); + } std::string dataChunk; this->dataChunks->blockingRead(dataChunk); if (!dataChunk.empty()) { @@ -111,7 +111,10 @@ throw std::runtime_error( "dangling data discovered after reading compaction"); } - this->getReactor = nullptr; + if (!this->getReactor->getStatus().ok()) { + throw std::runtime_error( + this->getReactor->getStatus().error_message()); + } this->state = State::LOGS; // WARNING: intentionally letting the flow enter case State::LOGS from // here, because we want to start sending logs right away instead of @@ -124,6 +127,10 @@ return std::make_unique(grpc::Status::OK); } if (this->currentLogIndex == this->logs.size()) { + if (!this->dataChunks->isEmpty()) { + throw std::runtime_error( + "dangling data discovered after reading logs"); + } return std::make_unique(grpc::Status::OK); } else if (this->currentLogIndex > this->logs.size()) { throw std::runtime_error("log index out of bound"); @@ -141,10 +148,15 @@ } std::string dataChunk; this->dataChunks->blockingRead(dataChunk); + if (!this->getReactor->getStatus().ok()) { + throw std::runtime_error(this->getReactor->getStatus().error_message()); + } if (dataChunk.empty()) { + this->checkSize = 0; ++this->currentLogIndex; this->currentLog = nullptr; } else { + this->checkSize += dataChunk.size(); response->set_logchunk(dataChunk); } return nullptr; diff --git a/services/blob/src/Reactors/server/GetReactor.h b/services/blob/src/Reactors/server/GetReactor.h --- a/services/blob/src/Reactors/server/GetReactor.h +++ b/services/blob/src/Reactors/server/GetReactor.h @@ -38,7 +38,7 @@ std::min(this->chunkSize, this->fileSize - this->offset); std::string range = "bytes=" + std::to_string(this->offset) + "-" + - std::to_string(this->offset + nextSize); + std::to_string(this->offset + nextSize - 1); this->getRequest.SetRange(range); Aws::S3::Model::GetObjectOutcome getOutcome =