Skip to content

Commit

Permalink
Add schema version to flexible sync client BIND message (#6863)
Browse files Browse the repository at this point in the history
* Send schema version as part of BIND messages

* Update comment

* Changelog
  • Loading branch information
danieltabacaru committed Jan 8, 2024
1 parent 822c29d commit 01ca8a1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
* Add baas-network-tests nightly task for testing sync client operation with non-ideal network conditions. ([PR #6852](https://github.com/realm/realm-core/pull/6852))
* Added non-ideal network conditions and network fault tests to the evergreen nightly test runs. ([PR #7063](https://github.com/realm/realm-core/pull/7063))
* Updated baas tests to run with dev mode disabled by default. ([PR #6852](https://github.com/realm/realm-core/pull/6852))
* Add schema version to flexible sync client BIND message. ([#6840](https://github.com/realm/realm-core/issues/6840))

----------------------------------------------

Expand Down
12 changes: 11 additions & 1 deletion src/realm/sync/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class SessionWrapper final : public util::AtomicRefCountBase, DB::CommitListener

SessionReason m_session_reason;

const uint64_t m_schema_version;

std::shared_ptr<SubscriptionStore> m_flx_subscription_store;
int64_t m_flx_active_version = 0;
int64_t m_flx_last_seen_version = 0;
Expand Down Expand Up @@ -714,6 +716,13 @@ SessionReason SessionImpl::get_session_reason() noexcept
return m_wrapper.m_session_reason;
}

uint64_t SessionImpl::get_schema_version() noexcept
{
// Can only be called if the session is active or being activated
REALM_ASSERT_EX(m_state == State::Active || m_state == State::Unactivated, m_state);
return m_wrapper.m_schema_version;
}

void SessionImpl::initiate_integrate_changesets(std::uint_fast64_t downloadable_bytes, DownloadBatchState batch_state,
const SyncProgress& progress, const ReceivedChangesets& changesets)
{
Expand Down Expand Up @@ -1140,6 +1149,7 @@ SessionWrapper::SessionWrapper(ClientImpl& client, DBRef db, std::shared_ptr<Sub
, m_proxy_config{config.proxy_config} // Throws
, m_debug_hook(std::move(config.on_sync_client_event_hook))
, m_session_reason(config.session_reason)
, m_schema_version(config.schema_version)
, m_flx_subscription_store(std::move(flx_sub_store))
, m_migration_store(std::move(migration_store))
{
Expand Down Expand Up @@ -2012,7 +2022,7 @@ void Client::voluntary_disconnect_all_connections()

bool Client::wait_for_session_terminations_or_client_stopped()
{
return m_impl.get()->wait_for_session_terminations_or_client_stopped();
return m_impl->wait_for_session_terminations_or_client_stopped();
}


Expand Down
5 changes: 5 additions & 0 deletions src/realm/sync/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ class Session {
///
/// Note: Currently only used in FLX sync.
SessionReason session_reason = SessionReason::Sync;

/// Schema version
///
/// Note: Currently set only for FLX sync.
uint64_t schema_version = -1; // = ObjectStore::NotVersioned
};

/// \brief Start a new session for the specified client-side Realm.
Expand Down
7 changes: 3 additions & 4 deletions src/realm/sync/noinst/client_impl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,8 @@ ClientImpl::ClientImpl(ClientConfig config)
REALM_ASSERT_EX(m_socket_provider, "Must provide socket provider in sync Client config");

if (m_one_connection_per_session) {
// FIXME: Re-enable this warning when the load balancer is able to handle
// multiplexing.
// logger.warn("Testing/debugging feature 'one connection per session' enabled - "
// "never do this in production");
logger.warn("Testing/debugging feature 'one connection per session' enabled - "
"never do this in production");
}

if (config.disable_upload_activation_delay) {
Expand Down Expand Up @@ -1873,6 +1871,7 @@ void Session::send_bind_message()
bind_json_data["migratedPartition"] = *migrated_partition;
}
bind_json_data["sessionReason"] = static_cast<uint64_t>(get_session_reason());
bind_json_data["schema_version"] = get_schema_version();
if (logger.would_log(util::Logger::Level::debug)) {
std::string json_data_dump;
if (!bind_json_data.empty()) {
Expand Down
3 changes: 3 additions & 0 deletions src/realm/sync/noinst/client_impl_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,9 @@ class ClientImpl::Session {
// - Client reset state means the session is going to be used to download a fresh realm.
SessionReason get_session_reason() noexcept;

/// Returns the schema version the synchronization session connects with to the server.
uint64_t get_schema_version() noexcept;

/// \brief Initiate the integration of downloaded changesets.
///
/// This function must provide for the passed changesets (if any) to
Expand Down

0 comments on commit 01ca8a1

Please sign in to comment.