From b00e7ed382e97780343267296bd246714c7034b9 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Thu, 16 Jun 2022 14:26:01 +0200 Subject: [PATCH] Client reset: use ThreadSafeReference instead of SharedRealm (related to https://github.com/realm/realm-js/issues/4410) --- src/realm/object-store/sync/sync_session.cpp | 10 +++++----- src/realm/sync/config.hpp | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/realm/object-store/sync/sync_session.cpp b/src/realm/object-store/sync/sync_session.cpp index 25f4582154f..3954a9e519b 100644 --- a/src/realm/object-store/sync/sync_session.cpp +++ b/src/realm/object-store/sync/sync_session.cpp @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -608,19 +609,18 @@ static sync::Session::Config::ClientReset make_client_reset_config(SyncConfig& s config.notify_after_client_reset = [notify = session_config.notify_after_client_reset]( std::string local_path, VersionID previous_version, bool did_recover) { REALM_ASSERT(!local_path.empty()); - SharedRealm frozen_before, active_after; + SharedRealm frozen_before; + ThreadSafeReference active_after; if (auto local_coordinator = RealmCoordinator::get_existing_coordinator(local_path)) { auto local_config = local_coordinator->get_config(); - active_after = local_coordinator->get_realm(local_config, util::none); + active_after = local_coordinator->get_unbound_realm(); local_config.scheduler = nullptr; frozen_before = local_coordinator->get_realm(local_config, previous_version); - REALM_ASSERT(active_after); - REALM_ASSERT(!active_after->is_frozen()); REALM_ASSERT(frozen_before); REALM_ASSERT(frozen_before->is_frozen()); } if (notify) { - notify(frozen_before, active_after, did_recover); + notify(frozen_before, std::move(active_after), did_recover); } }; config.notify_before_client_reset = [notify = session_config.notify_before_client_reset](std::string local_path) { diff --git a/src/realm/sync/config.hpp b/src/realm/sync/config.hpp index ca7ef6eb954..3fc93c2fb8c 100644 --- a/src/realm/sync/config.hpp +++ b/src/realm/sync/config.hpp @@ -36,6 +36,7 @@ namespace realm { class SyncUser; class SyncSession; class Realm; +class ThreadSafeReference; namespace bson { class Bson; @@ -182,7 +183,7 @@ struct SyncConfig { util::Optional recovery_directory; ClientResyncMode client_resync_mode = ClientResyncMode::Manual; std::function before_frozen)> notify_before_client_reset; - std::function before_frozen, std::shared_ptr after, bool did_recover)> + std::function before_frozen, ThreadSafeReference after, bool did_recover)> notify_after_client_reset; // Will be called after a download message is received and validated by the client but befefore it's been