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

Re-create all objects before updating their properties during client_reset::transfer_group() #6291

Merged
merged 4 commits into from
Feb 10, 2023

Conversation

jbreams
Copy link
Contributor

@jbreams jbreams commented Feb 9, 2023

What, How & Why?

This fixes a crash in automatic client resets where there are dangling links in the destination realm (i.e. the realm being client reset). The transfer_group() function takes a fresh copy of a realm and transfers a source realm's contents to a target by comparing each property in each object in each table, and creating/setting properties as needed if they don't exist or do not match. If the target table has a list of links where some of them are dangling, and the dangling link targets exist in the source realm, it will create the target objects, thereby resurrecting the dangling link, and end up with duplicate entries in the list. This violates an invariant in the IntraRealmObjectConverter class.

☑️ ToDos

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

@cla-bot cla-bot bot added the cla: yes label Feb 9, 2023
@jbreams jbreams changed the title Re-create all objects before updating their properties Re-create all objects before updating their properties during client_reset::transfer_group() Feb 9, 2023
@jbreams jbreams marked this pull request as ready for review February 10, 2023 02:33
Copy link
Contributor

@michael-wb michael-wb left a comment

Choose a reason for hiding this comment

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

LGTM-good find!
transfer_group is an insane function...

@@ -329,8 +329,30 @@ void transfer_group(const Transaction& group_src, Transaction& group_dst, util::
}
}

converters::EmbeddedObjectConverter embedded_tracker;
// We must re-create any missing objects that are abscent in dst before trying to copy
Copy link
Contributor

Choose a reason for hiding this comment

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

*absent

Copy link
Collaborator

Choose a reason for hiding this comment

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

missing objects or objects that are absent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops.

// get or create the object
auto dst = table_dst->create_object_with_primary_key(src_pk, &updated);
auto dst = table_dst->get_object_with_primary_key(src_pk);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will create the object if it doesn't exist?
Or it should have already been created by your changes above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. I updated the comment above.

@@ -357,11 +379,11 @@ void transfer_group(const Transaction& group_src, Transaction& group_dst, util::

for (const Obj& src : *table_src) {
auto src_pk = src.get_primary_key();
bool updated = false;
// get or create the object
Copy link
Collaborator

Choose a reason for hiding this comment

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

should update this comment

Copy link
Collaborator

@danieltabacaru danieltabacaru left a comment

Choose a reason for hiding this comment

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

LGTM

@danieltabacaru
Copy link
Collaborator

exception occurs during bootstrap application fails on CI at:
REQUIRE(error.error_code == make_error_code(sync::ClientError::bad_changeset));

Side note: maybe it should be turned into a CHECK so we see the actual error.

@jbreams jbreams merged commit 3dbeb43 into master Feb 10, 2023
@jbreams jbreams deleted the jbr/fix_client_reset_with_dangling_links branch February 10, 2023 17:12
@kiburtse kiburtse mentioned this pull request Mar 3, 2023
3 tasks
@ironage ironage mentioned this pull request Nov 3, 2023
3 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

client_reset::transfer_group() can crash when transferring tables with dangling links
3 participants