[grpc] Support latest version of grpc PoC #6338
Conversation
|
A cast is all that's need to make this work? Wow. But yeah, that could break badly at some point.. Maybe we can throw a @pavanbadugu @joseprupi @thomas-t1 @yaoshengzhe @aashray @inobelar @MarceColl from the other thread. |
|
Do we not have to update the cpp_generator.cc file from the grpc release version source code to the flatbuffers repo? It looks like though there will need to some some changes related to not using grpc::string in favor of std::string and a couple of minor fixes. |
|
This has resolved the gRPC 1.35 integration issues in our systems! Thanks! |
|
Travis CI failed because And the Bazel build fails with:
|
|
@youknowone what is the status on this PR? I would love to have it be part of the following redesign #6443 |
|
@mustiikhalil This is not an actual PR. So maybe the status is invalid. This PR shows how to (unsafely) solve the problem. As described in the issue text, I wish someone actually can solve the problem better way in future. |
|
I just wanted to share our experience in case someone is interested; We attempted to use gRPC with flatbuffers as a solution for RPC on resource restricted platforms/embedded, but it ultimately failed for a couple of reasons; You could argue that none of them has to do with flatbuffers, but in part has to do with the gRPC integration, so I'll write it up anyway;
So in the end we decided to roll our own RPC mechanism with flatbuffers as binary serialization format, but inspired by the payload format of gRPC, so in addition to client/server code generation, it allowed us to build a gRPC to/from our-internal-RPC proxy that does not require knowledge of the schema/service definition. |
|
@youknowone so whenever a user is generating a cpp grpc file they would have the following options @aardappel what do you think? On a side note, I don't think we would be able to support the current gRPC apis unless someone is willing to work on it, if we want to have it before the flatbuffers 2.0 release. If not I can take a look at it but that might be in later this year |
|
@mustiikhalil I am fine supporting this "hack" until grpc break it. My worry would be how we will found out if grpc break it, since it is just a cast, so it could be silent breakage that just corrupts data. Also not sure if we need a flag, since who will still be using an old grpc that doesn't have this problem? |
|
@aardappel what we can do is actually implement tests for this "hacky" solution for now. The flag would be for the new cpp generated code that adheres to the their APIs. so what i mean is the following:
|
|
@aardappel Tagged you on grpc/grpc#20594 which I've been following up on regarding similar concerns. |
|
Ok, looks like someone from gRPC will be looking at this in Q2. Still suggest to move forward with workarounds in the meantime. Once there is a better path we can adopt it. |
|
@mustiikhalil should we just merge this "hack" for now, and then you add your proposed flags after, or do you want to work on those first / in one PR? |
The flags were supposed to be whenever we support the new API generation for grpc, so that won't be anytime soon. So for now, we have to settle with the hack.
And if there is someone who would be looking into it, I believe we should wait before generating the new grpc apis. since this "hacky" solution might be a permanent one The PR is still failing, and it needs:
if the author is not willing to continue to work on it, I can just recreate it and finalize the hacky solution @aardappel ping @youknowone |
|
Oh, I wasn't expecting this will be going to be merged as it is. If it will be, I will clean up and fix broken parts. |
|
If possible can you rebase, so we can have the code generator github action and the new layout for the example code. |
|
I followed up the thread and realized lots things happend recently. I'd better to look in this earlier. Sorry for a week absence. @mustiikhalil About the broken code, I made an accidental force-push. So first 2 comments are based on the other version. The first version --- a/include/flatbuffers/grpc.h
+++ b/include/flatbuffers/grpc.h
@@ -287,8 +287,9 @@ template<class T> class SerializationTraits<flatbuffers::grpc::Message<T>> {
}
// Deserialize by pulling the
- static grpc::Status Deserialize(grpc_byte_buffer *buffer,
+ static grpc::Status Deserialize(ByteBuffer *buf,
flatbuffers::grpc::Message<T> *msg) {
+ grpc_byte_buffer *buffer = *reinterpret_cast<grpc_byte_buffer**>(buf);
if (!buffer) {
return ::grpc::Status(::grpc::StatusCode::INTERNAL, "No payload");
}And I was on the way to make second version because this would be a bit better to detect future break change if it works. But never finished and never tested. Still I think this version also will eventually work, because they are intending the same thing. --- a/include/flatbuffers/grpc.h
+++ b/include/flatbuffers/grpc.h
@@ -20,7 +20,9 @@
// Helper functionality to glue FlatBuffers and GRPC.
#include "flatbuffers/flatbuffers.h"
+#define private public
#include "grpcpp/support/byte_buffer.h"
+#undef private
#include "grpc/byte_buffer_reader.h"
namespace flatbuffers {
@@ -287,8 +289,9 @@ template<class T> class SerializationTraits<flatbuffers::grpc::Message<T>> {
}
// Deserialize by pulling the
- static grpc::Status Deserialize(grpc_byte_buffer *buffer,
+ static grpc::Status Deserialize(ByteBuffer *buf,
flatbuffers::grpc::Message<T> *msg) {
+ grpc_byte_buffer *buffer = buf->c_buffer();
if (!buffer) {
return ::grpc::Status(::grpc::StatusCode::INTERNAL, "No payload");
}I think force-push happened before the major discussion, so most of comments are about the second version. But one of the participant @aardappel maybe is thinking about the first version. So to make clear, which one is preferred? For the second version, I think it need some more compiler directive works to not to generate warning for the macro |
| flatbuffers::grpc::Message<T> *msg) { | ||
| grpc_byte_buffer *buffer = buf->c_buffer(); | ||
| if (!buffer) { |
mustiikhalil
Mar 3, 2021
Collaborator
The CI isn't happy about the casting to c_buffer()
external/com_github_grpc_grpc/include/grpcpp/impl/codegen/byte_buffer.h:167:21: error: 'grpc_byte_buffer* grpc::ByteBuffer::c_buffer()' is private
--
| grpc_byte_buffer* c_buffer() { return buffer_; }
| ^
| In file included from tests/monster_test.grpc.fb.h:8:0,
| from grpc/tests/grpctest.cpp:21:
| bazel-out/k8-fastbuild/bin/_virtual_includes/flatbuffers/flatbuffers/grpc.h:294:45: error: within this context
| grpc_byte_buffer *buffer = buf->c_buffer();
The CI isn't happy about the casting to c_buffer()
external/com_github_grpc_grpc/include/grpcpp/impl/codegen/byte_buffer.h:167:21: error: 'grpc_byte_buffer* grpc::ByteBuffer::c_buffer()' is private
--
| grpc_byte_buffer* c_buffer() { return buffer_; }
| ^
| In file included from tests/monster_test.grpc.fb.h:8:0,
| from grpc/tests/grpctest.cpp:21:
| bazel-out/k8-fastbuild/bin/_virtual_includes/flatbuffers/flatbuffers/grpc.h:294:45: error: within this context
| grpc_byte_buffer *buffer = buf->c_buffer();
adityajaltade
Mar 3, 2021
•
The issue with this is the in the grpc header byte_buffer.h the only friend class for SerializationTraits is defined here https://github.com/grpc/grpc/blob/master/include/grpcpp/impl/codegen/byte_buffer.h#L159 and is friend class SerializationTraits<ByteBuffer, void>;
In the case of include/flatbuffers/grpc.h, the first template parameter is flatbuffers::grpc::Message<T> and not ByteBuffer, so it is not a friend class.
Locally, I've had to change the grpc repo's header file to allow all SerializationTraits template specializations to be a friend class.
template <class T, class T1>
friend class SerializationTraits;
So, this is really tough to solve unilaterally from just one repo and needs both the repos to be in agreement.
The issue with this is the in the grpc header byte_buffer.h the only friend class for SerializationTraits is defined here https://github.com/grpc/grpc/blob/master/include/grpcpp/impl/codegen/byte_buffer.h#L159 and is friend class SerializationTraits<ByteBuffer, void>;
In the case of include/flatbuffers/grpc.h, the first template parameter is flatbuffers::grpc::Message<T> and not ByteBuffer, so it is not a friend class.
Locally, I've had to change the grpc repo's header file to allow all SerializationTraits template specializations to be a friend class.
template <class T, class T1>
friend class SerializationTraits;
So, this is really tough to solve unilaterally from just one repo and needs both the repos to be in agreement.
youknowone
Mar 3, 2021
Author
Contributor
It is my fault regarding unfinished second patch option.
I suggest to forget about it for now.
Let's go back to original working casting one and see how to goes.
When we see a stable solution, let's try this one later.
It is my fault regarding unfinished second patch option.
I suggest to forget about it for now.
Let's go back to original working casting one and see how to goes.
When we see a stable solution, let's try this one later.
878296e
to
7cdad0c
|
The broken CI is mostly about upgrading grpc rather than the PR itself. For now, cmake+linux (finally! thanks to @Perlmint) passes but cmake+macos does not. Bazel build also does not. Unfortunately, I don't know well about either cmake or bazel, so it is not an easy challenge to me. Could anyone take this over for further work for build systems? |
c71f44b
to
c394615
92360fe
to
abf2fef
|
Finally, All checks are passed. I applied some workarounds for it. |
|
@aardappel this PR seems to be done now, not sure about how the patch for the CI is done though |
| make | ||
| make install prefix=`pwd`/install | ||
| # Apply boringssl build patch | ||
| cd third_party/boringssl-with-bazel |
aardappel
Mar 25, 2021
Collaborator
maybe some clear comments why this is needed?
maybe some clear comments why this is needed?
| @@ -104,6 +104,7 @@ matrix: | |||
| - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which gcc-$GCC_VERSION) /usr/bin/gcc; fi | |||
|
|
|||
| script: | |||
| - pip install cmake | |||
aardappel
Mar 25, 2021
Collaborator
why are the changes in this file needed? CI has always worked with the existing CMake.
why are the changes in this file needed? CI has always worked with the existing CMake.
Perlmint
Mar 25, 2021
Contributor
https://github.com/grpc/grpc/blob/master/CMakeLists.txt#L60-L66
https://github.com/grpc/grpc/blob/master/BUILDING.md#install-after-build
Recent gRPC does not support installing with compiling third-party on cmake < 3.13. If you don't want to update the cmake, you should manually install some third-party libraries. gRPC_*_PROVIDER=package is the only supported option for the cmake < 3.13, But It requires external dependencies.
https://github.com/grpc/grpc/blob/master/CMakeLists.txt#L60-L66
https://github.com/grpc/grpc/blob/master/BUILDING.md#install-after-build
Recent gRPC does not support installing with compiling third-party on cmake < 3.13. If you don't want to update the cmake, you should manually install some third-party libraries. gRPC_*_PROVIDER=package is the only supported option for the cmake < 3.13, But It requires external dependencies.
|
Ok, I will merge this for now, so we can move forward. There are clearly some unfortunate things in here, but it be better to improve those in follow-ups. Thanks so much @youknowone and @mustiikhalil for helping moving this situation forward! |
276b1bc
into
google:master
|
@aardappel what type of cleanup/improvements that would be required for this? |
|
@mustiikhalil maybe the 2 things I mention above.. and eventually, a more solid solution for the cast. But that can probably wait until we've had someone from the gRPC team look at this. |
|
Thank you everyone opened to choose this option. Merging this one is totally unexpected event when I first made this PR. I am happy to wait new flatbuffers work with latest gRPC again. |
Fix #5836 for gRPC 1.33.2
This is not ideal because second commit is depending on gRPC internal.
I am locally using this patch on flatbuffers v1.12.0, but not confident for future stability.
I wish this PoC can help anyone who actually want to work on this issue.