Skip to content

Commit 513fafe

Browse files
committed
address feedback on pr
1 parent 4794483 commit 513fafe

File tree

7 files changed

+46
-36
lines changed

7 files changed

+46
-36
lines changed

lib/ldclient-rb/config.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,15 +699,15 @@ def initialize(store:, context_cache_size: nil, context_cache_time: nil, status_
699699
#
700700
class DataSystemConfig
701701
#
702-
# @param initializers [Array<Proc(Config) => LaunchDarkly::Interfaces::DataSystem::Initializer>, nil] Array of builder procs that take Config and return an Initializer
703-
# @param primary_synchronizer [Proc(Config) => LaunchDarkly::Interfaces::DataSystem::Synchronizer, nil] Builder proc that takes Config and returns the primary Synchronizer
704-
# @param secondary_synchronizer [Proc(Config) => LaunchDarkly::Interfaces::DataSystem::Synchronizer, nil] Builder proc that takes Config and returns the secondary Synchronizer
705-
# @param data_store_mode [Symbol] The data store mode
702+
# @param initializers [Array<Proc(Config) => LaunchDarkly::Interfaces::DataSystem::Initializer>, nil] The (optional) array of builder procs
703+
# @param primary_synchronizer [Proc(Config) => LaunchDarkly::Interfaces::DataSystem::Synchronizer, nil] The (optional) builder proc for primary synchronizer
704+
# @param secondary_synchronizer [Proc(Config) => LaunchDarkly::Interfaces::DataSystem::Synchronizer, nil] The (optional) builder proc for secondary synchronizer
705+
# @param data_store_mode [Symbol] The (optional) data store mode
706706
# @param data_store [LaunchDarkly::Interfaces::FeatureStore, nil] The (optional) data store
707707
# @param fdv1_fallback_synchronizer [Proc(Config) => LaunchDarkly::Interfaces::DataSystem::Synchronizer, nil]
708708
# The (optional) builder proc for FDv1-compatible fallback synchronizer
709709
#
710-
def initialize(initializers:, primary_synchronizer:, secondary_synchronizer:,
710+
def initialize(initializers: nil, primary_synchronizer: nil, secondary_synchronizer: nil,
711711
data_store_mode: LaunchDarkly::Interfaces::DataStoreMode::READ_ONLY, data_store: nil, fdv1_fallback_synchronizer: nil)
712712
@initializers = initializers
713713
@primary_synchronizer = primary_synchronizer

lib/ldclient-rb/impl/data_store/feature_store_client_wrapper.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def initialize(store, store_update_sink, logger)
2626
@store = store
2727
@store_update_sink = store_update_sink
2828
@logger = logger
29-
@monitoring_enabled = does_store_support_monitoring?
29+
@monitoring_enabled = store_supports_monitoring?
3030

3131
# Thread synchronization
3232
@mutex = Mutex.new
@@ -95,37 +95,37 @@ def monitoring_enabled?
9595
# @return [void]
9696
#
9797
private def update_availability(available)
98+
state_changed = false
99+
poller_to_stop = nil
100+
98101
@mutex.synchronize do
99102
return if available == @last_available
103+
104+
state_changed = true
100105
@last_available = available
106+
107+
if available
108+
poller_to_stop = @poller
109+
@poller = nil
110+
elsif @poller.nil?
111+
task = LaunchDarkly::Impl::RepeatingTask.new(0.5, 0, method(:check_availability), @logger, "LDClient/DataStoreWrapperV2#check-availability")
112+
@poller = task
113+
@poller.start
114+
end
101115
end
102116

117+
return unless state_changed
118+
103119
if available
104120
@logger.warn { "[LDClient] Persistent store is available again" }
121+
else
122+
@logger.warn { "[LDClient] Detected persistent store unavailability; updates will be cached until it recovers" }
105123
end
106124

107125
status = LaunchDarkly::Interfaces::DataStore::Status.new(available, true)
108126
@store_update_sink.update_status(status)
109127

110-
if available
111-
@mutex.synchronize do
112-
return if @poller.nil?
113-
114-
@poller.stop
115-
@poller = nil
116-
end
117-
118-
return
119-
end
120-
121-
@logger.warn { "[LDClient] Detected persistent store unavailability; updates will be cached until it recovers" }
122-
123-
task = LaunchDarkly::Impl::RepeatingTask.new(0.5, 0, method(:check_availability), @logger, "LDClient/DataStoreWrapperV2#check-availability")
124-
125-
@mutex.synchronize do
126-
@poller = task
127-
@poller.start
128-
end
128+
poller_to_stop.stop if poller_to_stop
129129
end
130130

131131
#
@@ -156,7 +156,7 @@ def monitoring_enabled?
156156
#
157157
# @return [Boolean]
158158
#
159-
private def does_store_support_monitoring?
159+
private def store_supports_monitoring?
160160
return false unless @store.respond_to?(:monitoring_enabled?)
161161
return false unless @store.respond_to?(:available?)
162162

lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module DataStore
1313
#
1414
class InMemoryFeatureStoreV2
1515
include LaunchDarkly::Interfaces::DataSystem::ReadOnlyStore
16-
def initialize
16+
def initialize(logger)
17+
@logger = logger
1718
@lock = Concurrent::ReadWriteLock.new
1819
@initialized = Concurrent::AtomicBoolean.new(false)
1920
@items = {}
@@ -97,7 +98,7 @@ def apply_delta(collections)
9798

9899
true
99100
rescue => e
100-
LaunchDarkly::Impl.log.error { "[LDClient] Failed applying apply_delta: #{e.message}" }
101+
@logger.error { "[LDClient] Failed applying apply_delta: #{e.message}" }
101102
false
102103
end
103104

@@ -113,8 +114,7 @@ def apply_delta(collections)
113114
collections.each do |kind, collection|
114115
items_decoded = {}
115116
collection.each do |key, item|
116-
# Items are already in decoded format for FDv2
117-
items_decoded[key.to_sym] = item
117+
items_decoded[key] = LaunchDarkly::Impl::Model.deserialize(kind, item, @logger)
118118
end
119119
all_decoded[kind] = items_decoded
120120
end

lib/ldclient-rb/impl/data_store/status_provider.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def initialize(store, listeners)
2929
@listeners = listeners
3030
@lock = Concurrent::ReadWriteLock.new
3131
@status = LaunchDarkly::Interfaces::DataStore::Status.new(true, false)
32+
@monitoring_enabled = store_supports_monitoring?
3233
end
3334

3435
# (see LaunchDarkly::Interfaces::DataStore::UpdateSink#update_status)
@@ -54,6 +55,15 @@ def status
5455

5556
# (see LaunchDarkly::Interfaces::DataStore::StatusProvider#monitoring_enabled?)
5657
def monitoring_enabled?
58+
@monitoring_enabled
59+
end
60+
61+
#
62+
# Determines whether the store supports monitoring.
63+
#
64+
# @return [Boolean]
65+
#
66+
private def store_supports_monitoring?
5767
return false if @store.nil?
5868
return false unless @store.respond_to?(:monitoring_enabled?)
5969

lib/ldclient-rb/impl/data_store/store.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def initialize(flag_change_broadcaster, change_set_broadcaster, logger)
3636
@persistent_store_writable = false
3737

3838
# Source of truth for flag evaluations once initialized
39-
@memory_store = InMemoryFeatureStoreV2.new
39+
@memory_store = InMemoryFeatureStoreV2.new(logger)
4040

4141
# Used to track dependencies between items in the store
4242
@dependency_tracker = LaunchDarkly::Impl::DependencyTracker.new
@@ -284,7 +284,7 @@ def get_data_store_status_provider
284284
# Convert a list of Changes to the pre-existing format used by FeatureStore.
285285
#
286286
# @param changes [Array<LaunchDarkly::Interfaces::DataSystem::Change>] List of changes
287-
# @return [Hash{Object => Hash{String => Hash}}] Hash suitable for FeatureStore operations
287+
# @return [Hash{DataKind => Hash{String => Hash}}] Hash suitable for FeatureStore operations
288288
#
289289
private def changes_to_store_data(changes)
290290
all_data = {
@@ -307,7 +307,7 @@ def get_data_store_status_provider
307307
#
308308
# Reset dependency tracker with new full data set.
309309
#
310-
# @param all_data [Hash{Object => Hash{String => Hash}}] Hash of data kinds to items
310+
# @param all_data [Hash{DataKind => Hash{String => Hash}}] Hash of data kinds to items
311311
# @return [void]
312312
#
313313
private def reset_dependency_tracker(all_data)
@@ -336,8 +336,8 @@ def get_data_store_status_provider
336336
#
337337
# Compute which items changed between old and new data sets.
338338
#
339-
# @param old_data [Hash{Object => Hash{String => Hash}}] Old data hash
340-
# @param new_data [Hash{Object => Hash{String => Hash}}] New data hash
339+
# @param old_data [Hash{DataKind => Hash{String => Hash}}] Old data hash
340+
# @param new_data [Hash{DataKind => Hash{String => Hash}}] New data hash
341341
# @return [Set<Hash>] Set of {kind:, key:} hashes
342342
#
343343
private def compute_changed_items_for_full_data_set(old_data, new_data)

lib/ldclient-rb/impl/model/serialization.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module Model
4141
# @return [Object] the flag or segment (or, for an unknown data kind, the data as a hash)
4242
def self.deserialize(kind, input, logger = nil)
4343
return nil if input.nil?
44-
return input if !input.is_a?(String) && !input.is_a?(Hash)
44+
return input unless input.is_a?(String) || input.is_a?(Hash)
4545
data = input.is_a?(Hash) ? input : JSON.parse(input, symbolize_names: true)
4646
case kind
4747
when Impl::DataStore::FEATURES

0 commit comments

Comments
 (0)