diff --git a/src/realm/group.cpp b/src/realm/group.cpp index e9b8ef247a3..f17db6a62bc 100644 --- a/src/realm/group.cpp +++ b/src/realm/group.cpp @@ -833,29 +833,23 @@ void Group::remove_table(size_t table_ndx, TableKey key) // columns of other tables, however, to do that, we would have to // automatically remove the "offending" link columns from those other // tables. Such a behaviour is deemed too obscure, and we shall therefore - // require that a removed table does not contain foreigh origin backlink + // require that a removed table does not contain foreign origin backlink // columns. if (table->is_cross_table_link_target()) throw CrossTableLinkTarget(table->get_name()); - // There is no easy way for Group::TransactAdvancer to handle removal of - // tables that contain foreign target table link columns, because that - // involves removal of the corresponding backlink columns. For that reason, - // we start by removing all columns, which will generate individual - // replication instructions for each column removal with sufficient - // information for Group::TransactAdvancer to handle them. - size_t n = table->get_column_count(); - Replication* repl = *get_repl(); - if (repl) { - // This will prevent sync instructions for column removals to be generated - repl->prepare_erase_class(key); - } - for (size_t i = n; i > 0; --i) { - ColKey col_key = table->spec_ndx2colkey(i - 1); - table->remove_column(col_key); + { + // We don't want to replicate the individual column removals along the + // way as they're covered by the table removal + Table::DisableReplication dr(*table); + for (size_t i = table->get_column_count(); i > 0; --i) { + ColKey col_key = table->spec_ndx2colkey(i - 1); + table->remove_column(col_key); + } } size_t prior_num_tables = m_tables.size(); + Replication* repl = *get_repl(); if (repl) repl->erase_class(key, prior_num_tables); // Throws diff --git a/src/realm/replication.hpp b/src/realm/replication.hpp index f3103207d41..afe579cfb0f 100644 --- a/src/realm/replication.hpp +++ b/src/realm/replication.hpp @@ -49,7 +49,6 @@ class Replication { virtual void add_class(TableKey table_key, StringData table_name, Table::Type table_type); virtual void add_class_with_primary_key(TableKey, StringData table_name, DataType pk_type, StringData pk_field, bool nullable, Table::Type table_type); - virtual void prepare_erase_class(TableKey table_key); virtual void erase_class(TableKey table_key, size_t num_tables); virtual void rename_class(TableKey table_key, StringData new_name); virtual void insert_column(const Table*, ColKey col_key, DataType type, StringData name, Table* target_table); @@ -494,8 +493,6 @@ inline void Replication::select_collection(const CollectionBase& list) } } -inline void Replication::prepare_erase_class(TableKey) {} - inline void Replication::erase_class(TableKey table_key, size_t) { unselect_all(); diff --git a/src/realm/sync/instruction_replication.cpp b/src/realm/sync/instruction_replication.cpp index ab9c0ad17da..25182975689 100644 --- a/src/realm/sync/instruction_replication.cpp +++ b/src/realm/sync/instruction_replication.cpp @@ -298,12 +298,6 @@ void SyncReplication::create_object_with_primary_key(const Table* table, ObjKey } -void SyncReplication::prepare_erase_class(TableKey table_key) -{ - REALM_ASSERT(!m_table_being_erased); - m_table_being_erased = table_key; -} - void SyncReplication::erase_class(TableKey table_key, size_t num_tables) { Replication::erase_class(table_key, num_tables); @@ -312,15 +306,10 @@ void SyncReplication::erase_class(TableKey table_key, size_t num_tables) bool is_class = m_transaction->table_is_public(table_key); - if (is_class) { - REALM_ASSERT(table_key == m_table_being_erased); - m_table_being_erased = TableKey(); - - if (!m_short_circuit) { - Instruction::EraseTable instr; - instr.table = emit_class_name(table_name); - emit(instr); - } + if (is_class && !m_short_circuit) { + Instruction::EraseTable instr; + instr.table = emit_class_name(table_name); + emit(instr); } m_last_table = nullptr; @@ -385,11 +374,6 @@ void SyncReplication::erase_column(const Table* table, ColKey col_ndx) Replication::erase_column(table, col_ndx); if (select_table(*table)) { - if (table->get_key() == m_table_being_erased) { - // Ignore any EraseColumn instructions generated by Core as part of - // EraseTable. - return; - } // Not allowed to remove PK/OID columns! REALM_ASSERT(col_ndx != table->get_primary_key_column()); Instruction::EraseColumn instr; diff --git a/src/realm/sync/instruction_replication.hpp b/src/realm/sync/instruction_replication.hpp index 5f37c919a07..44963679482 100644 --- a/src/realm/sync/instruction_replication.hpp +++ b/src/realm/sync/instruction_replication.hpp @@ -51,7 +51,6 @@ class SyncReplication : public Replication { void create_object(const Table*, GlobalKey) final; void create_object_with_primary_key(const Table*, ObjKey, Mixed) final; - void prepare_erase_class(TableKey tk) final; void erase_class(TableKey table_key, size_t num_tables) final; void rename_class(TableKey table_key, StringData new_name) final; void insert_column(const Table*, ColKey col_key, DataType type, StringData name, Table* target_table) final; @@ -105,8 +104,6 @@ class SyncReplication : public Replication { ChangesetEncoder m_encoder; Transaction* m_transaction; - TableKey m_table_being_erased; - template void emit(T instruction);