This morning I’ve finalized an early implementation of inter-store synchronization. Please not that it is definitely not mature, API and details might change over time.
So, what is this for? Synchronization is a way to replicate document between stores back and forth, while preserving whole history of document changes.
Here you are an example:
# Main store is default store
store = StrokeDB.default_store
# Let's create another store
another_store = StrokeDB::Config.build(:base_path => 'tmp_db').stores[:default]
# Here we're creating some document in another_store
doc = Document.create!(another_store, :hello => 'world')
# Updating it
doc.test = 'passed'
doc.save!
# Syncing it to store
# doc.__versions__.all.reverse is basically pass all versions of doc in reverse order (after this reversion latest version will be at the end of list). Order is important
store.sync!(doc.__versions__.all.reverse,another_store.timestamp)
# updating document at store
doc_at_store = store.find(doc.uuid)
doc_at_store.ok = true
doc_at_store.save!
# Syncing it back to another_store
another_store.sync!
(doc_at_store.__versions__.all.reverse,store.timestamp)
# Now, let's reload document at another store:
doc.reload
# ==> #<Doc __previous_version__: fe9e..., __version__: bdf6..., hello: "world", ok: true, test: "passed", uuid: "e70aca78-69d3-4e2c-920c-813f2c17be75">
# as you can see, it got 'ok' slot with value of true
Voila!
Synchronization will work just fine if you have a fast-forward situation and will raise ConflictCondition if you have a conflict. Oleg is working on merge3 algorithm to let it be one of the scenarios to resolve ConflictConditions; I am also thinking about 1-2 simple scenarios for conflict resolving.
Anyway, as I’ve said above, its API/way to work isn’t mature yet, so things might change.




