Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3377952
D3800.id11791.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Referenced Files
None
Subscribers
None
D3800.id11791.diff
View Options
diff --git a/services/backup/src/Reactors/BaseReactor.h b/services/backup/src/Reactors/BaseReactor.h
--- a/services/backup/src/Reactors/BaseReactor.h
+++ b/services/backup/src/Reactors/BaseReactor.h
@@ -2,6 +2,8 @@
#include <grpcpp/grpcpp.h>
+#include <mutex>
+
namespace comm {
namespace network {
namespace reactor {
@@ -14,12 +16,25 @@
};
class BaseReactor {
+private:
+ grpc::Status status = grpc::Status::OK;
+ std::mutex statusAccessMutex;
protected:
ReactorState state = ReactorState::NONE;
public:
+ grpc::Status getStatus() {
+ const std::unique_lock<std::mutex> lock(this->statusAccessMutex);
+ return this->status;
+ }
+ void setStatus(const grpc::Status &status) {
+ const std::unique_lock<std::mutex> lock(this->statusAccessMutex);
+ this->status = status;
+ }
+
ReactorState getState() const {
return this->state;
}
+
virtual void terminate(const grpc::Status &status){};
virtual void validate(){};
virtual void doneCallback(){};
diff --git a/services/backup/src/Reactors/client/base-reactors/ClientBidiReactorBase.h b/services/backup/src/Reactors/client/base-reactors/ClientBidiReactorBase.h
--- a/services/backup/src/Reactors/client/base-reactors/ClientBidiReactorBase.h
+++ b/services/backup/src/Reactors/client/base-reactors/ClientBidiReactorBase.h
@@ -16,7 +16,6 @@
protected:
Request request;
- grpc::Status status = grpc::Status::OK;
public:
grpc::ClientContext context;
@@ -82,11 +81,11 @@
template <class Request, class Response>
void ClientBidiReactorBase<Request, Response>::terminate(
const grpc::Status &status) {
- if (this->status.ok()) {
- this->status = status;
+ if (this->getStatus().ok()) {
+ this->setStatus(status);
}
- if (!this->status.ok()) {
- std::cout << "error: " << this->status.error_message() << std::endl;
+ if (!this->getStatus().ok()) {
+ std::cout << "error: " << this->getStatus().error_message() << std::endl;
}
if (this->state != ReactorState::RUNNING) {
return;
@@ -95,7 +94,7 @@
try {
this->validate();
} catch (std::runtime_error &e) {
- this->status = grpc::Status(grpc::StatusCode::INTERNAL, e.what());
+ this->setStatus(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}
this->StartWritesDone();
this->state = ReactorState::TERMINATED;
diff --git a/services/backup/src/Reactors/client/base-reactors/ClientReadReactorBase.h b/services/backup/src/Reactors/client/base-reactors/ClientReadReactorBase.h
--- a/services/backup/src/Reactors/client/base-reactors/ClientReadReactorBase.h
+++ b/services/backup/src/Reactors/client/base-reactors/ClientReadReactorBase.h
@@ -12,10 +12,6 @@
class ClientReadReactorBase : public grpc::ClientReadReactor<Response>,
public BaseReactor {
Response response;
-
-protected:
- grpc::Status status = grpc::Status::OK;
-
public:
Request request;
grpc::ClientContext context;
@@ -64,11 +60,11 @@
template <class Request, class Response>
void ClientReadReactorBase<Request, Response>::terminate(
const grpc::Status &status) {
- if (this->status.ok()) {
- this->status = status;
+ if (this->getStatus().ok()) {
+ this->setStatus(status);
}
- if (!this->status.ok()) {
- std::cout << "error: " << this->status.error_message() << std::endl;
+ if (!this->getStatus().ok()) {
+ std::cout << "error: " << this->getStatus().error_message() << std::endl;
}
if (this->state != ReactorState::RUNNING) {
return;
@@ -77,7 +73,7 @@
try {
this->validate();
} catch (std::runtime_error &e) {
- this->status = grpc::Status(grpc::StatusCode::INTERNAL, e.what());
+ this->setStatus(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}
this->state = ReactorState::TERMINATED;
}
diff --git a/services/backup/src/Reactors/client/base-reactors/ClientWriteReactorBase.h b/services/backup/src/Reactors/client/base-reactors/ClientWriteReactorBase.h
--- a/services/backup/src/Reactors/client/base-reactors/ClientWriteReactorBase.h
+++ b/services/backup/src/Reactors/client/base-reactors/ClientWriteReactorBase.h
@@ -11,7 +11,6 @@
template <class Request, class Response>
class ClientWriteReactorBase : public grpc::ClientWriteReactor<Request>,
public BaseReactor {
- grpc::Status status = grpc::Status::OK;
Request request;
void nextWrite();
@@ -67,11 +66,11 @@
template <class Request, class Response>
void ClientWriteReactorBase<Request, Response>::terminate(
const grpc::Status &status) {
- if (this->status.ok()) {
- this->status = status;
+ if (this->getStatus().ok()) {
+ this->setStatus(status);
}
- if (!this->status.ok()) {
- std::cout << "error: " << this->status.error_message() << std::endl;
+ if (!this->getStatus().ok()) {
+ std::cout << "error: " << this->getStatus().error_message() << std::endl;
}
if (this->state != ReactorState::RUNNING) {
return;
@@ -80,7 +79,7 @@
try {
this->validate();
} catch (std::runtime_error &e) {
- this->status = grpc::Status(grpc::StatusCode::INTERNAL, e.what());
+ this->setStatus(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}
this->state = ReactorState::TERMINATED;
this->StartWritesDone();
diff --git a/services/backup/src/Reactors/client/blob/BlobGetClientReactor.h b/services/backup/src/Reactors/client/blob/BlobGetClientReactor.h
--- a/services/backup/src/Reactors/client/blob/BlobGetClientReactor.h
+++ b/services/backup/src/Reactors/client/blob/BlobGetClientReactor.h
@@ -28,7 +28,6 @@
std::unique_ptr<grpc::Status>
readResponse(blob::GetResponse &response) override;
void doneCallback() override;
- grpc::Status getStatus() const;
};
} // namespace reactor
diff --git a/services/backup/src/Reactors/client/blob/BlobGetClientReactor.cpp b/services/backup/src/Reactors/client/blob/BlobGetClientReactor.cpp
--- a/services/backup/src/Reactors/client/blob/BlobGetClientReactor.cpp
+++ b/services/backup/src/Reactors/client/blob/BlobGetClientReactor.cpp
@@ -23,10 +23,6 @@
this->dataChunks->write("");
}
-grpc::Status BlobGetClientReactor::getStatus() const {
- return this->status;
-}
-
} // namespace reactor
} // namespace network
} // namespace comm
diff --git a/services/backup/src/Reactors/client/blob/BlobPutClientReactor.h b/services/backup/src/Reactors/client/blob/BlobPutClientReactor.h
--- a/services/backup/src/Reactors/client/blob/BlobPutClientReactor.h
+++ b/services/backup/src/Reactors/client/blob/BlobPutClientReactor.h
@@ -47,7 +47,6 @@
blob::PutRequest &request,
std::shared_ptr<blob::PutResponse> previousResponse) override;
void doneCallback() override;
- grpc::Status getStatus() const;
bool getDataExists() const;
};
diff --git a/services/backup/src/Reactors/client/blob/BlobPutClientReactor.cpp b/services/backup/src/Reactors/client/blob/BlobPutClientReactor.cpp
--- a/services/backup/src/Reactors/client/blob/BlobPutClientReactor.cpp
+++ b/services/backup/src/Reactors/client/blob/BlobPutClientReactor.cpp
@@ -54,10 +54,6 @@
this->terminationNotifier->notify_one();
}
-grpc::Status BlobPutClientReactor::getStatus() const {
- return this->status;
-}
-
bool BlobPutClientReactor::getDataExists() const {
return this->dataExists;
}
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
@@ -147,8 +147,8 @@
// as there may be multiple threads from the pool taking over here
const std::lock_guard<std::mutex> lock(this->reactorStateMutex);
// TODO implement
- std::cout << "receive logs done " << this->status.error_code() << "/"
- << this->status.error_message() << std::endl;
+ std::cout << "receive logs done " << this->getStatus().error_code() << "/"
+ << this->getStatus().error_message() << std::endl;
}
} // namespace reactor
diff --git a/services/backup/src/Reactors/server/base-reactors/ServerBidiReactorBase.h b/services/backup/src/Reactors/server/base-reactors/ServerBidiReactorBase.h
--- a/services/backup/src/Reactors/server/base-reactors/ServerBidiReactorBase.h
+++ b/services/backup/src/Reactors/server/base-reactors/ServerBidiReactorBase.h
@@ -24,14 +24,15 @@
};
template <class Request, class Response>
-class ServerBidiReactorBase
- : public grpc::ServerBidiReactor<Request, Response>, public BaseReactor {
+class ServerBidiReactorBase : public grpc::ServerBidiReactor<Request, Response>,
+ public BaseReactor {
Request request;
Response response;
protected:
ServerBidiReactorStatus status;
bool readingAborted = false;
+
public:
ServerBidiReactorBase();
@@ -40,6 +41,8 @@
void OnWriteDone(bool ok) override;
void terminate(ServerBidiReactorStatus status);
+ ServerBidiReactorStatus getStatus() const;
+ void setStatus(const ServerBidiReactorStatus &status);
virtual std::unique_ptr<ServerBidiReactorStatus>
handleRequest(Request request, Response *response) = 0;
@@ -63,26 +66,38 @@
template <class Request, class Response>
void ServerBidiReactorBase<Request, Response>::terminate(
ServerBidiReactorStatus status) {
- this->status = status;
+ this->setStatus(status);
try {
this->terminateCallback();
this->validate();
} catch (std::runtime_error &e) {
- this->status = ServerBidiReactorStatus(
- grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
+ this->setStatus(ServerBidiReactorStatus(
+ grpc::Status(grpc::StatusCode::INTERNAL, e.what())));
}
if (this->state != ReactorState::RUNNING) {
return;
}
- if (this->status.sendLastResponse) {
+ if (this->getStatus().sendLastResponse) {
this->StartWriteAndFinish(
- &this->response, grpc::WriteOptions(), this->status.status);
+ &this->response, grpc::WriteOptions(), this->getStatus().status);
} else {
- this->Finish(this->status.status);
+ this->Finish(this->getStatus().status);
}
this->state = ReactorState::TERMINATED;
}
+template <class Request, class Response>
+ServerBidiReactorStatus
+ServerBidiReactorBase<Request, Response>::getStatus() const {
+ return this->status;
+}
+
+template <class Request, class Response>
+void ServerBidiReactorBase<Request, Response>::setStatus(
+ const ServerBidiReactorStatus &status) {
+ this->status = status;
+}
+
template <class Request, class Response>
void ServerBidiReactorBase<Request, Response>::OnReadDone(bool ok) {
if (!ok) {
diff --git a/services/backup/src/Reactors/server/base-reactors/ServerReadReactorBase.h b/services/backup/src/Reactors/server/base-reactors/ServerReadReactorBase.h
--- a/services/backup/src/Reactors/server/base-reactors/ServerReadReactorBase.h
+++ b/services/backup/src/Reactors/server/base-reactors/ServerReadReactorBase.h
@@ -19,8 +19,6 @@
Request request;
protected:
Response *response;
- grpc::Status status;
-
public:
ServerReadReactorBase(Response *response);
void OnReadDone(bool ok) override;
@@ -62,20 +60,20 @@
template <class Request, class Response>
void ServerReadReactorBase<Request, Response>::terminate(
const grpc::Status &status) {
- this->status = status;
+ this->setStatus(status);
try {
this->terminateCallback();
this->validate();
} catch (std::runtime_error &e) {
- this->status = grpc::Status(grpc::StatusCode::INTERNAL, e.what());
+ this->setStatus(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}
- if (!this->status.ok()) {
- std::cout << "error: " << this->status.error_message() << std::endl;
+ if (!this->getStatus().ok()) {
+ std::cout << "error: " << this->getStatus().error_message() << std::endl;
}
if (this->state != ReactorState::RUNNING) {
return;
}
- this->Finish(this->status);
+ this->Finish(this->getStatus());
this->state = ReactorState::TERMINATED;
}
diff --git a/services/backup/src/Reactors/server/base-reactors/ServerWriteReactorBase.h b/services/backup/src/Reactors/server/base-reactors/ServerWriteReactorBase.h
--- a/services/backup/src/Reactors/server/base-reactors/ServerWriteReactorBase.h
+++ b/services/backup/src/Reactors/server/base-reactors/ServerWriteReactorBase.h
@@ -24,8 +24,6 @@
protected:
// this is a const ref since it's not meant to be modified
const Request &request;
- grpc::Status status;
-
public:
ServerWriteReactorBase(const Request *request);
@@ -42,20 +40,20 @@
template <class Request, class Response>
void ServerWriteReactorBase<Request, Response>::terminate(
const grpc::Status &status) {
- this->status = status;
+ this->setStatus(status);
try {
this->terminateCallback();
this->validate();
} catch (std::runtime_error &e) {
- this->status = grpc::Status(grpc::StatusCode::INTERNAL, e.what());
+ this->setStatus(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}
- if (!this->status.ok()) {
- std::cout << "error: " << this->status.error_message() << std::endl;
+ if (!this->getStatus().ok()) {
+ std::cout << "error: " << this->getStatus().error_message() << std::endl;
}
if (this->state != ReactorState::RUNNING) {
return;
}
- this->Finish(this->status);
+ this->Finish(this->getStatus());
this->state = ReactorState::TERMINATED;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 8:19 AM (19 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2593302
Default Alt Text
D3800.id11791.diff (13 KB)
Attached To
Mode
D3800: [services] Backup - synchronize status access in reactors
Attached
Detach File
Event Timeline
Log In to Comment