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-2185 Sync client should steal file ident of fresh realm when performing client reset #7850

Merged
merged 30 commits into from
Jul 3, 2024

Conversation

michael-wb
Copy link
Contributor

@michael-wb michael-wb commented Jun 27, 2024

What, How & Why?

When a client reset occurs, the local realm should assume the file ident from the fresh realm when the client reset diff takes place at the end of the client reset. Currently, it is requesting a new file ident and using that value for the local realm, which is interfering with the client being able to receive role changes while the client reset diff is in progress.

Fixes #7846

☑️ ToDos

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

Copy link

coveralls-official bot commented Jun 28, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1207

Details

  • 95 of 97 (97.94%) changed or added relevant lines in 7 files are covered.
  • 46 unchanged lines in 13 files lost coverage.
  • Overall coverage increased (+0.02%) to 90.972%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/noinst/client_impl_base.cpp 52 54 96.3%
Files with Coverage Reduction New Missed Lines %
src/realm/index_string.hpp 1 93.48%
src/realm/sync/noinst/server/server_history.cpp 1 63.7%
test/test_index_string.cpp 1 93.48%
test/test_query2.cpp 1 98.73%
src/realm/cluster.cpp 2 75.6%
src/realm/collection_parent.cpp 3 93.08%
src/realm/sync/client.cpp 3 91.74%
src/realm/table.cpp 3 90.42%
test/test_thread.cpp 3 66.14%
src/realm/sync/transform.cpp 4 60.92%
Totals Coverage Status
Change from base Build 2449: 0.02%
Covered Lines: 214934
Relevant Lines: 236264

💛 - Coveralls

Copy link

coveralls-official bot commented Jun 29, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1213

Details

  • 107 of 109 (98.17%) changed or added relevant lines in 7 files are covered.
  • 37 unchanged lines in 8 files lost coverage.
  • Overall coverage increased (+0.01%) to 91.002%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/noinst/client_impl_base.cpp 52 54 96.3%
Files with Coverage Reduction New Missed Lines %
src/realm/query_engine.hpp 1 93.94%
src/realm/array_blobs_big.cpp 2 98.58%
src/realm/object-store/shared_realm.cpp 2 91.89%
src/realm/query_expression.cpp 2 86.62%
src/realm/table.cpp 3 90.59%
src/realm/sync/transform.cpp 4 61.11%
src/realm/sync/noinst/client_impl_base.cpp 6 82.41%
test/fuzz_group.cpp 17 51.67%
Totals Coverage Status
Change from base Build 2451: 0.01%
Covered Lines: 215296
Relevant Lines: 236583

💛 - Coveralls

Copy link

coveralls-official bot commented Jun 29, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1214

Details

  • 120 of 137 (87.59%) changed or added relevant lines in 8 files are covered.
  • 78 unchanged lines in 12 files lost coverage.
  • Overall coverage decreased (-0.02%) to 90.975%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/client_base.hpp 9 10 90.0%
src/realm/sync/noinst/client_impl_base.cpp 53 69 76.81%
Files with Coverage Reduction New Missed Lines %
src/realm/sync/instruction_applier.cpp 1 67.95%
src/realm/array_blobs_big.cpp 2 98.58%
src/realm/object-store/shared_realm.cpp 2 91.89%
src/realm/table.cpp 3 90.59%
src/realm/util/future.hpp 3 95.94%
src/realm/sync/transform.cpp 4 60.92%
src/realm/sync/noinst/server/server_history.cpp 5 63.44%
test/object-store/util/sync/baas_admin_api.cpp 5 84.93%
src/realm/index_string.cpp 8 84.63%
src/realm/sync/noinst/client_impl_base.cpp 12 81.86%
Totals Coverage Status
Change from base Build 2451: -0.02%
Covered Lines: 215260
Relevant Lines: 236615

💛 - Coveralls

Copy link

coveralls-official bot commented Jun 29, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1215

Details

  • 135 of 154 (87.66%) changed or added relevant lines in 9 files are covered.
  • 63 unchanged lines in 11 files lost coverage.
  • Overall coverage decreased (-0.02%) to 90.973%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/client_base.hpp 9 10 90.0%
test/object-store/sync/flx_sync.cpp 14 16 87.5%
src/realm/sync/noinst/client_impl_base.cpp 54 70 77.14%
Files with Coverage Reduction New Missed Lines %
src/realm/array_mixed.cpp 1 94.02%
src/realm/object-store/shared_realm.cpp 2 91.89%
test/test_bplus_tree.cpp 2 99.27%
src/realm/collection_parent.cpp 3 93.08%
src/realm/table.cpp 3 90.59%
src/realm/util/future.hpp 3 95.94%
test/fuzz_tester.hpp 4 57.32%
test/object-store/util/sync/baas_admin_api.cpp 5 84.93%
src/realm/sync/noinst/server/server.cpp 6 73.74%
src/realm/sync/noinst/client_impl_base.cpp 10 81.82%
Totals Coverage Status
Change from base Build 2451: -0.02%
Covered Lines: 215256
Relevant Lines: 236616

💛 - Coveralls

Copy link

coveralls-official bot commented Jul 1, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1222

Details

  • 135 of 154 (87.66%) changed or added relevant lines in 9 files are covered.
  • 64 unchanged lines in 18 files lost coverage.
  • Overall coverage increased (+0.001%) to 91.002%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/client_base.hpp 9 10 90.0%
test/object-store/sync/flx_sync.cpp 14 16 87.5%
src/realm/sync/noinst/client_impl_base.cpp 54 70 77.14%
Files with Coverage Reduction New Missed Lines %
src/realm/mixed.cpp 1 86.75%
src/realm/sync/noinst/server/server_history.cpp 1 63.7%
test/test_index_string.cpp 1 93.48%
test/test_query2.cpp 1 98.73%
src/realm/query_expression.hpp 2 93.81%
src/realm/sync/client.cpp 3 91.74%
src/realm/sync/noinst/protocol_codec.hpp 3 74.07%
src/realm/table.cpp 3 90.59%
src/realm/util/future.hpp 3 95.94%
test/fuzz_group.cpp 3 49.12%
Totals Coverage Status
Change from base Build 2454: 0.001%
Covered Lines: 215306
Relevant Lines: 236596

💛 - Coveralls

Comment on lines 1891 to 1895
// Send QUERY messages when the upload progress client version reaches the snapshot version
// of a pending subscription, or if this is a fresh realm download session, since UPLOAD
// messages are not allowed and the upload progress will not be updated.
return m_upload_progress.client_version >= m_pending_flx_sub_set->snapshot_version ||
REALM_UNLIKELY(is_fresh_realm_download());
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this logic is invalid? We can't reorder things like this because the pending subscription may depend on the writes before it which are waiting to be uploaded. We don't want to send Pending subscriptions to the server when downloading a fresh Realm; we want to send the currently active one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this is only for the fresh realm, so there are no meaningful writes. The fresh realm bootstraps using the active subscriptions of the local realm (but they are marked pending when committed to the fresh realm) so I think it's safe to assume that any changes before that were uploaded because otherwise we would have had the same problem when bootstrapping the local realm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fresh realm sync session has its own (new) subscription store with only one pending subscription (other than query version 0), which is the active subscription from the local realm. Since we're not sending upload messages, we can't rely on the m_upload_progress.client_version value - I guess it could wait until query version 0 is complete.

Sync = 0,
// Download a fresh realm
ClientReset,
// Download a fresh realm => BIND message sessionReason = 1
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be changing this type to conflate two completely unrelated bits of state. This enum is naming the values passed to the server for the session reason, and adding other states doesn't make much sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated - now this enum is back to the original 2 values and a separate bool member variable (m_fresh_realm_download) was added to ClientImpl::Session that is set to true for client reset fresh download sessions in Activate()

The original SessionReason couldn't be used as-is since it is set to ClientReset for both the fresh download and client reset diff sessions...

Comment on lines 2297 to 2298
// Storage for the file ident from the fresh realm that was migrated to the local realm
SaltedFileIdent client_file_ident_out;
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to reread the ident from the file rather than using an out parameter. This would make it harder to accidentally have inconsistent states where we fail to actually update the ident in the file and don't notice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated - the file_ident_out parameter has been removed and the local realm file ident is being extracted after the client reset diff is complete.

Copy link

coveralls-official bot commented Jul 2, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1231

Details

  • 101 of 107 (94.39%) changed or added relevant lines in 9 files are covered.
  • 64 unchanged lines in 13 files lost coverage.
  • Overall coverage remained the same at 90.986%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/noinst/client_impl_base.cpp 39 41 95.12%
test/object-store/sync/flx_migration.cpp 1 3 33.33%
test/object-store/sync/flx_sync.cpp 9 11 81.82%
Files with Coverage Reduction New Missed Lines %
src/realm/sync/instructions.hpp 1 76.03%
src/realm/sync/noinst/server/server_history.cpp 1 63.7%
test/fuzz_tester.hpp 1 57.73%
test/test_dictionary.cpp 1 99.83%
src/realm/sync/client.cpp 3 91.02%
src/realm/sync/instruction_applier.cpp 3 68.01%
src/realm/sync/noinst/client_impl_base.cpp 3 82.15%
test/test_thread.cpp 3 66.14%
src/realm/sync/noinst/server/server.cpp 4 73.71%
src/realm/util/assert.hpp 4 87.1%
Totals Coverage Status
Change from base Build 2457: 0.0%
Covered Lines: 215170
Relevant Lines: 236487

💛 - Coveralls

Copy link

coveralls-official bot commented Jul 2, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1236

Details

  • 131 of 137 (95.62%) changed or added relevant lines in 10 files are covered.
  • 40 unchanged lines in 10 files lost coverage.
  • Overall coverage increased (+0.02%) to 90.994%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/noinst/client_impl_base.cpp 44 46 95.65%
test/object-store/sync/flx_migration.cpp 1 3 33.33%
test/object-store/sync/flx_sync.cpp 9 11 81.82%
Files with Coverage Reduction New Missed Lines %
src/realm/sort_descriptor.cpp 1 94.06%
src/realm/util/compression.cpp 1 89.62%
test/object-store/util/test_file.cpp 2 86.29%
test/test_lang_bind_helper.cpp 2 93.2%
src/realm/collection_parent.cpp 3 93.08%
src/realm/sync/noinst/client_impl_base.cpp 3 82.12%
src/realm/unicode.cpp 3 83.83%
test/fuzz_group.cpp 3 49.12%
src/realm/sync/noinst/server/server.cpp 9 73.78%
src/realm/bplustree.cpp 13 71.41%
Totals Coverage Status
Change from base Build 2466: 0.02%
Covered Lines: 215237
Relevant Lines: 236540

💛 - Coveralls

version_type current_client_version;
SaltedFileIdent file_ident;
SyncProgress sync_progress;
auto wt = target->start_read();
Copy link
Collaborator

Choose a reason for hiding this comment

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

not used

@@ -169,6 +169,10 @@ class SessionWrapper final : public util::AtomicRefCountBase, DB::CommitListener

const SessionReason m_session_reason;

// If false, QUERY and MARK messages are allowed but UPLOAD messages will not
// be sent to the server.
const bool m_allow_upload_messages = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to assign a default value since you must do it in the constructor

@@ -1871,13 +1870,17 @@ void Session::send_message()
return false;
}

// Send QUERY messages when the upload progress client version reaches the snapshot version
// of a pending subscription, or if this is a fresh realm download session, since UPLOAD
// messages are not allowed and the upload progress will not be updated.
Copy link
Collaborator

Choose a reason for hiding this comment

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

the local upload progress is actually updated, but no upload messages are sent

return m_upload_progress.client_version >= m_pending_flx_sub_set->snapshot_version;
};

if (check_pending_flx_version()) {
return send_query_change_message(); // throws
}

// Don't allow UPLOAD messages for client reset fresh realm download sessions
Copy link
Collaborator

Choose a reason for hiding this comment

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

not really doing anything in that sense to justify the comment

