Skip to content

Commit 1815605

Browse files
committed
Only track pending client resets done by the same core version
If the previous attempt at performing a client reset was done with a different core version then we should retry the client reset as the new version may have fixed a bug that made the previous attempt fail (or may be a downgrade to a version before when the bug was introduced). This also simplifies the tracking as it means that we don't need to be able to read trackers created by different versions. This also means that we can freely change the schema of the table, which this takes advantage of to drop the unused primary key and make the error required, as we never actually stored null and the code reading it would have crashed if it encountered a null error.
1 parent b10122e commit 1815605

15 files changed

+210
-334
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### Enhancements
44
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
5-
* None.
5+
* Client reset cycle detection now checks if the previous recovery attempt was made by the same core version, and if not attempts recovery again ([PR #7944](https://github.com/realm/realm-core/pull/7944)).
66

77
### Fixed
88
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)

src/realm/sync/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ set(NOINST_HEADERS
7676
noinst/integer_codec.hpp
7777
noinst/migration_store.hpp
7878
noinst/pending_bootstrap_store.hpp
79+
noinst/pending_reset_store.hpp
7980
noinst/protocol_codec.hpp
8081
noinst/root_certs.hpp
8182
noinst/sync_metadata_schema.hpp

src/realm/sync/client.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ void SessionWrapper::handle_pending_client_reset_acknowledgement()
16551655
{
16561656
REALM_ASSERT(!m_finalized);
16571657

1658-
auto has_pending_reset = PendingResetStore::has_pending_reset(m_db->start_frozen());
1658+
auto has_pending_reset = PendingResetStore::has_pending_reset(*m_db->start_frozen());
16591659
if (!has_pending_reset) {
16601660
return; // nothing to do
16611661
}
@@ -1678,7 +1678,7 @@ void SessionWrapper::handle_pending_client_reset_acknowledgement()
16781678
logger.debug(util::LogCategory::reset, "Server has acknowledged %1", pending_reset);
16791679

16801680
auto tr = self->m_db->start_write();
1681-
auto cur_pending_reset = PendingResetStore::has_pending_reset(tr);
1681+
auto cur_pending_reset = PendingResetStore::has_pending_reset(*tr);
16821682
if (!cur_pending_reset) {
16831683
logger.debug(util::LogCategory::reset, "Client reset cycle detection tracker already removed.");
16841684
return;
@@ -1689,7 +1689,7 @@ void SessionWrapper::handle_pending_client_reset_acknowledgement()
16891689
else {
16901690
logger.info(util::LogCategory::reset, "Found new %1", cur_pending_reset);
16911691
}
1692-
PendingResetStore::clear_pending_reset(tr);
1692+
PendingResetStore::clear_pending_reset(*tr);
16931693
tr->commit();
16941694
});
16951695
}

src/realm/sync/noinst/client_reset.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -410,18 +410,17 @@ void transfer_group(const Transaction& group_src, Transaction& group_dst, util::
410410
}
411411
}
412412

413-
ClientResyncMode reset_precheck_guard(const TransactionRef& wt_local, ClientResyncMode mode,
414-
PendingReset::Action action, const std::optional<Status>& error,
415-
util::Logger& logger)
413+
static ClientResyncMode reset_precheck_guard(const TransactionRef& wt_local, ClientResyncMode mode,
414+
PendingReset::Action action, const Status& error, util::Logger& logger)
416415
{
417-
if (auto previous_reset = sync::PendingResetStore::has_pending_reset(wt_local)) {
416+
if (auto previous_reset = sync::PendingResetStore::has_pending_reset(*wt_local)) {
418417
logger.info(util::LogCategory::reset, "Found a previous %1", *previous_reset);
419418
if (action != previous_reset->action) {
420419
// IF a different client reset is being performed, cler the pending client reset and start over.
421420
logger.info(util::LogCategory::reset,
422421
"New '%1' client reset of type: '%2' is incompatible - clearing previous reset", action,
423422
mode);
424-
sync::PendingResetStore::clear_pending_reset(wt_local);
423+
sync::PendingResetStore::clear_pending_reset(*wt_local);
425424
}
426425
else {
427426
switch (previous_reset->mode) {
@@ -444,10 +443,10 @@ ClientResyncMode reset_precheck_guard(const TransactionRef& wt_local, ClientResy
444443
util::LogCategory::reset,
445444
"A previous '%1' mode reset from %2 downgrades this mode ('%3') to DiscardLocal",
446445
previous_reset->mode, previous_reset->time, mode);
447-
sync::PendingResetStore::clear_pending_reset(wt_local);
446+
sync::PendingResetStore::clear_pending_reset(*wt_local);
448447
break;
449448
case ClientResyncMode::DiscardLocal:
450-
sync::PendingResetStore::clear_pending_reset(wt_local);
449+
sync::PendingResetStore::clear_pending_reset(*wt_local);
451450
// previous mode Recover and this mode is Discard, this is not a cycle yet
452451
break;
453452
case ClientResyncMode::Manual:
@@ -473,7 +472,7 @@ ClientResyncMode reset_precheck_guard(const TransactionRef& wt_local, ClientResy
473472
mode = ClientResyncMode::DiscardLocal;
474473
}
475474
}
476-
sync::PendingResetStore::track_reset(wt_local, mode, action, error);
475+
sync::PendingResetStore::track_reset(*wt_local, mode, action, error);
477476
// Ensure we save the tracker object even if we encounter an error and roll
478477
// back the client reset later
479478
wt_local->commit_and_continue_writing();

src/realm/sync/noinst/client_reset.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ namespace _impl::client_reset {
6262
void transfer_group(const Transaction& tr_src, Transaction& tr_dst, util::Logger& logger,
6363
bool allow_schema_additions);
6464

65-
ClientResyncMode reset_precheck_guard(const TransactionRef& wt_local, ClientResyncMode mode,
66-
sync::ProtocolErrorInfo::Action action, const std::optional<Status>& error,
67-
util::Logger& logger);
68-
6965
// preform_client_reset_diff() takes the Realm performs a client reset on
7066
// the Realm in 'path_local' given the Realm 'path_fresh' as the source of truth.
7167
// If the fresh path is not provided, discard mode is assumed and all data in the local

src/realm/sync/noinst/migration_store.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool MigrationStore::load_data(bool read_only)
6060
throw RuntimeError(ErrorCodes::UnsupportedFileFormatVersion,
6161
"Invalid schema version for flexible sync migration store metadata");
6262
}
63-
load_sync_metadata_schema(tr, &internal_tables);
63+
load_sync_metadata_schema(*tr, &internal_tables);
6464
}
6565
else {
6666
if (read_only) {
@@ -72,7 +72,7 @@ bool MigrationStore::load_data(bool read_only)
7272
SyncMetadataSchemaVersions schema_versions(tr);
7373
// Create the metadata schema and set the version (in the same commit)
7474
schema_versions.set_version_for(tr, internal_schema_groups::c_flx_migration_store, c_schema_version);
75-
create_sync_metadata_schema(tr, &internal_tables);
75+
create_sync_metadata_schema(*tr, &internal_tables);
7676
tr->commit_and_continue_as_read();
7777
}
7878
REALM_ASSERT(m_migration_table);

src/realm/sync/noinst/pending_bootstrap_store.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ PendingBootstrapStore::PendingBootstrapStore(DBRef db, util::Logger& logger,
109109
throw RuntimeError(ErrorCodes::SchemaVersionMismatch,
110110
"Invalid schema version for FLX sync pending bootstrap table group");
111111
}
112-
load_sync_metadata_schema(tr, &internal_tables);
112+
load_sync_metadata_schema(*tr, &internal_tables);
113113
}
114114
else {
115115
tr->promote_to_write();
116116
// Ensure the schema versions table is initialized (may add its own commit)
117117
SyncMetadataSchemaVersions schema_versions(tr);
118118
// Create the metadata schema and set the version (in the same commit)
119119
schema_versions.set_version_for(tr, internal_schema_groups::c_pending_bootstraps, c_schema_version);
120-
create_sync_metadata_schema(tr, &internal_tables);
120+
create_sync_metadata_schema(*tr, &internal_tables);
121121
tr->commit_and_continue_as_read();
122122
}
123123
REALM_ASSERT(m_table);

0 commit comments

Comments
 (0)