-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add gRPC support to FDB #11782
base: main
Are you sure you want to change the base?
Add gRPC support to FDB #11782
Changes from all commits
e7629c7
8cacc14
d322bb2
efc66d1
e09d497
0ad35ff
965cea6
f7fcbdd
f5bfe17
780f53d
f4a6da3
171d269
010a473
86f9573
4272db5
c0a9baf
f6052bb
3d81782
fc27c9b
02429ed
b69646d
997d15b
bf5ca81
1b822c6
17eb913
b24bedb
ee8ccc7
dc3c12a
8814ab4
8036f3b
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,21 @@ | ||
/** | ||
* FileTransfer.cpp | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2013-2024 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
#include "fdbrpc/FileTransfer.h" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* gRPC.actor.cpp | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2013-2024 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
#include <cstdio> | ||
#include <thread> | ||
#include "fdbrpc/FlowGrpc.h" | ||
|
||
#include "flow/actorcompiler.h" // This must be the last #include. | ||
|
||
GrpcServer::GrpcServer(const NetworkAddress& addr) : address_(addr) {} | ||
|
||
GrpcServer::~GrpcServer() { | ||
if (server_) { | ||
shutdown(); | ||
} | ||
|
||
if (server_thread_.joinable()) { | ||
server_thread_.join(); | ||
} | ||
} | ||
|
||
Future<Void> GrpcServer::run() { | ||
grpc::ServerBuilder builder_; | ||
builder_.AddListeningPort(address_.toString(), grpc::InsecureServerCredentials()); | ||
for (auto& service : registered_services_) { | ||
builder_.RegisterService(service.get()); | ||
} | ||
server_ = builder_.BuildAndStart(); | ||
return server_promise_.getFuture(); | ||
} | ||
|
||
void GrpcServer::shutdown() { | ||
server_->Shutdown(); // TODO (Vishesh): This needs to be Future. | ||
server_promise_.send(Void()); | ||
server_ = nullptr; | ||
} | ||
|
||
void GrpcServer::registerService(std::shared_ptr<grpc::Service> service) { | ||
registered_services_.push_back(service); | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* FlowGrpcTests.actor.cpp | ||
* | ||
* This source file is part of the FoundationDB open source project | ||
* | ||
* Copyright 2013-2024 Apple Inc. and the FoundationDB project authors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
#include <cstdio> | ||
|
||
#include "flow/UnitTest.h" | ||
#include "fdbrpc/FlowGrpc.h" | ||
#include "fdbrpc/FlowGrpcTests.h" | ||
|
||
#include "flow/actorcompiler.h" // This must be the last #include. | ||
|
||
// So that tests are not optimized out. :/ | ||
void forceLinkGrpcTests() {} | ||
|
||
namespace fdbrpc_test { | ||
namespace asio = boost::asio; | ||
|
||
TEST_CASE("/fdbrpc/grpc/basic_sync_client") { | ||
state NetworkAddress addr(NetworkAddress::parse("127.0.0.1:50001")); | ||
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. Test will fail if this port is already occupied? 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. Yes. I have make some sort of |
||
state GrpcServer server(addr); | ||
server.registerService(make_shared<TestEchoServiceImpl>()); | ||
state Future<Void> server_actor = server.run(); | ||
|
||
EchoClient client(grpc::CreateChannel(addr.toString(), grpc::InsecureChannelCredentials())); | ||
std::string reply = client.Echo("Ping!"); | ||
std::cout << "Echo received: " << reply << std::endl; | ||
ASSERT_EQ(reply, "Echo: Ping!"); | ||
|
||
server.shutdown(); | ||
wait(server_actor); | ||
return Void(); | ||
} | ||
|
||
TEST_CASE("/fdbrpc/grpc/basic_async_client") { | ||
state NetworkAddress addr(NetworkAddress::parse("127.0.0.1:50003")); | ||
state GrpcServer server(addr); | ||
server.registerService(make_shared<TestEchoServiceImpl>()); | ||
state Future<Void> _ = server.run(); | ||
|
||
state shared_ptr<asio::thread_pool> pool = make_shared<asio::thread_pool>(4); | ||
state AsyncGrpcClient<TestEchoService> client(addr.toString(), pool); | ||
|
||
try { | ||
state EchoRequest request; | ||
request.set_message("Ping!"); | ||
EchoResponse response = wait(client.call(&TestEchoService::Stub::Echo, request)); | ||
std::cout << "Echo received: " << response.message() << std::endl; | ||
ASSERT_EQ(response.message(), "Echo: Ping!"); | ||
} catch (Error& e) { | ||
ASSERT_EQ(e.code(), error_code_grpc_error); | ||
ASSERT(false); | ||
} | ||
|
||
return Void(); | ||
} | ||
|
||
TEST_CASE("/fdbrpc/grpc/no_server_running") { | ||
state NetworkAddress addr(NetworkAddress::parse("127.0.0.1:50004")); | ||
state shared_ptr<asio::thread_pool> pool(make_shared<asio::thread_pool>(4)); | ||
state AsyncGrpcClient<TestEchoService> client(addr.toString(), pool); | ||
|
||
try { | ||
state EchoRequest request; | ||
request.set_message("Ping!"); | ||
EchoResponse response = wait(client.call(&TestEchoService::Stub::Echo, request)); | ||
ASSERT(false); // RPC should fail as there is no server running.; | ||
} catch (Error& e) { | ||
ASSERT_EQ(e.code(), error_code_grpc_error); | ||
} | ||
|
||
return Void(); | ||
} | ||
|
||
TEST_CASE("/fdbrpc/grpc/destroy_server_without_shutdown") { | ||
state NetworkAddress addr(NetworkAddress::parse("127.0.0.1:50005")); | ||
state GrpcServer server(addr); | ||
server.registerService(make_shared<TestEchoServiceImpl>()); | ||
state Future<Void> _ = server.run(); | ||
return Void(); | ||
} | ||
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. What is the expectation here? Can we assert for it? 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. If lose last server reference, it cleans up, shutsdown and doesn't cause any random segfaults etc. |
||
|
||
} // namespace fdbrpc_test |
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.
No ACTOR in here?
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.
Not sure why it would be actor?