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

Remove ability to synchronize objects without primary key #7039

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jedelbo
Copy link
Contributor

@jedelbo jedelbo commented Oct 6, 2023

With the legacy server this was based on GlobalKey, but if we at some point will allow objects without primary key to be synced to MongoDB server, we will probably have to invent a new strategy.

As we remove support for GlobalKey we will have to change the way we allocate ObjKeys for tombstones. Beforehand we used a hash of the primary key to construct a GlobalKey and from that an ObjKey. Now we just use the current ObjKey to construct a corresponding unresolved key. But it has the effect that there is not an easy way to come from primary key to potential unresolved key, so we will have to search for a potential tombstone.

What, How & Why?

☑️ ToDos

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

With the legacy server this was based on GlobalKey, but if we at some
point will allow objects without primary key to be synced to MongoDB
server, we will probably have to invent a new strategy.

As we remove support for GlobalKey we will have to change the way we
allocate ObjKeys for tombstones. Beforehand we used a hash of the
primary key to construct a GlobalKey and from that an ObjKey. Now we just
use the current ObjKey to construct a corresponding unresolved key. But
it has the effect that there is not an easy way to come from primary key
to potential unresolved key, so we will have to search for a potential
tombstone.
@coveralls-official
Copy link

coveralls-official bot commented Oct 6, 2023

Pull Request Test Coverage Report for Build github_pull_request_281922

  • 101 of 105 (96.19%) changed or added relevant lines in 13 files are covered.
  • 238 unchanged lines in 19 files lost coverage.
  • Overall coverage decreased (-0.08%) to 90.445%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/util/compare_groups.cpp 2 3 66.67%
src/realm/sync/instruction_applier.cpp 2 5 40.0%
Files with Coverage Reduction New Missed Lines %
test/test_dictionary.cpp 1 99.85%
src/realm/array_string.cpp 2 85.04%
src/realm/object-store/shared_realm.cpp 2 93.74%
src/realm/query_expression.hpp 2 93.24%
src/realm/sync/network/network.cpp 3 89.66%
src/realm/sync/noinst/server/server.cpp 3 75.92%
test/test_util_network.cpp 3 97.2%
src/realm/sync/instruction_applier.cpp 4 64.05%
src/realm/sync/noinst/client_reset.cpp 4 93.1%
src/realm/sync/transform.cpp 4 61.68%
Totals Coverage Status
Change from base Build github_pull_request_281750: -0.08%
Covered Lines: 232657
Relevant Lines: 257235

💛 - Coveralls

@tgoyne
Copy link
Member

tgoyne commented Oct 9, 2023

I believe ClientHistory::fix_up_client_file_ident_in_stored_changesets() and some related plumbing for fix_up_object_ids can also go away as that's there to rewrite GlobalKeys created before contacting the server.

@jedelbo jedelbo marked this pull request as ready for review November 1, 2023 14:30
bad_transaction_log("CreateObject(GlobalKey) on table with a primary key");
}
m_last_object = table->create_object(key);
[&](GlobalKey) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we don't remove this type all together so there is no breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, this is kind of breaking in that we don't support GlobalKey anymore. But is was never used in context of MongoDB cloud. I think next step would be to remove the type altogether.

Copy link
Collaborator

Choose a reason for hiding this comment

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

what's stopping us to do it now?

if (auto sz = m_tombstones->size()) {
// Check for potential tombstone
Iterator end(*m_tombstones, sz);
for (Iterator it(*m_tombstones, 0); it != end; ++it) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't this going to be slow? maybe we should run some benchmarks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure this will be slower than before. The assumption is that we will have a limited number of tombstones. Alternatively we could implement an index just for tombstones.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the assumption hold true? At least with some benchmark we'd know what to expect.

@@ -570,6 +570,7 @@ void Transaction::upgrade_file_format(int target_file_format_version)
if (current_file_format_version < 24) {
for (auto k : table_keys) {
auto t = get_table(k);
t->free_collision_table();
Copy link
Collaborator

Choose a reason for hiding this comment

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

what was the consequence of not doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what the question is. But the collision table is not needed anymore. We will not generate the unresolved key based on the primary key.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. I thought it was a fix.

@jedelbo jedelbo marked this pull request as draft November 3, 2023 12:57
Base automatically changed from next-major to master February 23, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants