-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RCORE-2006 Reuse realm file for sync schema migrations #7487
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7a2e3fc
Use the same realm file when performing a schema migration
danieltabacaru 511af84
touch ups
danieltabacaru 6b5ef1a
Add support to clear PendingBootstrapStore while in a write transaction
danieltabacaru d839e43
Fix AdditiveDiscovered schema mode documentation and test
danieltabacaru e95e4b4
Fix tests
danieltabacaru dd617de
Delete private tables during schema migration
danieltabacaru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
#include <realm/sync/subscriptions.hpp> | ||
#include <realm/sync/noinst/sync_schema_migration.hpp> | ||
#include <realm/object-store/impl/realm_coordinator.hpp> | ||
#include <realm/object-store/sync/sync_manager.hpp> | ||
#include <realm/object-store/sync/sync_session.hpp> | ||
#include <realm/object-store/thread_safe_reference.hpp> | ||
|
||
|
@@ -192,20 +191,10 @@ void AsyncOpenTask::migrate_schema_or_complete(AsyncOpenCallback&& callback, | |
return; | ||
} | ||
|
||
// Sync schema migrations require setting a subscription initializer callback to bootstrap the data. The | ||
// subscriptions in the current realm file may not be compatible with the new schema so cannot rely on them. | ||
auto config = coordinator->get_config(); | ||
if (!config.sync_config->subscription_initializer) { | ||
status = Status(ErrorCodes::SyncSchemaMigrationError, | ||
"Sync schema migrations must provide a subscription initializer callback in the sync config"); | ||
async_open_complete(std::move(callback), coordinator, status); | ||
return; | ||
} | ||
|
||
// Migrate the schema. | ||
// * First upload the changes at the old schema version | ||
// * Then, delete the realm, reopen it, and bootstrap at new schema version | ||
// The lifetime of the task is extended until bootstrap completes. | ||
// * Then, pause the session, delete all tables, re-initialize the metadata, and finally restart the session. | ||
// The lifetime of the task is extended until the bootstrap completes. | ||
std::shared_ptr<AsyncOpenTask> self(shared_from_this()); | ||
session->wait_for_upload_completion([callback = std::move(callback), coordinator, session, self, | ||
this](Status status) mutable { | ||
|
@@ -220,38 +209,11 @@ void AsyncOpenTask::migrate_schema_or_complete(AsyncOpenCallback&& callback, | |
return; | ||
} | ||
|
||
auto future = SyncSession::Internal::pause_async(*session); | ||
// Wait until the SessionWrapper is done using the DBRef. | ||
std::move(future).get_async([callback = std::move(callback), coordinator, self, this](Status status) mutable { | ||
{ | ||
util::CheckedLockGuard lock(m_mutex); | ||
if (!m_session) | ||
return; // Swallow all events if the task has been cancelled. | ||
} | ||
|
||
if (!status.is_ok()) { | ||
self->async_open_complete(std::move(callback), coordinator, status); | ||
return; | ||
} | ||
|
||
// Delete the realm file and reopen it. | ||
try { | ||
util::CheckedLockGuard lock(m_mutex); | ||
auto config = coordinator->get_config(); | ||
m_session = nullptr; | ||
coordinator->close(); | ||
coordinator = nullptr; | ||
util::File::remove(config.path); | ||
coordinator = _impl::RealmCoordinator::get_coordinator(config); | ||
m_session = coordinator->sync_session(); | ||
} | ||
catch (...) { | ||
async_open_complete(std::move(callback), coordinator, exception_to_status()); | ||
return; | ||
} | ||
|
||
auto migration_completed_callback = [callback = std::move(callback), coordinator = std::move(coordinator), | ||
self](Status status) mutable { | ||
self->wait_for_bootstrap_or_complete(std::move(callback), coordinator, status); | ||
}); | ||
}; | ||
SyncSession::Internal::migrate_schema(*session, std::move(migration_completed_callback)); | ||
}); | ||
} | ||
|
||
|
@@ -270,4 +232,4 @@ void AsyncOpenTask::wait_for_bootstrap_or_complete(AsyncOpenCallback&& callback, | |
} | ||
} | ||
|
||
} // namespace realm | ||
} // namespace realm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing newline at end of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this leave the db in a state where there are tables out there with invalid links? I guess in the place this is used right now that may not be important to consider because we remove all tables in a single WT, but what are the implications if an SDK started using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. we remove all tables so it should not cause any issue. I don't think we expose this to the SDKs (had a look in
spec.yml
and there is no reference). I could also have a private method and friend the class (or some other utility)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java was the only SDK which exposed table schema mutations directly and everything else only does it by setting the object store schema. Should probably add a comment in the declaration that
ignore_backlinks=true
will leave things in an invalid state just in case someone ends up using it in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point