Skip to content

Commit

Permalink
Revert "Disable replication when writing to the pending bootstrap store"
Browse files Browse the repository at this point in the history
This reverts commit afe0e0f.

DisableReplication actually disables replication on the DB, not the
Transaction, so it's extremely unsafe to use.
  • Loading branch information
tgoyne committed Jun 5, 2024
1 parent 1f78955 commit 95d9c1d
Showing 1 changed file with 31 additions and 37 deletions.
68 changes: 31 additions & 37 deletions src/realm/sync/noinst/pending_bootstrap_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,44 +141,39 @@ void PendingBootstrapStore::add_batch(int64_t query_version, util::Optional<Sync
}

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

{
DisableReplication disable_replication(*tr);
auto bootstrap_table = tr->get_table(m_table);
auto incomplete_bootstraps = Query(bootstrap_table).not_equal(m_query_version, query_version).find_all();
incomplete_bootstraps.for_each([&](Obj obj) {
m_logger.debug(util::LogCategory::changeset, "Clearing incomplete bootstrap for query version %1",
obj.get<int64_t>(m_query_version));
return IteratorControl::AdvanceToNext;
});
incomplete_bootstraps.clear();

auto bootstrap_obj = bootstrap_table->create_object_with_primary_key(Mixed{query_version}, &did_create);
if (progress) {
auto progress_obj = bootstrap_obj.create_and_set_linked_object(m_progress);
progress_obj.set(m_progress_latest_server_version, int64_t(progress->latest_server_version.version));
progress_obj.set(m_progress_latest_server_version_salt, int64_t(progress->latest_server_version.salt));
progress_obj.set(m_progress_download_server_version, int64_t(progress->download.server_version));
progress_obj.set(m_progress_download_client_version,
int64_t(progress->download.last_integrated_client_version));
progress_obj.set(m_progress_upload_server_version,
int64_t(progress->upload.last_integrated_server_version));
progress_obj.set(m_progress_upload_client_version, int64_t(progress->upload.client_version));
}
bool did_create = false;
auto bootstrap_obj = bootstrap_table->create_object_with_primary_key(Mixed{query_version}, &did_create);
if (progress) {
auto progress_obj = bootstrap_obj.create_and_set_linked_object(m_progress);
progress_obj.set(m_progress_latest_server_version, int64_t(progress->latest_server_version.version));
progress_obj.set(m_progress_latest_server_version_salt, int64_t(progress->latest_server_version.salt));
progress_obj.set(m_progress_download_server_version, int64_t(progress->download.server_version));
progress_obj.set(m_progress_download_client_version,
int64_t(progress->download.last_integrated_client_version));
progress_obj.set(m_progress_upload_server_version, int64_t(progress->upload.last_integrated_server_version));
progress_obj.set(m_progress_upload_client_version, int64_t(progress->upload.client_version));
}

auto changesets_list = bootstrap_obj.get_linklist(m_changesets);
for (size_t idx = 0; idx < changesets.size(); ++idx) {
auto cur_changeset = changesets_list.create_and_insert_linked_object(changesets_list.size());
cur_changeset.set(m_changeset_remote_version, int64_t(changesets[idx].remote_version));
cur_changeset.set(m_changeset_last_integrated_client_version,
int64_t(changesets[idx].last_integrated_local_version));
cur_changeset.set(m_changeset_origin_file_ident, int64_t(changesets[idx].origin_file_ident));
cur_changeset.set(m_changeset_origin_timestamp, int64_t(changesets[idx].origin_timestamp));
cur_changeset.set(m_changeset_original_changeset_size, int64_t(changesets[idx].original_changeset_size));
BinaryData compressed_data(compressed_changesets[idx].data(), compressed_changesets[idx].size());
cur_changeset.set(m_changeset_data, compressed_data);
}
auto changesets_list = bootstrap_obj.get_linklist(m_changesets);
for (size_t idx = 0; idx < changesets.size(); ++idx) {
auto cur_changeset = changesets_list.create_and_insert_linked_object(changesets_list.size());
cur_changeset.set(m_changeset_remote_version, int64_t(changesets[idx].remote_version));
cur_changeset.set(m_changeset_last_integrated_client_version,
int64_t(changesets[idx].last_integrated_local_version));
cur_changeset.set(m_changeset_origin_file_ident, int64_t(changesets[idx].origin_file_ident));
cur_changeset.set(m_changeset_origin_timestamp, int64_t(changesets[idx].origin_timestamp));
cur_changeset.set(m_changeset_original_changeset_size, int64_t(changesets[idx].original_changeset_size));
BinaryData compressed_data(compressed_changesets[idx].data(), compressed_changesets[idx].size());
cur_changeset.set(m_changeset_data, compressed_data);
}

tr->commit();
Expand Down Expand Up @@ -314,7 +309,6 @@ void PendingBootstrapStore::pop_front_pending(const TransactionRef& tr, size_t c
if (bootstrap_table->is_empty()) {
return;
}
DisableReplication disable_replication(*tr);

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

0 comments on commit 95d9c1d

Please sign in to comment.