@@ -44,8 +44,12 @@ void ClientHistory::set_client_file_ident_in_wt(version_type current_version, Sa
44
44
45
45
Array& root = m_arrays->root ;
46
46
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
47
49
root.set (s_client_file_ident_salt_iip,
48
50
RefOrTagged::make_tagged (client_file_ident.salt )); // Throws
51
+
52
+ m_client_file_ident = client_file_ident.ident ;
49
53
}
50
54
51
55
@@ -61,6 +65,8 @@ void ClientHistory::set_client_reset_adjustments(version_type current_version, S
61
65
UploadCursor upload_progress = {0 , 0 };
62
66
Array& root = m_arrays->root ;
63
67
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
64
70
root.set (s_client_file_ident_salt_iip,
65
71
RefOrTagged::make_tagged (client_file_ident.salt )); // Throws
66
72
root.set (s_progress_download_server_version_iip,
@@ -84,6 +90,8 @@ void ClientHistory::set_client_reset_adjustments(version_type current_version, S
84
90
root.set (s_progress_uploadable_bytes_iip,
85
91
RefOrTagged::make_tagged (0 )); // Throws
86
92
93
+ m_client_file_ident = client_file_ident.ident ;
94
+
87
95
// Discard existing synchronization history
88
96
do_trim_sync_history (sync_history_size ()); // Throws
89
97
@@ -152,7 +160,7 @@ int ClientReplication::get_history_schema_version() const noexcept
152
160
// Overriding member function in realm::Replication
153
161
bool ClientReplication::is_upgradable_history_schema (int stored_schema_version) const noexcept
154
162
{
155
- if (stored_schema_version == 11 ) {
163
+ if (stored_schema_version == 11 || stored_schema_version == 12 ) {
156
164
return true ;
157
165
}
158
166
return false ;
@@ -176,6 +184,11 @@ void ClientReplication::upgrade_history_schema(int stored_schema_version)
176
184
schema_version = 12 ;
177
185
}
178
186
187
+ if (schema_version < 13 ) {
188
+ m_history.update_client_file_id ();
189
+ schema_version = 13 ;
190
+ }
191
+
179
192
// NOTE: Future migration steps go here.
180
193
181
194
REALM_ASSERT (schema_version == get_client_history_schema_version ());
@@ -184,6 +197,19 @@ void ClientReplication::upgrade_history_schema(int stored_schema_version)
184
197
m_history.record_current_schema_version (); // Throws
185
198
}
186
199
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
+
187
213
void ClientHistory::compress_stored_changesets ()
188
214
{
189
215
using gf = _impl::GroupFriend;
@@ -235,12 +261,13 @@ void ClientHistory::get_status(version_type& current_client_version, SaltedFileI
235
261
TransactionRef rt = m_db->start_read (); // Throws
236
262
version_type current_client_version_2 = rt->get_version ();
237
263
238
- SaltedFileIdent client_file_ident_2{rt-> get_sync_file_id () , 0 };
264
+ SaltedFileIdent client_file_ident_2{m_client_file_ident , 0 };
239
265
SyncProgress progress_2;
240
266
using gf = _impl::GroupFriend;
241
267
if (ref_type ref = gf::get_history_ref (*rt)) {
242
268
Array root (m_db->get_alloc ());
243
269
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 ());
244
271
client_file_ident_2.salt = salt_type (root.get_as_ref_or_tagged (s_client_file_ident_salt_iip).get_as_int ());
245
272
progress_2.latest_server_version .version =
246
273
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)
280
307
prepare_for_write (); // Throws
281
308
282
309
Array& root = m_arrays->root ;
283
- REALM_ASSERT (wt-> get_sync_file_id () == 0 );
310
+ REALM_ASSERT (m_client_file_ident == 0 );
284
311
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
285
314
root.set (s_client_file_ident_salt_iip,
286
315
RefOrTagged::make_tagged (client_file_ident.salt )); // Throws
287
316
root.set (s_progress_download_client_version_iip, RefOrTagged::make_tagged (0 ));
288
317
root.set (s_progress_upload_client_version_iip, RefOrTagged::make_tagged (0 ));
289
318
319
+ m_client_file_ident = client_file_ident.ident ;
320
+
290
321
// Note: This transaction produces an empty changeset. Empty changesets are
291
322
// not uploaded to the server.
292
323
wt->commit (); // Throws
@@ -420,8 +451,7 @@ void ClientHistory::integrate_server_changesets(
420
451
}
421
452
VersionID old_version = transact->get_version_of_current_transaction ();
422
453
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 );
425
455
426
456
ensure_updated (local_version); // Throws
427
457
prepare_for_write (); // Throws
@@ -520,12 +550,11 @@ size_t ClientHistory::transform_and_apply_server_changesets(util::Span<Changeset
520
550
}
521
551
522
552
version_type local_version = transact->get_version_of_current_transaction ().version ;
523
- auto sync_file_id = transact->get_sync_file_id ();
524
553
525
554
try {
526
555
for (auto & changeset : changesets_to_integrate) {
527
556
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 );
529
558
530
559
// It is possible that the synchronization history has been trimmed
531
560
// 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
555
584
return !(m_db->other_writers_waiting_for_lock () &&
556
585
transact->get_commit_size () >= commit_byte_size_limit && allow_lock_release);
557
586
};
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
561
590
return changesets_transformed_count;
562
591
}
563
592
catch (const BadChangesetError& e) {
@@ -1095,6 +1124,7 @@ void ClientHistory::update_from_ref_and_version(ref_type ref, version_type versi
1095
1124
// No history
1096
1125
m_ct_history_base_version = version;
1097
1126
m_sync_history_base_version = version;
1127
+ m_client_file_ident = 0 ;
1098
1128
m_arrays.reset ();
1099
1129
m_progress_download = {0 , 0 };
1100
1130
return ;
@@ -1115,6 +1145,7 @@ void ClientHistory::update_from_ref_and_version(ref_type ref, version_type versi
1115
1145
REALM_ASSERT (m_arrays->origin_timestamps .size () == sync_history_size ());
1116
1146
1117
1147
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 ());
1118
1149
m_progress_download.server_version =
1119
1150
version_type (root.get_as_ref_or_tagged (s_progress_download_server_version_iip).get_as_int ());
1120
1151
m_progress_download.last_integrated_client_version =
@@ -1167,6 +1198,7 @@ void ClientHistory::verify() const
1167
1198
if (!m_arrays) {
1168
1199
REALM_ASSERT (m_progress_download.server_version == 0 );
1169
1200
REALM_ASSERT (m_progress_download.last_integrated_client_version == 0 );
1201
+ REALM_ASSERT (m_client_file_ident == 0 );
1170
1202
return ;
1171
1203
}
1172
1204
m_arrays->verify ();
0 commit comments