C++ Server-Side SDK
LaunchDarkly SDK
evaluation_stack.hpp
1 #pragma once
2 
3 #include <launchdarkly/data/evaluation_reason.hpp>
4 #include <launchdarkly/server_side/integrations/big_segments/big_segment_store_types.hpp>
5 
6 #include <optional>
7 #include <string>
8 #include <unordered_map>
9 #include <unordered_set>
10 
11 namespace launchdarkly::server_side::data_components {
12 class BigSegmentStoreWrapper;
13 } // namespace launchdarkly::server_side::data_components
14 
15 namespace launchdarkly::server_side::evaluation {
16 
21 struct Guard {
22  Guard(std::unordered_set<std::string>& set, std::string key);
23  ~Guard();
24 
25  Guard(Guard const&) = delete;
26  Guard& operator=(Guard const&) = delete;
27 
28  Guard(Guard&&) = delete;
29  Guard& operator=(Guard&&) = delete;
30 
31  private:
32  std::unordered_set<std::string>& set_;
33  std::string const key_;
34 };
35 
46  public:
51  explicit EvaluationStack(
52  data_components::BigSegmentStoreWrapper* big_segment_store = nullptr);
53 
61  [[nodiscard]] std::optional<Guard> NoticePrerequisite(
62  std::string prerequisite_key);
63 
71  [[nodiscard]] std::optional<Guard> NoticeSegment(std::string segment_key);
72 
77  const;
78 
85 
91  const;
92 
97  [[nodiscard]] integrations::Membership const* FindMembership(
98  std::string const& context_key) const;
99 
104  void StoreMembership(std::string context_key,
105  integrations::Membership membership);
106 
112  void RecordStoreError(std::string context_key);
113 
118  [[nodiscard]] bool DidStoreError(std::string const& context_key) const;
119 
120  private:
121  std::unordered_set<std::string> prerequisites_seen_;
122  std::unordered_set<std::string> segments_seen_;
123 
124  data_components::BigSegmentStoreWrapper* big_segment_store_;
125  enum EvaluationReason::BigSegmentsStatus big_segments_status_ =
126  EvaluationReason::BigSegmentsStatus::kNone;
127  // Keyed by unhashed context key. Empty until the first Big Segment lookup.
128  std::unordered_map<std::string, integrations::Membership> memberships_;
129  std::unordered_set<std::string> store_error_keys_;
130 };
131 
132 } // namespace launchdarkly::server_side::evaluation
BigSegmentsStatus
Definition: evaluation_reason.hpp:61
Internal layer between the evaluator and a customer-provided integrations::IBigSegmentStore.
Definition: big_segment_store_wrapper.hpp:44
void RecordBigSegmentsStatus(enum EvaluationReason::BigSegmentsStatus status)
Definition: evaluation_stack.cpp:61
void RecordStoreError(std::string context_key)
Definition: evaluation_stack.cpp:87
integrations::Membership const * FindMembership(std::string const &context_key) const
Definition: evaluation_stack.cpp:73
void StoreMembership(std::string context_key, integrations::Membership membership)
Definition: evaluation_stack.cpp:82
EvaluationStack(data_components::BigSegmentStoreWrapper *big_segment_store=nullptr)
Definition: evaluation_stack.cpp:27
data_components::BigSegmentStoreWrapper * BigSegmentStore() const
Definition: evaluation_stack.cpp:56
enum EvaluationReason::BigSegmentsStatus BigSegmentsStatus() const
Definition: evaluation_stack.cpp:69
std::optional< Guard > NoticePrerequisite(std::string prerequisite_key)
Definition: evaluation_stack.cpp:40
bool DidStoreError(std::string const &context_key) const
Definition: evaluation_stack.cpp:91
std::optional< Guard > NoticeSegment(std::string segment_key)
Definition: evaluation_stack.cpp:49
Membership describes which Big Segments a single context belongs to, as reported by an IBigSegmentSto...
Definition: big_segment_store_types.hpp:30
Definition: evaluation_stack.hpp:21