Skip to content

GH-50282: [C++][FlightRPC] Refactor GRPC server and transport classes - #50407

Draft
Alex-PLACET wants to merge 15 commits into
apache:mainfrom
Alex-PLACET:refactor/internal-transport
Draft

GH-50282: [C++][FlightRPC] Refactor GRPC server and transport classes#50407
Alex-PLACET wants to merge 15 commits into
apache:mainfrom
Alex-PLACET:refactor/internal-transport

Conversation

@Alex-PLACET

@Alex-PLACETAlex-PLACET commented Jul 7, 2026

Copy link
Copy Markdown

The goal of the pullrequest is to refactor the FligtRPC code to prepare the async implementation. I moved code from grpc_server and transport_server to the _internal files which will be used in both sync and async server implmentations.
I also created dedicated function for specific responsabilities and reduce code complexity or duplication.

@github-actionsgithub-actionsBot added the awaiting review Awaiting review label Jul 7, 2026
@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@Alex-PLACETAlex-PLACET changed the title GH-#50282: [C++][FlightRPC] Refactor GRPC server and transport classesGH-50282: [C++][FlightRPC] Refactor GRPC server and transport classesJul 7, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #50282has been automatically assigned in GitHub to PR creator.

@Alex-PLACET

Copy link
Copy Markdown
Author

@raulcd Can you launch the CI please

@Alex-PLACET

Copy link
Copy Markdown
Author

@raulcd Can you run the CI again please?

@Alex-PLACET

Copy link
Copy Markdown
Author

@raulcd Can you launch the CI please

@Alex-PLACET

Copy link
Copy Markdown
Author

@raulcd Can you launch the CI please (I hope it will be the last time)

@raulcd

Copy link
Copy Markdown
Member

@raulcd Can you launch the CI please (I hope it will be the last time)

Sorry @Alex-PLACET , I missed this comment. Just kicked it

@Alex-PLACET
Alex-PLACETforce-pushed the refactor/internal-transport branch from f3c0c73 to 560bd8dCompareJuly 23, 2026 11:40
@Alex-PLACET
Alex-PLACETforce-pushed the refactor/internal-transport branch from 560bd8d to 20c2325CompareJuly 23, 2026 11:41
Comment on lines +226 to +227
Protobuf_SOURCE=BUNDLED \
gRPC_SOURCE=BUNDLED \

@raulcdraulcdJul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably bump ARROW_GRPC_REQUIRED_VERSION. I am pretty sure if Ubuntu 22.04 ships older GRPC than necessary, we will also have to update the Linux Package jobs (.deb) for old ubuntu (potentially also for old Red Hat?), I'll kick off Linux Packages.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the label doesn't work well with draft, PRs, I am unsure why the Linux Package jobs did not trigger, I'll take a look.

::grpc::ByteBuffer* buffer, arrow::flight::internal::FlightData* out);

ARROW_FLIGHT_EXPORT
bool IsRegisteredGrpcFlightDataMessage(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add some comments on why now we have to register/unregister FlightData messages. Are those necessary?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point was I got some issue with protobuf and I though it was because of a mess with with FlightPayload. I think I introduce an issue at some point it fixed it later in my development. I just removed this mechanism as it is useless now.

@raulcdraulcd added the CI: Extra: Package: Linux Run extra Linux Packages CI label Jul 31, 2026
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Jul 31, 2026

@Alex-PLACETAlex-PLACETSep 2, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the code was moved from transport_server.cc

std::vector<std::shared_ptr<ServerMiddleware>> middleware_;
std::unordered_map<std::string, std::shared_ptr<ServerMiddleware>> middleware_map_;
CallHeaders incoming_headers_;
};

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actionsgithub-actionsBot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Sep 2, 2026
Comment on lines -586 to -621
// Allow uploading messages of any length
builder.SetMaxReceiveMessageSize(-1);

const std::string scheme = uri.scheme();
int port = 0;
if (scheme == kSchemeGrpc || scheme == kSchemeGrpcTcp || scheme == kSchemeGrpcTls) {
std::stringstream address;
address << arrow::util::UriEncodeHost(uri.host()) << ':' << uri.port_text();

std::shared_ptr<::grpc::ServerCredentials> creds;
if (scheme == kSchemeGrpcTls) {
::grpc::SslServerCredentialsOptions ssl_options;
for (const auto& pair : options.tls_certificates) {
ssl_options.pem_key_cert_pairs.push_back({pair.pem_key, pair.pem_cert});
}
if (options.verify_client) {
ssl_options.client_certificate_request =
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY;
}
if (!options.root_certificates.empty()) {
ssl_options.pem_root_certs = options.root_certificates;
}
creds = ::grpc::SslServerCredentials(ssl_options);
} else {
creds = ::grpc::InsecureServerCredentials();
}

builder.AddListeningPort(address.str(), creds, &port);
} else if (scheme == kSchemeGrpcUnix) {
std::stringstream address;
address << "unix:" << uri.path();
builder.AddListeningPort(address.str(), ::grpc::InsecureServerCredentials());
location_ = options.location;
} else {
return Status::NotImplemented("Scheme is not supported: " + scheme);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a dedicated function: AddServerListeningPort

Comment on lines +38 to +74
Status AddServerListeningPort(const FlightServerOptions& options,
const arrow::util::Uri& uri, ::grpc::ServerBuilder* builder,
Location* location, int* port) {
const std::string scheme = uri.scheme();
if (scheme == kSchemeGrpc || scheme == kSchemeGrpcTcp || scheme == kSchemeGrpcTls) {
std::stringstream address;
address << arrow::util::UriEncodeHost(uri.host()) << ':' << uri.port_text();

std::shared_ptr<::grpc::ServerCredentials> creds;
if (scheme == kSchemeGrpcTls) {
::grpc::SslServerCredentialsOptions ssl_options;
for (const auto& pair : options.tls_certificates) {
ssl_options.pem_key_cert_pairs.push_back({pair.pem_key, pair.pem_cert});
}
if (options.verify_client) {
ssl_options.client_certificate_request =
GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY;
}
if (!options.root_certificates.empty()) {
ssl_options.pem_root_certs = options.root_certificates;
}
creds = ::grpc::SslServerCredentials(ssl_options);
} else {
creds = ::grpc::InsecureServerCredentials();
}
builder->AddListeningPort(address.str(), creds, port);
return Status::OK();
}
if (scheme == kSchemeGrpcUnix) {
std::stringstream address;
address << "unix:" << uri.path();
builder->AddListeningPort(address.str(), ::grpc::InsecureServerCredentials());
*location = options.location;
return Status::OK();
}
return Status::NotImplemented("Scheme is not supported: " + scheme);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from grpc_server.cc

}

namespace {
class TransportIpcMessageReader : public ipc::MessageReader {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to transport_server_internal.cc

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the code comes from server.cc

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the code moved to grpc_server_internal cpp and h

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Alex-PLACET@raulcd