mirror of
https://github.com/apache/arrow.git
synced 2026-10-28 16:47:19 +08:00
Make FlightCallOptions a POD type
This commit is contained in:
1 parent
d4bef27811
commit
a573d2c61d
5 files changed
+12
-37
No files matched your search
@@ -51,24 +51,7 @@ class MemoryPool;
|
||||
|
||||
namespace flight {
|
||||
|
||||
class FlightCallOptions::Impl {
|
||||
private:
|
||||
bool timeout_set_ = false;
|
||||
TimeoutDuration timeout_;
|
||||
friend class FlightCallOptions;
|
||||
};
|
||||
|
||||
FlightCallOptions::FlightCallOptions() : impl_(new FlightCallOptions::Impl()) {}
|
||||
FlightCallOptions::~FlightCallOptions() = default;
|
||||
|
||||
void FlightCallOptions::set_timeout(const TimeoutDuration& timeout_sec) {
|
||||
impl_->timeout_set_ = true;
|
||||
impl_->timeout_ = timeout_sec;
|
||||
}
|
||||
|
||||
const TimeoutDuration& FlightCallOptions::timeout() const { return impl_->timeout_; }
|
||||
|
||||
bool FlightCallOptions::HasTimeout() const { return impl_->timeout_set_; }
|
||||
FlightCallOptions::FlightCallOptions() : timeout(-1) {}
|
||||
|
||||
struct ClientRpc {
|
||||
grpc::ClientContext context;
|
||||
@@ -77,10 +60,10 @@ struct ClientRpc {
|
||||
/// XXX workaround until we have a handshake in Connect
|
||||
context.set_wait_for_ready(true);
|
||||
|
||||
if (options.HasTimeout()) {
|
||||
if (options.timeout.count() >= 0) {
|
||||
std::chrono::system_clock::time_point deadline =
|
||||
std::chrono::time_point_cast<std::chrono::system_clock::time_point::duration>(
|
||||
std::chrono::system_clock::now() + options.timeout());
|
||||
std::chrono::system_clock::now() + options.timeout);
|
||||
context.set_deadline(deadline);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,21 +48,13 @@ typedef std::chrono::duration<double, std::chrono::seconds::period> TimeoutDurat
|
||||
/// \brief Hints to the underlying RPC layer for Arrow Flight calls.
|
||||
class ARROW_EXPORT FlightCallOptions {
|
||||
public:
|
||||
/// Create a default set of call options.
|
||||
FlightCallOptions();
|
||||
~FlightCallOptions();
|
||||
/// \brief Set a timeout on this call. If the call does not complete
|
||||
/// within the specified period, the call will complete with a
|
||||
/// non-OK status.
|
||||
void set_timeout(const TimeoutDuration& timeout_sec);
|
||||
/// \brief Get the timeout for this call. Only valid if HasTimeout()
|
||||
/// is true.
|
||||
const TimeoutDuration& timeout() const;
|
||||
/// \brief Check if a timeout was set for this call.
|
||||
bool HasTimeout() const;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
/// \brief An optional timeout for this call. Negative durations
|
||||
/// mean an implementation-defined default behavior will be used
|
||||
/// instead. This is the default value.
|
||||
TimeoutDuration timeout;
|
||||
};
|
||||
|
||||
/// \brief Client class for Arrow Flight RPC services (gRPC-based).
|
||||
|
||||
@@ -364,7 +364,7 @@ TEST_F(TestFlightClient, TimeoutFires) {
|
||||
std::unique_ptr<FlightClient> client;
|
||||
ASSERT_OK(FlightClient::Connect("localhost", 30001, &client));
|
||||
FlightCallOptions options;
|
||||
options.set_timeout(TimeoutDuration{0.2});
|
||||
options.timeout = TimeoutDuration{0.2};
|
||||
std::unique_ptr<FlightInfo> info;
|
||||
auto start = std::chrono::system_clock::now();
|
||||
Status status = client->GetFlightInfo(options, FlightDescriptor{}, &info);
|
||||
@@ -376,7 +376,7 @@ TEST_F(TestFlightClient, TimeoutFires) {
|
||||
TEST_F(TestFlightClient, NoTimeout) {
|
||||
// Call should complete quickly, so timeout should not fire
|
||||
FlightCallOptions options;
|
||||
options.set_timeout(TimeoutDuration{0.5});
|
||||
options.timeout = TimeoutDuration{0.5};
|
||||
std::unique_ptr<FlightInfo> info;
|
||||
auto start = std::chrono::system_clock::now();
|
||||
auto descriptor = FlightDescriptor::Path({"examples", "ints"});
|
||||
|
||||
@@ -41,7 +41,7 @@ cdef class FlightCallOptions:
|
||||
|
||||
def __init__(self, timeout=None):
|
||||
if timeout is not None:
|
||||
self.options.set_timeout(CTimeoutDuration(timeout))
|
||||
self.options.timeout = CTimeoutDuration(timeout)
|
||||
|
||||
@staticmethod
|
||||
cdef CFlightCallOptions* unwrap(obj):
|
||||
|
||||
@@ -146,7 +146,7 @@ cdef extern from "arrow/flight/api.h" namespace "arrow" nogil:
|
||||
|
||||
cdef cppclass CFlightCallOptions" arrow::flight::FlightCallOptions":
|
||||
CFlightCallOptions()
|
||||
void set_timeout(CTimeoutDuration duration)
|
||||
CTimeoutDuration timeout
|
||||
|
||||
cdef cppclass CFlightClient" arrow::flight::FlightClient":
|
||||
@staticmethod
|
||||
|
||||
Reference in new issue
Block a user