Skip to content

Commit

Permalink
runtime: set type_url for storage Any requests (#831)
Browse files Browse the repository at this point in the history
The prost protobuf library does not support message descriptors, so
encapsulated Any messages from Nodes cannot fill in the type_url
field.  However, the C++ protobuf library code that unpacks an Any
message into a specific protobuf message type requires this field
to be present and match.

Work around this by assuming that storage requests are of the correct
type, and modify the Any message to set its type_url field
appropriately.
  • Loading branch information
daviddrysdale authored Apr 9, 2020
1 parent 9bfc2a4 commit 4946661
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions oak/server/storage/storage_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ oak::StatusOr<std::unique_ptr<GrpcResponse>> StorageNode::ProcessMethod(GrpcRequ

if (method_name == "/oak.StorageNode/Read") {
StorageChannelReadRequest read_req;
// Assume the type of the embedded request is correct.
grpc_req->mutable_req_msg()->set_type_url("type.googleapis.com/" +
read_req.GetDescriptor()->full_name());
if (!grpc_req->req_msg().UnpackTo(&read_req)) {
return absl::Status(absl::StatusCode::kInvalidArgument, "Failed to unpack request");
}
Expand All @@ -105,6 +108,9 @@ oak::StatusOr<std::unique_ptr<GrpcResponse>> StorageNode::ProcessMethod(GrpcRequ

} else if (method_name == "/oak.StorageNode/Write") {
StorageChannelWriteRequest write_req;
// Assume the type of the embedded request is correct.
grpc_req->mutable_req_msg()->set_type_url("type.googleapis.com/" +
write_req.GetDescriptor()->full_name());
if (!grpc_req->req_msg().UnpackTo(&write_req)) {
return absl::Status(absl::StatusCode::kInvalidArgument, "Failed to unpack request");
}
Expand All @@ -116,6 +122,9 @@ oak::StatusOr<std::unique_ptr<GrpcResponse>> StorageNode::ProcessMethod(GrpcRequ

} else if (method_name == "/oak.StorageNode/Delete") {
StorageChannelDeleteRequest delete_req;
// Assume the type of the embedded request is correct.
grpc_req->mutable_req_msg()->set_type_url("type.googleapis.com/" +
delete_req.GetDescriptor()->full_name());
if (!grpc_req->req_msg().UnpackTo(&delete_req)) {
return absl::Status(absl::StatusCode::kInvalidArgument, "Failed to unpack request");
}
Expand All @@ -125,6 +134,9 @@ oak::StatusOr<std::unique_ptr<GrpcResponse>> StorageNode::ProcessMethod(GrpcRequ

} else if (method_name == "/oak.StorageNode/Begin") {
StorageChannelBeginRequest begin_req;
// Assume the type of the embedded request is correct.
grpc_req->mutable_req_msg()->set_type_url("type.googleapis.com/" +
begin_req.GetDescriptor()->full_name());
if (!grpc_req->req_msg().UnpackTo(&begin_req)) {
return absl::Status(absl::StatusCode::kInvalidArgument, "Failed to unpack request");
}
Expand All @@ -136,6 +148,9 @@ oak::StatusOr<std::unique_ptr<GrpcResponse>> StorageNode::ProcessMethod(GrpcRequ

} else if (method_name == "/oak.StorageNode/Commit") {
StorageChannelCommitRequest commit_req;
// Assume the type of the embedded request is correct.
grpc_req->mutable_req_msg()->set_type_url("type.googleapis.com/" +
commit_req.GetDescriptor()->full_name());
if (!grpc_req->req_msg().UnpackTo(&commit_req)) {
return absl::Status(absl::StatusCode::kInvalidArgument, "Failed to unpack request");
}
Expand All @@ -144,6 +159,9 @@ oak::StatusOr<std::unique_ptr<GrpcResponse>> StorageNode::ProcessMethod(GrpcRequ

} else if (method_name == "/oak.StorageNode/Rollback") {
StorageChannelRollbackRequest rollback_req;
// Assume the type of the embedded request is correct.
grpc_req->mutable_req_msg()->set_type_url("type.googleapis.com/" +
rollback_req.GetDescriptor()->full_name());
if (!grpc_req->req_msg().UnpackTo(&rollback_req)) {
return absl::Status(absl::StatusCode::kInvalidArgument, "Failed to unpack request");
}
Expand Down

0 comments on commit 4946661

Please sign in to comment.