-
Notifications
You must be signed in to change notification settings - Fork 4.1k
ARROW-4558: [C++][Flight] Implement gRPC customizations without UB #3633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
23fe416
ac405b3
b3609d4
ed6eb80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <limits> | ||
| #include <memory> | ||
|
|
||
| #include "grpcpp/impl/codegen/config_protobuf.h" | ||
| #undef GRPC_OPEN_SOURCE_PROTO | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment on this? I think it's easy to miss it or misunderstand why it's here. (as in "what happens if I remove this")
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| #include "grpcpp/impl/codegen/proto_utils.h" | ||
|
|
||
| namespace arrow { | ||
| namespace ipc { | ||
| namespace internal { | ||
|
|
||
| struct IpcPayload; | ||
|
|
||
| } // namespace internal | ||
| } // namespace ipc | ||
|
|
||
| namespace flight { | ||
|
|
||
| struct FlightData; | ||
|
|
||
| namespace protocol { | ||
|
|
||
| class FlightData; | ||
|
|
||
| } // namespace protocol | ||
| } // namespace flight | ||
| } // namespace arrow | ||
|
|
||
| namespace grpc { | ||
|
|
||
| using arrow::flight::FlightData; | ||
| using arrow::ipc::internal::IpcPayload; | ||
|
|
||
| class ByteBuffer; | ||
| class Status; | ||
|
|
||
| Status FlightDataSerialize(const IpcPayload& msg, ByteBuffer* out, bool* own_buffer); | ||
| Status FlightDataDeserialize(ByteBuffer* buffer, FlightData* out); | ||
|
|
||
| // This class provides a protobuf serializer. It translates between protobuf | ||
| // objects and grpc_byte_buffers. More information about SerializationTraits can | ||
| // be found in include/grpcpp/impl/codegen/serialization_traits.h. | ||
| template <class T> | ||
| class SerializationTraits< | ||
| T, typename std::enable_if< | ||
| std::is_base_of<grpc::protobuf::Message, T>::value && | ||
| !std::is_same<arrow::flight::protocol::FlightData, T>::value>::type> { | ||
| public: | ||
| static Status Serialize(const grpc::protobuf::Message& msg, ByteBuffer* bb, | ||
| bool* own_buffer) { | ||
| return GenericSerialize<ProtoBufferWriter, T>(msg, bb, own_buffer); | ||
| } | ||
|
|
||
| static Status Deserialize(ByteBuffer* buffer, grpc::protobuf::Message* msg) { | ||
| return GenericDeserialize<ProtoBufferReader, T>(buffer, msg); | ||
| } | ||
| }; | ||
|
|
||
| template <class T> | ||
| class SerializationTraits<T, typename std::enable_if<std::is_same< | ||
| arrow::flight::protocol::FlightData, T>::value>::type> { | ||
| public: | ||
| static Status Serialize(const grpc::protobuf::Message& msg, ByteBuffer* bb, | ||
| bool* own_buffer) { | ||
| return FlightDataSerialize(*reinterpret_cast<const IpcPayload*>(&msg), bb, | ||
| own_buffer); | ||
| } | ||
|
|
||
| static Status Deserialize(ByteBuffer* buffer, grpc::protobuf::Message* msg) { | ||
| return FlightDataDeserialize(buffer, reinterpret_cast<FlightData*>(msg)); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace grpc | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
|
|
||
| #include "arrow/flight/protocol.h" | ||
|
|
||
| #include "arrow/flight/Flight.grpc.pb.cc" // NOLINT | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the trick of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears that the linker (at least with gcc on Linux) was seeing the vtable generated in Flight.grpc.pb.cc and overriding the ones in server.cc/client.cc. This was the only way I could make sure that the same code is generated in all places There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd appreciate a comment about that just so that someone else looking at it isn't confused.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| #include "arrow/flight/Flight.pb.cc" // NOLINT | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
|
|
||
| #pragma once | ||
|
|
||
| // Need to include this first to get our gRPC customizations | ||
| #include "arrow/flight/customize_protobuf.h" | ||
|
|
||
| #include "arrow/flight/Flight.grpc.pb.h" | ||
| #include "arrow/flight/Flight.pb.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we are praying that
Writedoesn't do anything with the FlightData pointer except pass it toSerializationTraits<FlightData>, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. But the reader/writer layers have no knowledge of the message types; SerializationTraits is the only point of contact
https://github.com/grpc/grpc/blob/f41affc9c7e0358612b9747e914e8b01af53f75d/include/grpcpp/impl/codegen/call_op_set.h#L395
https://github.com/grpc/grpc/blob/46bd2f7adb926053345665d5c487fa20acd2b5b0/include/grpcpp/impl/codegen/server_interface.h#L255