Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3527935
D4411.id14147.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D4411.id14147.diff
View Options
diff --git a/services/backup/src/Reactors/server/SendLogReactor.h b/services/backup/src/Reactors/server/SendLogReactor.h
--- a/services/backup/src/Reactors/server/SendLogReactor.h
+++ b/services/backup/src/Reactors/server/SendLogReactor.h
@@ -1,5 +1,6 @@
#pragma once
+#include "LogItem.h"
#include "ServerReadReactorBase.h"
#include "ServiceBlobClient.h"
@@ -35,9 +36,7 @@
std::string logID;
std::string backupID;
std::string hash;
- // either the value itself which is a dump of a single operation (if
- // `persistedInBlob` is false) or the holder to blob (if `persistedInBlob` is
- // true)
+ std::string blobHolder;
std::string value;
std::mutex reactorStateMutex;
diff --git a/services/backup/src/Reactors/server/SendLogReactor.cpp b/services/backup/src/Reactors/server/SendLogReactor.cpp
--- a/services/backup/src/Reactors/server/SendLogReactor.cpp
+++ b/services/backup/src/Reactors/server/SendLogReactor.cpp
@@ -12,12 +12,12 @@
namespace reactor {
void SendLogReactor::storeInDatabase() {
- // TODO handle attachment holders
+ bool storedInBlob = this->persistenceMethod == PersistenceMethod::BLOB;
database::LogItem logItem(
this->backupID,
this->logID,
- (this->persistenceMethod == PersistenceMethod::BLOB),
- this->value,
+ storedInBlob,
+ storedInBlob ? this->blobHolder : this->value,
{},
this->hash);
database::DatabaseManager::getInstance().putLogItem(logItem);
@@ -29,9 +29,9 @@
}
void SendLogReactor::initializePutReactor() {
- if (this->value.empty()) {
+ if (this->blobHolder.empty()) {
throw std::runtime_error(
- "put reactor cannot be initialized with empty value");
+ "put reactor cannot be initialized with empty blob holder");
}
if (this->hash.empty()) {
throw std::runtime_error(
@@ -39,7 +39,7 @@
}
if (this->putReactor == nullptr) {
this->putReactor = std::make_shared<reactor::BlobPutClientReactor>(
- this->value, this->hash, &this->blobPutDoneCV);
+ this->blobHolder, this->hash, &this->blobPutDoneCV);
this->blobClient.put(this->putReactor);
}
}
@@ -90,39 +90,27 @@
if (chunk->size() == 0) {
return std::make_unique<grpc::Status>(grpc::Status::OK);
}
- // decide if keep in DB or upload to blob
- if (chunk->size() <= LOG_DATA_SIZE_DATABASE_LIMIT) {
- if (this->persistenceMethod == PersistenceMethod::UNKNOWN) {
- this->persistenceMethod = PersistenceMethod::DB;
- this->value = std::move(*chunk);
- this->storeInDatabase();
- return nullptr;
- } else if (this->persistenceMethod == PersistenceMethod::BLOB) {
- this->initializePutReactor();
- this->putReactor->scheduleSendingDataChunk(std::move(chunk));
- } else {
+ if (this->persistenceMethod == PersistenceMethod::BLOB) {
+ if (this->putReactor == nullptr) {
throw std::runtime_error(
- "error - invalid persistence state for chunk smaller than "
- "database limit");
+ "put reactor is being used but has not been initialized");
}
- } else {
- if (this->persistenceMethod != PersistenceMethod::UNKNOWN &&
- this->persistenceMethod != PersistenceMethod::BLOB) {
- throw std::runtime_error(
- "error - invalid persistence state, uploading to blob should be "
- "continued but it is not");
- }
- if (this->persistenceMethod == PersistenceMethod::UNKNOWN) {
- this->persistenceMethod = PersistenceMethod::BLOB;
- }
- if (this->value.empty()) {
- this->value =
- tools::generateHolder(this->hash, this->backupID, this->logID);
- }
- this->initializePutReactor();
this->putReactor->scheduleSendingDataChunk(std::move(chunk));
+ return nullptr;
+ }
+ this->value += std::move(*chunk);
+ database::LogItem logItem = database::LogItem(
+ this->backupID, this->logID, true, this->value, "", this->hash);
+ if (database::LogItem::getItemSize(&logItem) >
+ LOG_DATA_SIZE_DATABASE_LIMIT) {
+ this->persistenceMethod = PersistenceMethod::BLOB;
+ this->blobHolder =
+ tools::generateHolder(this->hash, this->backupID, this->logID);
+ this->initializePutReactor();
+ this->putReactor->scheduleSendingDataChunk(
+ std::make_unique<std::string>(this->value));
+ this->value = "";
}
-
return nullptr;
};
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 25, 7:33 AM (11 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2701935
Default Alt Text
D4411.id14147.diff (4 KB)
Attached To
Mode
D4411: [services] Backup - Send Log - Use separate variables for value and blob holder
Attached
Detach File
Event Timeline
Log In to Comment