Skip to content

Commit afe0e0f

Browse files
committed
Disable replication when writing to the pending bootstrap store
Nothing observes this table for notifications, so we don't need CT history. This is a pretty minor optimization unless we get a very large number of very small changests from the server.
1 parent 3e376d8 commit afe0e0f

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

src/realm/sync/noinst/pending_bootstrap_store.cpp

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

143143
auto tr = m_db->start_write();
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();
152-
153144
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-
}
165145

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);
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+
}
169+
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+
}
177182
}
178183

179184
tr->commit();
@@ -309,6 +314,7 @@ void PendingBootstrapStore::pop_front_pending(const TransactionRef& tr, size_t c
309314
if (bootstrap_table->is_empty()) {
310315
return;
311316
}
317+
DisableReplication disable_replication(*tr);
312318

313319
// We should only have one pending bootstrap at a time.
314320
REALM_ASSERT(bootstrap_table->size() == 1);
@@ -336,7 +342,7 @@ void PendingBootstrapStore::pop_front_pending(const TransactionRef& tr, size_t c
336342
bootstrap_obj.get<int64_t>(m_query_version), changeset_list.size());
337343
}
338344

339-
m_has_pending = (bootstrap_table->is_empty() == false);
345+
m_has_pending = !bootstrap_table->is_empty();
340346
}
341347

342348
} // namespace realm::sync

0 commit comments

Comments
 (0)