Skip to content
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 6 commits into from
Mar 26, 2024

Conversation

danieltabacaru
Copy link
Collaborator

@danieltabacaru danieltabacaru commented Mar 17, 2024

What, How & Why?

In the previous design of schema migrations, the RealmCoordinator was closed so the realm file can be deleted. This worked under the assumption that only one AsyncOpenTask was in progress at any time. Since apps may open a realm file multiple times at once, we've changed it so there is no need to delete the realm file and instead reuse the same file.

Upon uploading the unsynced changes, the client will:

  1. Pause the sync session

  2. Once the sync client releases the realm file:

    • Delete all tables (private and public)
    • Reset the subscription store
    • Empty the sync history and adjust cursors
    • Reset file ident (the server flags the old ident as in the case of a client reset so it cannot be used to finish the migration)
  3. Resume the session (the client asks for a new file ident)

Note: This still works under the assumption that a realm file is opened only asynchronously for a migration to work

Fixes #7442, #7325.

☑️ ToDos

  • [ ] 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • [ ] C-API, if public C++ API changed
  • [ ] bindgen/spec.yml, if public C++ API changed

@danieltabacaru danieltabacaru marked this pull request as ready for review March 18, 2024 10:33
Copy link

coveralls-official bot commented Mar 18, 2024

Pull Request Test Coverage Report for Build daniel.tabacaru_782

Details

  • 365 of 377 (96.82%) changed or added relevant lines in 15 files are covered.
  • 472 unchanged lines in 24 files lost coverage.
  • Overall coverage decreased (-0.02%) to 91.791%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/object-store/sync/sync_session.cpp 55 61 90.16%
test/object-store/sync/flx_schema_migration.cpp 234 240 97.5%
Files with Coverage Reduction New Missed Lines %
src/realm/sync/client.hpp 1 97.67%
src/realm/sync/network/network.cpp 1 89.86%
src/realm/array_string.cpp 2 85.25%
src/realm/collection_parent.cpp 2 92.48%
src/realm/object-store/shared_realm.cpp 2 93.01%
test/object-store/sync/flx_schema_migration.cpp 2 97.48%
src/realm/dictionary.cpp 3 85.13%
src/realm/object-store/sync/impl/sync_client.hpp 3 95.0%
src/realm/sort_descriptor.cpp 3 93.8%
src/realm/sync/noinst/server/server.cpp 3 76.8%
Totals Coverage Status
Change from base Build 2137: -0.02%
Covered Lines: 242997
Relevant Lines: 264729

💛 - Coveralls

@@ -832,7 +832,7 @@ void Group::remove_table(size_t table_ndx, TableKey key)
// tables. Such a behaviour is deemed too obscure, and we shall therefore
// require that a removed table does not contain foreign origin backlink
// columns.
if (table->is_cross_table_link_target())
if (!ignore_backlinks && table->is_cross_table_link_target())
Copy link
Contributor

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?

Copy link
Collaborator Author

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)

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

@@ -270,4 +232,4 @@ void AsyncOpenTask::wait_for_bootstrap_or_complete(AsyncOpenCallback&& callback,
}
}

} // namespace realm
} // namespace realm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline at end of file

// Delete all public tables (and their columns).
const bool ignore_backlinks = true;
for (const auto& tk : tr->get_table_keys()) {
// Do not remove the metadata tables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually want to leave the private tables? There shouldn't be anything that needs to be preserved, and deleting and recreating them is closer in behavior to what deleting the file did.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. I initially deleted those as well, but there was an issue with it. Just got an idea how I may be able to overcome that.

@danieltabacaru danieltabacaru merged commit 32e931a into master Mar 26, 2024
39 checks passed
@danieltabacaru danieltabacaru deleted the dt/reuse_realm_for_schema_migrations branch March 26, 2024 16:32
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow multiple AsyncOpenTask's in progress at once if a schema migration is needed
3 participants