class Yoda::Store::Registry
Constants
- PROJECT_STATUS_KEY
- REGISTRY_VERSION
@note This number must be updated when breaking change is added.
Attributes
adapter[R]
@return [Adapters::LmdbAdapter, nil]
lock[R]
@return [Concurrent::ReentrantReadWriteLock]
patch_set[R]
@return [Objects::PatchSet]
registry_cache[R]
@return [RegistryCache]
Public Class Methods
new(adapter = nil)
click to toggle source
# File lib/yoda/store/registry.rb, line 12 def initialize(adapter = nil) @patch_set = Objects::PatchSet.new @adapter = adapter @registry_cache = RegistryCache.new @lock = Concurrent::ReentrantReadWriteLock.new end
Public Instance Methods
add_patch(patch)
click to toggle source
@param patch [Patch]
# File lib/yoda/store/registry.rb, line 48 def add_patch(patch) lock.with_write_lock do registry_cache.clear_from_patch(patch) patch_set.register(patch) end end
clear()
click to toggle source
# File lib/yoda/store/registry.rb, line 63 def clear lock.with_write_lock do registry_cache.delete_all adapter.clear end end
compress_and_save()
click to toggle source
Store
patch set data to the database. old data in the database are discarded.
# File lib/yoda/store/registry.rb, line 72 def compress_and_save return unless adapter lock.with_write_lock do el_keys = patch_set.keys progress = Instrument::Progress.new(el_keys.length) { |length:, index:| Instrument.instance.registry_dump(index: index, length: length) } data = Enumerator.new do |yielder| el_keys.each { |key| yielder << [key, patch_set.find(key)] } end adapter.batch_write(data, progress) adapter.sync Logger.info "saved #{el_keys.length} keys." @patch_set = Objects::PatchSet.new registry_cache.delete_all end end
find(path)
click to toggle source
@param path [String] @return [Objects::Base, nil]
# File lib/yoda/store/registry.rb, line 35 def find(path) lock.with_read_lock do registry_cache.fetch_or_calc(path) do if adapter&.exist?(path) patch_set.patch(adapter.get(path)) else patch_set.find(path) end end end end
has_key?(path)
click to toggle source
@param path [String] @return [true, false]
# File lib/yoda/store/registry.rb, line 57 def has_key?(path) lock.with_read_lock do adapter&.exists?(path) || patch_set.has_key?(path) end end
project_status()
click to toggle source
@return [Objects::ProjectStatus, nil]
# File lib/yoda/store/registry.rb, line 20 def project_status lock.with_read_lock do adapter&.exist?(PROJECT_STATUS_KEY) && adapter.get(PROJECT_STATUS_KEY) end end
save_project_status(new_project_status)
click to toggle source
@param new_project_status [Objects::ProjectStatus]
# File lib/yoda/store/registry.rb, line 27 def save_project_status(new_project_status) lock.with_write_lock do adapter.put(PROJECT_STATUS_KEY, new_project_status) end end
Private Instance Methods
keys()
click to toggle source
# File lib/yoda/store/registry.rb, line 104 def keys Set.new(adapter&.keys.map(&:to_s) || []).union(patch_set.keys) end