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

Add get local schema version to the C-API #7873

Merged
merged 6 commits into from
Jul 16, 2024

Conversation

nicola-cab
Copy link
Member

What, How & Why?

Kotlin uses some heuristic for which is required to know the local schema version, before opening a synchronized realm via open_async.

There is no clear API for reading the local schema version without opening the realm, and most importantly, avoiding opening a synchronized realm (in order to guarantee that no sync code is run).

Opening realm in immutable mode seems a viable and simple approach for achieving that, although it will result in a double opening, if a migration is needed (since it requires opening a synchronized realm in async mode).

Another possible approach is to add a new cnf param that the SDK needs to specify and throw an exception inside RealmCoordinator::do_get_realm if the new param is set.

☑️ ToDos

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

@cla-bot cla-bot bot added the cla: yes label Jul 9, 2024
@nicola-cab nicola-cab added no-changelog no-jira-ticket Skip checking the PR title for Jira reference and removed cla: yes labels Jul 9, 2024
@tgoyne
Copy link
Member

tgoyne commented Jul 9, 2024

Opening in Immutable mode can fail catastrophically if it's done while another process is writing to the file, as it doesn't create a read lock. Instead it needs to modify the config to unset the sync config and set force_sync_history if there was a sync config so that the file is opened using sync replication but without creating a sync session.

@cla-bot cla-bot bot added the cla: yes label Jul 11, 2024
@nicola-cab nicola-cab force-pushed the ct/capi_retrieve_persisted_schema_version branch from 8023729 to cd33039 Compare July 11, 2024 16:17
src/realm.h Outdated
/**
* Get the schema version for this realm at the path.
*
* This function cannot fail.
Copy link
Member

Choose a reason for hiding this comment

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

This opens (and possibly creates) a Realm file, which can fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep left over…

}

return wrap_err([&]() {
auto realm = new shared_realm{Realm::get_shared_realm(conf)};
Copy link
Member

Choose a reason for hiding this comment

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

There's no reason to wrap this in an extra shared_realm since it isn't returned to the caller.

@nicola-cab nicola-cab force-pushed the ct/capi_retrieve_persisted_schema_version branch from cd33039 to 8830dca Compare July 12, 2024 09:39
@nicola-cab nicola-cab force-pushed the ct/capi_retrieve_persisted_schema_version branch from 2f1210b to fc97025 Compare July 12, 2024 10:40
Copy link

coveralls-official bot commented Jul 12, 2024

Pull Request Test Coverage Report for Build nicola.cabiddu_1845

Details

  • 14 of 17 (82.35%) changed or added relevant lines in 2 files are covered.
  • 55 unchanged lines in 13 files lost coverage.
  • Overall coverage increased (+0.01%) to 90.991%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/object-store/c_api/schema.cpp 10 13 76.92%
Files with Coverage Reduction New Missed Lines %
src/realm/array_mixed.cpp 1 94.02%
src/realm/dictionary.cpp 1 85.16%
src/realm/sync/noinst/server/server_history.cpp 1 63.7%
test/test_dictionary.cpp 1 99.83%
src/realm/list.cpp 2 87.37%
test/object-store/util/test_file.cpp 2 86.29%
test/test_lang_bind_helper.cpp 2 93.2%
src/realm/sync/transform.cpp 3 60.99%
src/realm/table.cpp 4 90.42%
src/realm/sync/noinst/client_impl_base.cpp 6 81.94%
Totals Coverage Status
Change from base Build 2491: 0.01%
Covered Lines: 215263
Relevant Lines: 236575

💛 - Coveralls

Copy link
Contributor

@clementetb clementetb left a comment

Choose a reason for hiding this comment

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

Tested in Realm-Kotlin.

@nicola-cab
Copy link
Member Author

@tgoyne is it ok to merge the PR? (it needs a changelog entry probably).

Copy link
Member

@tgoyne tgoyne left a comment

Choose a reason for hiding this comment

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

Needs a changelog entry.

conf.force_sync_history = true;
}

auto realm = new shared_realm{Realm::get_shared_realm(conf)};
Copy link
Member

Choose a reason for hiding this comment

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

No reason to wrap this in a shared_realm

@nicola-cab nicola-cab requested a review from tgoyne July 15, 2024 17:25
@nicola-cab nicola-cab force-pushed the ct/capi_retrieve_persisted_schema_version branch from 8ceef8b to 45caad4 Compare July 15, 2024 17:30
@nicola-cab nicola-cab merged commit ad8ba53 into master Jul 16, 2024
41 checks passed
@nicola-cab nicola-cab deleted the ct/capi_retrieve_persisted_schema_version branch July 16, 2024 09:26
@github-actions github-actions bot mentioned this pull request Jul 19, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes no-changelog no-jira-ticket Skip checking the PR title for Jira reference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants