Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/server-sdk/src/client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ IDataSourceStatusProvider& ClientImpl::DataSourceStatus() {
// }

ClientImpl::~ClientImpl() {
data_system_->Shutdown(); // This is a blocking call.
ioc_.stop();
// TODO(SC-219101)
run_thread_.join();
Expand Down
16 changes: 11 additions & 5 deletions libs/server-sdk/src/data_interfaces/system/idata_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@
namespace launchdarkly::server_side::data_interfaces {

/**
* \brief IDataSystem obtains data used for flag evaluations and makes it available
* @brief IDataSystem obtains data used for flag evaluations and makes it available
* to other components.
*/
class IDataSystem : public IStore {
public:
public:
/**
* \return Identity of the system. Used in logs.
* @return Identity of the system. Used in logs.
*/
[[nodiscard]] virtual std::string const& Identity() const = 0;

/**
* \brief Initializes the system. This method will be called before any of
* @brief Initializes the system. This method will be called before any of
* the IStore methods are called.
*/
virtual void Initialize() = 0;

/**
* @brief Shuts down the system. This method will be called at some point
* after Initialize, after which no methods from IStore will be called.
*/
virtual void Shutdown() = 0;

virtual ~IDataSystem() override = default;
IDataSystem(IDataSystem const& item) = delete;
IDataSystem(IDataSystem&& item) = delete;
IDataSystem& operator=(IDataSystem const&) = delete;
IDataSystem& operator=(IDataSystem&&) = delete;

protected:
protected:
IDataSystem() = default;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ void BackgroundSync::Initialize() {
nullptr /* no bootstrap data supported yet */);
}

void BackgroundSync::Shutdown() {
auto promise = std::make_shared<std::promise<void>>();
auto const did_shutdown = promise->get_future();
synchronizer_->ShutdownAsync([promise]() { promise->set_value(); });
did_shutdown.wait();
}

std::string const& BackgroundSync::Identity() const {
static std::string id = "background sync via " + synchronizer_->Identity();
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class BackgroundSync final : public data_interfaces::IDataSystem {

void Initialize() override;

void Shutdown() override;

private:
data_components::MemoryStore store_;
data_components::ChangeNotifier change_notifier_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ std::string const& LazyLoad::Identity() const {

void LazyLoad::Initialize() {}

void LazyLoad::Shutdown() {}

std::shared_ptr<data_model::FlagDescriptor> LazyLoad::GetFlag(
std::string const& key) const {
auto const state = tracker_.State(Keys::kAllSegments, time_());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class LazyLoad final : public data_interfaces::IDataSystem {

void Initialize() override;

void Shutdown() override;

private:
void RefreshAllFlags() const;
void RefreshAllSegments() const;
Expand Down