Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3536191
D3467.id10719.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D3467.id10719.diff
View Options
diff --git a/services/backup/docker-server/contents/server/src/Reactors/server/CreateNewBackupReactor.h b/services/backup/docker-server/contents/server/src/Reactors/server/CreateNewBackupReactor.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/Reactors/server/CreateNewBackupReactor.h
@@ -0,0 +1,104 @@
+#pragma once
+
+#include "ServerBidiReactorBase.h"
+#include "ServiceBlobClient.h"
+#include "Tools.h"
+
+#include "../_generated/backup.grpc.pb.h"
+#include "../_generated/backup.pb.h"
+
+#include <iostream>
+#include <memory>
+#include <string>
+
+#include <chrono>
+#include <thread>
+
+namespace comm {
+namespace network {
+namespace reactor {
+
+class CreateNewBackupReactor : public ServerBidiReactorBase<
+ backup::CreateNewBackupRequest,
+ backup::CreateNewBackupResponse> {
+ enum class State {
+ KEY_ENTROPY = 1,
+ DATA_HASH = 2,
+ DATA_CHUNKS = 3,
+ };
+
+ State state = State::KEY_ENTROPY;
+ std::string keyEntropy;
+ std::string dataHash;
+ std::string backupID;
+
+ std::string generateBackupID();
+
+public:
+ std::unique_ptr<ServerBidiReactorStatus> handleRequest(
+ backup::CreateNewBackupRequest request,
+ backup::CreateNewBackupResponse *response) override;
+ void doneCallback();
+};
+
+std::string CreateNewBackupReactor::generateBackupID() {
+ // mock
+ return generateRandomString();
+}
+
+std::unique_ptr<ServerBidiReactorStatus> CreateNewBackupReactor::handleRequest(
+ backup::CreateNewBackupRequest request,
+ backup::CreateNewBackupResponse *response) {
+ std::cout << "[CNR] here handle request" << std::endl;
+ switch (this->state) {
+ case State::KEY_ENTROPY: {
+ if (!request.has_keyentropy()) {
+ throw std::runtime_error(
+ "backup key entropy expected but not received");
+ }
+ std::cout << "[CNR] here handle request key entropy" << std::endl;
+ this->keyEntropy = request.keyentropy();
+ this->state = State::DATA_HASH;
+ return nullptr;
+ }
+ case State::DATA_HASH: {
+ if (!request.has_newcompactionhash()) {
+ throw std::runtime_error("data hash expected but not received");
+ }
+ this->dataHash = request.newcompactionhash();
+ this->state = State::DATA_CHUNKS;
+
+ // TODO confirm - holder may be a backup id
+ this->backupID = this->generateBackupID();
+ ServiceBlobClient::getInstance().put(this->backupID, this->dataHash);
+ return nullptr;
+ }
+ case State::DATA_CHUNKS: {
+ std::cout << "[CNR] here handle request data chunk "
+ << request.newcompactionchunk().size() << std::endl;
+ // TODO initialize blob client reactor
+ if (ServiceBlobClient::getInstance().putReactor == nullptr) {
+ throw std::runtime_error(
+ "blob client reactor has not been initialized");
+ }
+ std::cout << "[CNR] here enqueueing data chunk" << std::endl;
+
+ ServiceBlobClient::getInstance().putReactor->scheduleSendingDataChunk(
+ request.newcompactionchunk());
+
+ return nullptr;
+ }
+ }
+ throw std::runtime_error("new backup - invalid state");
+}
+
+void CreateNewBackupReactor::doneCallback() {
+ std::cout << "[CNR] create new backup done " << this->status.status.error_code()
+ << "/" << this->status.status.error_message() << std::endl;
+ std::cout << "[CNR] enqueueing empty chunk to end blob upload" << std::endl;
+ ServiceBlobClient::getInstance().putReactor->scheduleSendingDataChunk("");
+}
+
+} // namespace reactor
+} // namespace network
+} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 5:42 PM (11 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2707811
Default Alt Text
D3467.id10719.diff (3 KB)
Attached To
Mode
D3467: [services] Backup - Add server reactor implementations - create new backup reactor
Attached
Detach File
Event Timeline
Log In to Comment