Class: Yoda::Store::Registry
- Inherits:
-
Object
- Object
- Yoda::Store::Registry
- Defined in:
- lib/yoda/store/registry.rb
Constant Summary collapse
- REGISTRY_VERSION =
Note:
This number must be updated when breaking change is added.
2
- PROJECT_STATUS_KEY =
'%project_status'
Instance Method Summary collapse
- #add_patch(patch) ⇒ Object
- #clear ⇒ Object
-
#compress_and_save ⇒ Object
Store patch set data to the database.
- #find(path) ⇒ Objects::Base?
- #has_key?(path) ⇒ true, false
-
#initialize(adapter = nil) ⇒ Registry
constructor
A new instance of Registry.
- #project_status ⇒ Objects::ProjectStatus?
- #save_project_status(new_project_status) ⇒ Object
Constructor Details
#initialize(adapter = nil) ⇒ Registry
Returns a new instance of Registry.
12 13 14 15 16 17 |
# 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 |
Instance Method Details
#add_patch(patch) ⇒ Object
48 49 50 51 52 53 |
# 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 ⇒ Object
63 64 65 66 67 68 |
# 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 ⇒ Object
Store patch set data to the database. old data in the database are discarded.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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) ⇒ Objects::Base?
35 36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ true, false
57 58 59 60 61 |
# 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 ⇒ Objects::ProjectStatus?
20 21 22 23 24 |
# 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) ⇒ Object
27 28 29 30 31 |
# 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 |