@@ -83,6 +83,20 @@ using IndexToEnableMoW =
8383 std::allocator<phmap::Pair<const int64_t , bool >>, 4 ,
8484 std::mutex>;
8585
86+ class CloseWaitNotifier {
87+ public:
88+ int64_t close_wait_version () const ;
89+
90+ void wait_for_close_event (int64_t observed_version, int64_t timeout_ms);
91+
92+ void notify_close_wait ();
93+
94+ private:
95+ std::atomic<int64_t > _close_wait_version {0 };
96+ bthread::Mutex _close_wait_mutex;
97+ bthread::ConditionVariable _close_wait_cv;
98+ };
99+
86100class LoadStreamReplyHandler : public brpc ::StreamInputHandler {
87101public:
88102 LoadStreamReplyHandler (PUniqueId load_id, int64_t dst_id, std::weak_ptr<LoadStreamStub> stub)
@@ -110,12 +124,17 @@ class LoadStreamStub : public std::enable_shared_from_this<LoadStreamStub> {
110124 // construct new stub
111125 LoadStreamStub (PUniqueId load_id, int64_t src_id,
112126 std::shared_ptr<IndexToTabletSchema> schema_map,
113- std::shared_ptr<IndexToEnableMoW> mow_map, bool incremental = false );
127+ std::shared_ptr<IndexToEnableMoW> mow_map, bool incremental = false ,
128+ std::shared_ptr<CloseWaitNotifier> close_wait_notifier =
129+ std::make_shared<CloseWaitNotifier>());
114130
115131 LoadStreamStub (UniqueId load_id, int64_t src_id,
116132 std::shared_ptr<IndexToTabletSchema> schema_map,
117- std::shared_ptr<IndexToEnableMoW> mow_map, bool incremental = false )
118- : LoadStreamStub(load_id.to_proto(), src_id, schema_map, mow_map, incremental) {};
133+ std::shared_ptr<IndexToEnableMoW> mow_map, bool incremental = false ,
134+ std::shared_ptr<CloseWaitNotifier> close_wait_notifier =
135+ std::make_shared<CloseWaitNotifier>())
136+ : LoadStreamStub(load_id.to_proto(), src_id, schema_map, mow_map, incremental,
137+ std::move (close_wait_notifier)) {};
119138
120139// for mock this class in UT
121140#ifdef BE_TEST
@@ -245,6 +264,8 @@ class LoadStreamStub : public std::enable_shared_from_this<LoadStreamStub> {
245264 tablet_load_infos);
246265
247266private:
267+ void notify_close_wait ();
268+
248269 Status _encode_and_send (PStreamHeader& header, std::span<const Slice> data = {});
249270 Status _send_with_buffer (butil::IOBuf& buf, bool sync = false );
250271 Status _send_with_retry (butil::IOBuf& buf);
@@ -283,6 +304,7 @@ class LoadStreamStub : public std::enable_shared_from_this<LoadStreamStub> {
283304 std::unordered_map<int64_t , Status> _failed_tablets;
284305
285306 bool _is_incremental = false ;
307+ std::shared_ptr<CloseWaitNotifier> _close_wait_notifier;
286308
287309 bthread::Mutex _write_mutex;
288310 size_t _bytes_written = 0 ;
@@ -295,12 +317,14 @@ class LoadStreamStubs {
295317public:
296318 LoadStreamStubs (size_t num_streams, UniqueId load_id, int64_t src_id,
297319 std::shared_ptr<IndexToTabletSchema> schema_map,
298- std::shared_ptr<IndexToEnableMoW> mow_map, bool incremental = false )
320+ std::shared_ptr<IndexToEnableMoW> mow_map, bool incremental = false ,
321+ std::shared_ptr<CloseWaitNotifier> close_wait_notifier =
322+ std::make_shared<CloseWaitNotifier>())
299323 : _is_incremental(incremental) {
300324 _streams.reserve (num_streams);
301325 for (size_t i = 0 ; i < num_streams; i++) {
302- _streams.emplace_back (
303- new LoadStreamStub (load_id, src_id, schema_map, mow_map, incremental));
326+ _streams.emplace_back (new LoadStreamStub (load_id, src_id, schema_map, mow_map,
327+ incremental, close_wait_notifier ));
304328 }
305329 }
306330
0 commit comments