@@ -847,6 +847,10 @@ class ClientImpl::Session {
/// Returns the schema version the synchronization session connects with to the server.
uint64_t get_schema_version() noexcept;

// Returns false if this session is not allowed to send UPLOAD messages to the server to
// update the cursor info, such as during a client reset fresh realm download
bool are_uploads_allowed() noexcept;
Copy link
Collaborator

Choose a reason for hiding this comment

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

a bit odd to have this method while there is also m_allow_upload

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed the function to upload_messages_allowed() and m_allow_uploads to m_delay_uploads to hopefully better clarify their purpose.

src/realm/sync/noinst/client_impl_base.cpp Show resolved Hide resolved
Copy link

coveralls-official bot commented Jul 2, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1237

Details

  • 129 of 135 (95.56%) changed or added relevant lines in 10 files are covered.
  • 65 unchanged lines in 17 files lost coverage.
  • Overall coverage increased (+0.007%) to 90.991%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/noinst/client_impl_base.cpp 42 44 95.45%
test/object-store/sync/flx_migration.cpp 1 3 33.33%
test/object-store/sync/flx_sync.cpp 9 11 81.82%
Files with Coverage Reduction New Missed Lines %
src/realm/dictionary.cpp 1 85.16%
src/realm/sync/noinst/server/server.cpp 1 73.93%
src/realm/util/serializer.cpp 1 90.43%
test/test_table.cpp 1 99.51%
src/realm/db.cpp 2 92.19%
src/realm/list.cpp 2 87.37%
src/realm/mixed.cpp 2 86.46%
src/realm/sync/network/http.hpp 2 82.27%
src/realm/table_view.cpp 2 92.99%
test/object-store/util/test_file.cpp 2 86.29%
Totals Coverage Status
Change from base Build 2467: 0.007%
Covered Lines: 215219
Relevant Lines: 236528

💛 - Coveralls

Copy link

coveralls-official bot commented Jul 2, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1238

Details

  • 135 of 142 (95.07%) changed or added relevant lines in 10 files are covered.
  • 49 unchanged lines in 18 files lost coverage.
  • Overall coverage increased (+0.004%) to 90.988%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/noinst/client_impl_base.hpp 6 7 85.71%
src/realm/sync/noinst/client_impl_base.cpp 47 49 95.92%
test/object-store/sync/flx_migration.cpp 1 3 33.33%
test/object-store/sync/flx_sync.cpp 9 11 81.82%
Files with Coverage Reduction New Missed Lines %
src/realm/dictionary.cpp 1 85.16%
src/realm/query_engine.hpp 1 93.94%
src/realm/sync/noinst/changeset_index.cpp 1 79.47%
src/realm/sync/noinst/server/server.cpp 1 74.4%
src/realm/sync/noinst/server/server_history.cpp 1 63.51%
src/realm/util/serializer.cpp 1 90.43%
test/test_index_string.cpp 1 93.48%
src/realm/list.cpp 2 87.37%
src/realm/mixed.cpp 2 86.46%
src/realm/sync/network/http.hpp 2 82.27%
Totals Coverage Status
Change from base Build 2467: 0.004%
Covered Lines: 215212
Relevant Lines: 236527

💛 - Coveralls

Copy link

coveralls-official bot commented Jul 3, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1243

Details

  • 136 of 143 (95.1%) changed or added relevant lines in 10 files are covered.
  • 66 unchanged lines in 17 files lost coverage.
  • Overall coverage decreased (-0.008%) to 90.976%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/noinst/client_impl_base.hpp 7 8 87.5%
src/realm/sync/noinst/client_impl_base.cpp 47 49 95.92%
test/object-store/sync/flx_migration.cpp 1 3 33.33%
test/object-store/sync/flx_sync.cpp 9 11 81.82%
Files with Coverage Reduction New Missed Lines %
src/realm/dictionary.cpp 1 85.16%
src/realm/query_engine.hpp 1 93.94%
src/realm/sort_descriptor.cpp 1 94.06%
src/realm/sync/noinst/server/server_history.cpp 1 63.7%
src/realm/util/serializer.cpp 1 90.43%
src/realm/list.cpp 2 87.37%
src/realm/mixed.cpp 2 86.46%
src/realm/sync/network/http.hpp 2 82.27%
src/realm/sync/noinst/client_impl_base.cpp 2 82.2%
src/realm/table_view.cpp 2 92.99%
Totals Coverage Status
Change from base Build 2467: -0.008%
Covered Lines: 215189
Relevant Lines: 236534

💛 - Coveralls

@@ -952,7 +956,7 @@ class ClientImpl::Session {
// Set to true when download completion is reached. Set to false after a
Copy link
Collaborator

Choose a reason for hiding this comment

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

you need to update the comment

Copy link

coveralls-official bot commented Jul 3, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1245

Details

  • 140 of 147 (95.24%) changed or added relevant lines in 10 files are covered.
  • 68 unchanged lines in 14 files lost coverage.
  • Overall coverage increased (+0.002%) to 90.986%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/sync/noinst/client_impl_base.hpp 7 8 87.5%
src/realm/sync/noinst/client_impl_base.cpp 47 49 95.92%
test/object-store/sync/flx_migration.cpp 1 3 33.33%
test/object-store/sync/flx_sync.cpp 9 11 81.82%
Files with Coverage Reduction New Missed Lines %
src/realm/sync/noinst/server/server_history.cpp 1 63.7%
src/realm/util/serializer.cpp 1 90.43%
test/fuzz_tester.hpp 1 57.73%
test/test_index_string.cpp 1 93.48%
src/realm/mixed.cpp 2 86.46%
src/realm/sync/network/http.hpp 2 82.27%
src/realm/sync/noinst/client_impl_base.cpp 2 82.15%
src/realm/collection_parent.cpp 3 93.08%
src/realm/sync/noinst/protocol_codec.hpp 3 74.07%
src/realm/table.cpp 3 90.42%
Totals Coverage Status
Change from base Build 2467: 0.002%
Covered Lines: 215209
Relevant Lines: 236529

💛 - Coveralls

@jbreams
Copy link
Contributor

jbreams commented Jul 3, 2024

@tgoyne , can you take another look when you get a chance?

Copy link
Contributor

@ironage ironage left a comment

Choose a reason for hiding this comment

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

LGTM

@michael-wb michael-wb merged commit dd4992e into master Jul 3, 2024
40 checks passed
@michael-wb michael-wb deleted the mwb/fix-client-reset-ident branch July 3, 2024 22:12
@github-actions github-actions bot mentioned this pull request Jul 5, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 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.

Sync client should steal file ident of fresh realm when performing client reset
5 participants