@@ -44,8 +44,12 @@ void ClientHistory::set_client_file_ident_in_wt(version_type current_version, Sa
4444
4545 Array& root = m_arrays->root ;
4646 m_group->set_sync_file_id (client_file_ident.ident ); // Throws
47+ root.set (s_client_file_ident_iip,
48+ RefOrTagged::make_tagged (client_file_ident.ident )); // Throws
4749 root.set (s_client_file_ident_salt_iip,
4850 RefOrTagged::make_tagged (client_file_ident.salt )); // Throws
51+
52+ m_client_file_ident = client_file_ident.ident ;
4953}
5054
5155
@@ -61,6 +65,8 @@ void ClientHistory::set_client_reset_adjustments(version_type current_version, S
6165 UploadCursor upload_progress = {0 , 0 };
6266 Array& root = m_arrays->root ;
6367 m_group->set_sync_file_id (client_file_ident.ident ); // Throws
68+ root.set (s_client_file_ident_iip,
69+ RefOrTagged::make_tagged (client_file_ident.ident )); // Throws
6470 root.set (s_client_file_ident_salt_iip,
6571 RefOrTagged::make_tagged (client_file_ident.salt )); // Throws
6672 root.set (s_progress_download_server_version_iip,
@@ -84,6 +90,8 @@ void ClientHistory::set_client_reset_adjustments(version_type current_version, S
8490 root.set (s_progress_uploadable_bytes_iip,
8591 RefOrTagged::make_tagged (0 )); // Throws
8692
93+ m_client_file_ident = client_file_ident.ident ;
94+
8795 // Discard existing synchronization history
8896 do_trim_sync_history (sync_history_size ()); // Throws
8997
@@ -152,7 +160,7 @@ int ClientReplication::get_history_schema_version() const noexcept
152160// Overriding member function in realm::Replication
153161bool ClientReplication::is_upgradable_history_schema (int stored_schema_version) const noexcept
154162{
155- if (stored_schema_version == 11 ) {
163+ if (stored_schema_version == 11 || stored_schema_version == 12 ) {
156164 return true ;
157165 }
158166 return false ;
@@ -176,6 +184,11 @@ void ClientReplication::upgrade_history_schema(int stored_schema_version)
176184 schema_version = 12 ;
177185 }
178186
187+ if (schema_version < 13 ) {
188+ m_history.update_client_file_id ();
189+ schema_version = 13 ;
190+ }
191+
179192 // NOTE: Future migration steps go here.
180193
181194 REALM_ASSERT (schema_version == get_client_history_schema_version ());
@@ -184,6 +197,19 @@ void ClientReplication::upgrade_history_schema(int stored_schema_version)
184197 m_history.record_current_schema_version (); // Throws
185198}
186199
200+ void ClientHistory::update_client_file_id ()
201+ {
202+ using gf = _impl::GroupFriend;
203+ Allocator& alloc = gf::get_alloc (*m_group);
204+ auto ref = gf::get_history_ref (*m_group);
205+ Array root{alloc};
206+ root.init_from_ref (ref);
207+ gf::set_history_parent (*m_group, root);
208+
209+ auto file_id = m_group->get_sync_file_id ();
210+ root.set (s_client_file_ident_iip, RefOrTagged::make_tagged (file_id));
211+ }
212+
187213void ClientHistory::compress_stored_changesets ()
188214{
189215 using gf = _impl::GroupFriend;
@@ -235,12 +261,13 @@ void ClientHistory::get_status(version_type& current_client_version, SaltedFileI
235261 TransactionRef rt = m_db->start_read (); // Throws
236262 version_type current_client_version_2 = rt->get_version ();
237263
238- SaltedFileIdent client_file_ident_2{rt-> get_sync_file_id () , 0 };
264+ SaltedFileIdent client_file_ident_2{m_client_file_ident , 0 };
239265 SyncProgress progress_2;
240266 using gf = _impl::GroupFriend;
241267 if (ref_type ref = gf::get_history_ref (*rt)) {
242268 Array root (m_db->get_alloc ());
243269 root.init_from_ref (ref);
270+ client_file_ident_2.ident = file_ident_type (root.get_as_ref_or_tagged (s_client_file_ident_iip).get_as_int ());
244271 client_file_ident_2.salt = salt_type (root.get_as_ref_or_tagged (s_client_file_ident_salt_iip).get_as_int ());
245272 progress_2.latest_server_version .version =
246273 version_type (root.get_as_ref_or_tagged (s_progress_latest_server_version_iip).get_as_int ());
@@ -280,13 +307,17 @@ void ClientHistory::set_client_file_ident(SaltedFileIdent client_file_ident)
280307 prepare_for_write (); // Throws
281308
282309 Array& root = m_arrays->root ;
283- REALM_ASSERT (wt-> get_sync_file_id () == 0 );
310+ REALM_ASSERT (m_client_file_ident == 0 );
284311 wt->set_sync_file_id (client_file_ident.ident );
312+ root.set (s_client_file_ident_iip,
313+ RefOrTagged::make_tagged (client_file_ident.ident )); // Throws
285314 root.set (s_client_file_ident_salt_iip,
286315 RefOrTagged::make_tagged (client_file_ident.salt )); // Throws
287316 root.set (s_progress_download_client_version_iip, RefOrTagged::make_tagged (0 ));
288317 root.set (s_progress_upload_client_version_iip, RefOrTagged::make_tagged (0 ));
289318
319+ m_client_file_ident = client_file_ident.ident ;
320+
290321 // Note: This transaction produces an empty changeset. Empty changesets are
291322 // not uploaded to the server.
292323 wt->commit (); // Throws
@@ -420,8 +451,7 @@ void ClientHistory::integrate_server_changesets(
420451 }
421452 VersionID old_version = transact->get_version_of_current_transaction ();
422453 version_type local_version = old_version.version ;
423- auto sync_file_id = transact->get_sync_file_id ();
424- REALM_ASSERT (sync_file_id != 0 );
454+ REALM_ASSERT (m_client_file_ident != 0 );
425455
426456 ensure_updated (local_version); // Throws
427457 prepare_for_write (); // Throws
@@ -520,12 +550,11 @@ size_t ClientHistory::transform_and_apply_server_changesets(util::Span<Changeset
520550 }
521551
522552 version_type local_version = transact->get_version_of_current_transaction ().version ;
523- auto sync_file_id = transact->get_sync_file_id ();
524553
525554 try {
526555 for (auto & changeset : changesets_to_integrate) {
527556 REALM_ASSERT (changeset.last_integrated_remote_version <= local_version);
528- REALM_ASSERT (changeset.origin_file_ident > 0 && changeset.origin_file_ident != sync_file_id );
557+ REALM_ASSERT (changeset.origin_file_ident > 0 && changeset.origin_file_ident != m_client_file_ident );
529558
530559 // It is possible that the synchronization history has been trimmed
531560 // to a point where a prefix of the merge window is no longer
@@ -555,9 +584,9 @@ size_t ClientHistory::transform_and_apply_server_changesets(util::Span<Changeset
555584 return !(m_db->other_writers_waiting_for_lock () &&
556585 transact->get_commit_size () >= commit_byte_size_limit && allow_lock_release);
557586 };
558- auto changesets_transformed_count =
559- transformer. transform_remote_changesets ( *this , sync_file_id , local_version, changesets_to_integrate,
560- std::move (changeset_applier), logger); // Throws
587+ auto changesets_transformed_count = transformer. transform_remote_changesets (
588+ *this , m_client_file_ident , local_version, changesets_to_integrate, std::move (changeset_applier) ,
589+ logger); // Throws
561590 return changesets_transformed_count;
562591 }
563592 catch (const BadChangesetError& e) {
@@ -1095,6 +1124,7 @@ void ClientHistory::update_from_ref_and_version(ref_type ref, version_type versi
10951124 // No history
10961125 m_ct_history_base_version = version;
10971126 m_sync_history_base_version = version;
1127+ m_client_file_ident = 0 ;
10981128 m_arrays.reset ();
10991129 m_progress_download = {0 , 0 };
11001130 return ;
@@ -1115,6 +1145,7 @@ void ClientHistory::update_from_ref_and_version(ref_type ref, version_type versi
11151145 REALM_ASSERT (m_arrays->origin_timestamps .size () == sync_history_size ());
11161146
11171147 const Array& root = m_arrays->root ;
1148+ m_client_file_ident = file_ident_type (root.get_as_ref_or_tagged (s_client_file_ident_iip).get_as_int ());
11181149 m_progress_download.server_version =
11191150 version_type (root.get_as_ref_or_tagged (s_progress_download_server_version_iip).get_as_int ());
11201151 m_progress_download.last_integrated_client_version =
@@ -1167,6 +1198,7 @@ void ClientHistory::verify() const
11671198 if (!m_arrays) {
11681199 REALM_ASSERT (m_progress_download.server_version == 0 );
11691200 REALM_ASSERT (m_progress_download.last_integrated_client_version == 0 );
1201+ REALM_ASSERT (m_client_file_ident == 0 );
11701202 return ;
11711203 }
11721204 m_arrays->verify ();
0 commit comments