Skip to content

Commit d8a2e45

Browse files
authored
Revert "Disable replication when writing to the pending bootstrap store" (#7776)
This reverts commit afe0e0f. DisableReplication actually disables replication on the DB, not the Transaction, so it's extremely unsafe to use.
1 parent 1f78955 commit d8a2e45

File tree

1 file changed

+31
-37
lines changed

1 file changed

+31
-37
lines changed

src/realm/sync/noinst/pending_bootstrap_store.cpp

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -141,44 +141,39 @@ void PendingBootstrapStore::add_batch(int64_t query_version, util::Optional<Sync
141141
}
142142

143143
auto tr = m_db->start_write();
144-
bool did_create = false;
144+
auto bootstrap_table = tr->get_table(m_table);
145+
auto incomplete_bootstraps = Query(bootstrap_table).not_equal(m_query_version, query_version).find_all();
146+
incomplete_bootstraps.for_each([&](Obj obj) {
147+
m_logger.debug(util::LogCategory::changeset, "Clearing incomplete bootstrap for query version %1",
148+
obj.get<int64_t>(m_query_version));
149+
return IteratorControl::AdvanceToNext;
150+
});
151+
incomplete_bootstraps.clear();
145152

146-
{
147-
DisableReplication disable_replication(*tr);
148-
auto bootstrap_table = tr->get_table(m_table);
149-
auto incomplete_bootstraps = Query(bootstrap_table).not_equal(m_query_version, query_version).find_all();
150-
incomplete_bootstraps.for_each([&](Obj obj) {
151-
m_logger.debug(util::LogCategory::changeset, "Clearing incomplete bootstrap for query version %1",
152-
obj.get<int64_t>(m_query_version));
153-
return IteratorControl::AdvanceToNext;
154-
});
155-
incomplete_bootstraps.clear();
156-
157-
auto bootstrap_obj = bootstrap_table->create_object_with_primary_key(Mixed{query_version}, &did_create);
158-
if (progress) {
159-
auto progress_obj = bootstrap_obj.create_and_set_linked_object(m_progress);
160-
progress_obj.set(m_progress_latest_server_version, int64_t(progress->latest_server_version.version));
161-
progress_obj.set(m_progress_latest_server_version_salt, int64_t(progress->latest_server_version.salt));
162-
progress_obj.set(m_progress_download_server_version, int64_t(progress->download.server_version));
163-
progress_obj.set(m_progress_download_client_version,
164-
int64_t(progress->download.last_integrated_client_version));
165-
progress_obj.set(m_progress_upload_server_version,
166-
int64_t(progress->upload.last_integrated_server_version));
167-
progress_obj.set(m_progress_upload_client_version, int64_t(progress->upload.client_version));
168-
}
153+
bool did_create = false;
154+
auto bootstrap_obj = bootstrap_table->create_object_with_primary_key(Mixed{query_version}, &did_create);
155+
if (progress) {
156+
auto progress_obj = bootstrap_obj.create_and_set_linked_object(m_progress);
157+
progress_obj.set(m_progress_latest_server_version, int64_t(progress->latest_server_version.version));
158+
progress_obj.set(m_progress_latest_server_version_salt, int64_t(progress->latest_server_version.salt));
159+
progress_obj.set(m_progress_download_server_version, int64_t(progress->download.server_version));
160+
progress_obj.set(m_progress_download_client_version,
161+
int64_t(progress->download.last_integrated_client_version));
162+
progress_obj.set(m_progress_upload_server_version, int64_t(progress->upload.last_integrated_server_version));
163+
progress_obj.set(m_progress_upload_client_version, int64_t(progress->upload.client_version));
164+
}
169165

170-
auto changesets_list = bootstrap_obj.get_linklist(m_changesets);
171-
for (size_t idx = 0; idx < changesets.size(); ++idx) {
172-
auto cur_changeset = changesets_list.create_and_insert_linked_object(changesets_list.size());
173-
cur_changeset.set(m_changeset_remote_version, int64_t(changesets[idx].remote_version));
174-
cur_changeset.set(m_changeset_last_integrated_client_version,
175-
int64_t(changesets[idx].last_integrated_local_version));
176-
cur_changeset.set(m_changeset_origin_file_ident, int64_t(changesets[idx].origin_file_ident));
177-
cur_changeset.set(m_changeset_origin_timestamp, int64_t(changesets[idx].origin_timestamp));
178-
cur_changeset.set(m_changeset_original_changeset_size, int64_t(changesets[idx].original_changeset_size));
179-
BinaryData compressed_data(compressed_changesets[idx].data(), compressed_changesets[idx].size());
180-
cur_changeset.set(m_changeset_data, compressed_data);
181-
}
166+
auto changesets_list = bootstrap_obj.get_linklist(m_changesets);
167+
for (size_t idx = 0; idx < changesets.size(); ++idx) {
168+
auto cur_changeset = changesets_list.create_and_insert_linked_object(changesets_list.size());
169+
cur_changeset.set(m_changeset_remote_version, int64_t(changesets[idx].remote_version));
170+
cur_changeset.set(m_changeset_last_integrated_client_version,
171+
int64_t(changesets[idx].last_integrated_local_version));
172+
cur_changeset.set(m_changeset_origin_file_ident, int64_t(changesets[idx].origin_file_ident));
173+
cur_changeset.set(m_changeset_origin_timestamp, int64_t(changesets[idx].origin_timestamp));
174+
cur_changeset.set(m_changeset_original_changeset_size, int64_t(changesets[idx].original_changeset_size));
175+
BinaryData compressed_data(compressed_changesets[idx].data(), compressed_changesets[idx].size());
176+
cur_changeset.set(m_changeset_data, compressed_data);
182177
}
183178

184179
tr->commit();
@@ -314,7 +309,6 @@ void PendingBootstrapStore::pop_front_pending(const TransactionRef& tr, size_t c
314309
if (bootstrap_table->is_empty()) {
315310
return;
316311
}
317-
DisableReplication disable_replication(*tr);
318312

319313
// We should only have one pending bootstrap at a time.
320314
REALM_ASSERT(bootstrap_table->size() == 1);

0 commit comments

Comments
 (0)