File tree Expand file tree Collapse file tree
libs/server-sdk/src/data_components/big_segments Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -142,8 +142,12 @@ BigSegmentStoreStatus BigSegmentStoreWrapper::GetStatus() {
142142 }
143143 }
144144 // No poll has completed yet; do one now so the caller gets an accurate
145- // staleness reading rather than a default.
146- return PollStoreAndUpdateStatus ();
145+ // staleness reading rather than a default. call_once coalesces concurrent
146+ // first-callers onto a single store query.
147+ std::call_once (first_poll_once_,
148+ [this ] { PollStoreAndUpdateStatus (); });
149+ std::lock_guard lock (status_mutex_);
150+ return *last_status_;
147151}
148152
149153BigSegmentStoreStatus BigSegmentStoreWrapper::PollStoreAndUpdateStatus () {
Original file line number Diff line number Diff line change @@ -138,17 +138,22 @@ class BigSegmentStoreWrapper
138138 // Cancels the pending poll delay on destruction, ending the poll loop.
139139 async::CancellationSource poll_cancel_;
140140
141+ // Internally thread-safe.
141142 MembershipCache cache_;
142143
144+ // Broadcasts status changes to listeners registered via OnStatusChange.
145+ boost::signals2::signal<void (BigSegmentStoreStatus)> status_signal_;
146+
147+ // Coalesces the cold-start fallback poll in GetStatus().
148+ std::once_flag first_poll_once_;
149+
143150 // In-flight store queries keyed by context key. Protected by load_mutex_.
144151 std::mutex load_mutex_;
145152 std::unordered_map<std::string, std::shared_ptr<InFlightQuery>> in_flight_;
146153
147154 // Protected by status_mutex_; nullopt until the first poll completes.
148155 std::mutex status_mutex_;
149156 std::optional<BigSegmentStoreStatus> last_status_;
150-
151- boost::signals2::signal<void (BigSegmentStoreStatus)> status_signal_;
152157};
153158
154159} // namespace launchdarkly::server_side::data_components
You can’t perform that action at this time.
0 commit comments