From ed9acbba0a39b614479db275d2ecd4ee906e93d3 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 20 Apr 2023 10:09:53 -0700 Subject: [PATCH] Rename instructions from "list" to "collection" to reflect how they're actually used now --- src/realm/exec/realm_trawler.cpp | 10 +- src/realm/group.cpp | 10 +- src/realm/impl/transact_log.cpp | 2 +- src/realm/impl/transact_log.hpp | 113 ++++++++------- src/realm/object-store/audit.mm | 10 +- .../object-store/impl/deep_change_checker.hpp | 4 +- .../impl/transact_log_handler.cpp | 24 ++-- src/realm/replication.cpp | 10 +- src/realm/replication.hpp | 14 +- test/test_lang_bind_helper.cpp | 131 ++---------------- 10 files changed, 105 insertions(+), 223 deletions(-) diff --git a/src/realm/exec/realm_trawler.cpp b/src/realm/exec/realm_trawler.cpp index fd10aaef6ce..d19eeab9874 100644 --- a/src/realm/exec/realm_trawler.cpp +++ b/src/realm/exec/realm_trawler.cpp @@ -972,13 +972,13 @@ class HistoryLogger { return true; } - bool list_set(size_t ndx) + bool collection_set(size_t ndx) { std::cout << "Collection set at " << ndx << std::endl; return true; } - bool list_insert(size_t ndx) + bool collection_insert(size_t ndx) { std::cout << "Collection insert at " << ndx << std::endl; return true; @@ -1011,19 +1011,19 @@ class HistoryLogger { return true; } - bool list_move(size_t from_link_ndx, size_t to_link_ndx) + bool collection_move(size_t from_link_ndx, size_t to_link_ndx) { std::cout << "List move from " << from_link_ndx << " to " << to_link_ndx << std::endl; return true; } - bool list_erase(size_t ndx) + bool collection_erase(size_t ndx) { std::cout << "Collection erase at " << ndx << std::endl; return true; } - bool list_clear(size_t old_list_size) + bool collection_clear(size_t old_list_size) { std::cout << "Collection clear. Old size: " << old_list_size << std::endl; return true; diff --git a/src/realm/group.cpp b/src/realm/group.cpp index 6ac86d44111..e9b8ef247a3 100644 --- a/src/realm/group.cpp +++ b/src/realm/group.cpp @@ -1323,12 +1323,12 @@ class Group::TransactAdvancer { return true; // No-op } - bool list_set(size_t) + bool collection_set(size_t) { return true; } - bool list_insert(size_t) + bool collection_insert(size_t) { return true; } @@ -1366,17 +1366,17 @@ class Group::TransactAdvancer { return true; // No-op } - bool list_move(size_t, size_t) noexcept + bool collection_move(size_t, size_t) noexcept { return true; // No-op } - bool list_erase(size_t) noexcept + bool collection_erase(size_t) noexcept { return true; // No-op } - bool list_clear(size_t) noexcept + bool collection_clear(size_t) noexcept { return true; // No-op } diff --git a/src/realm/impl/transact_log.cpp b/src/realm/impl/transact_log.cpp index a3fc5e0ee96..6e42a2f3459 100644 --- a/src/realm/impl/transact_log.cpp +++ b/src/realm/impl/transact_log.cpp @@ -30,7 +30,7 @@ bool TransactLogEncoder::select_table(TableKey key) bool TransactLogEncoder::select_collection(ColKey col_key, ObjKey key) { - append_simple_instr(instr_SelectList, col_key, key.value); // Throws + append_simple_instr(instr_SelectCollection, col_key, key.value); // Throws return true; } diff --git a/src/realm/impl/transact_log.hpp b/src/realm/impl/transact_log.hpp index b07add05440..093181335fd 100644 --- a/src/realm/impl/transact_log.hpp +++ b/src/realm/impl/transact_log.hpp @@ -52,16 +52,16 @@ enum Instruction { instr_RenameColumn = 22, // Rename column in selected descriptor // instr_SetLinkType = 23, Strong/weak (unused from file format 11) - instr_SelectList = 30, - instr_ListInsert = 31, // Insert list entry - instr_ListSet = 32, // Assign to list entry - instr_ListMove = 33, // Move an entry within a link list + instr_SelectCollection = 30, + instr_CollectionInsert = 31, // Insert collection entry + instr_CollectionSet = 32, // Assign to collection entry + instr_CollectionMove = 33, // Move an entry within an ordered collection // instr_ListSwap = 34, Swap two entries within a list (unused from file format 11) - instr_ListErase = 35, // Remove an entry from a list - instr_ListClear = 36, // Remove all entries from a list + instr_CollectionErase = 35, // Remove an entry from a collection + instr_CollectionClear = 36, // Remove all entries from a collection // No longer emitted, but supported for a file shared with an older version. - // Treated identically to the List versions. + // Treated identically to the Collection versions. instr_DictionaryInsert = 37, instr_DictionarySet = 38, instr_DictionaryErase = 39, @@ -131,10 +131,6 @@ class NullInstructionObserver { { return true; } - bool select_link_list(ColKey, ObjKey) - { - return true; - } bool insert_group_level_table(TableKey) { return true; @@ -185,23 +181,23 @@ class NullInstructionObserver { } // Must have collection selected: - bool list_set(size_t) + bool collection_set(size_t) { return true; } - bool list_insert(size_t) + bool collection_insert(size_t) { return true; } - bool list_move(size_t, size_t) + bool collection_move(size_t, size_t) { return true; } - bool list_erase(size_t) + bool collection_erase(size_t) { return true; } - bool list_clear(size_t) + bool collection_clear(size_t) { return true; } @@ -246,11 +242,11 @@ class TransactLogEncoder { // Must have collection selected: bool select_collection(ColKey col_key, ObjKey key); - bool list_set(size_t list_ndx); - bool list_insert(size_t ndx); - bool list_move(size_t from_link_ndx, size_t to_link_ndx); - bool list_erase(size_t list_ndx); - bool list_clear(size_t old_list_size); + bool collection_set(size_t collection_ndx); + bool collection_insert(size_t ndx); + bool collection_move(size_t from_ndx, size_t to_ndx); + bool collection_erase(size_t collection_ndx); + bool collection_clear(size_t old_size); bool typed_link_change(ColKey col, TableKey dest); @@ -628,41 +624,40 @@ inline bool TransactLogEncoder::modify_object(ColKey col_key, ObjKey key) } +/************************************ Collections ***********************************/ -/************************************ List ***********************************/ - -inline bool TransactLogEncoder::list_set(size_t list_ndx) +inline bool TransactLogEncoder::collection_set(size_t ndx) { - append_simple_instr(instr_ListSet, list_ndx); // Throws + append_simple_instr(instr_CollectionSet, ndx); // Throws return true; } -inline bool TransactLogEncoder::list_insert(size_t list_ndx) +inline bool TransactLogEncoder::collection_insert(size_t ndx) { - append_simple_instr(instr_ListInsert, list_ndx); // Throws + append_simple_instr(instr_CollectionInsert, ndx); // Throws return true; } -inline bool TransactLogEncoder::list_move(size_t from_link_ndx, size_t to_link_ndx) +inline bool TransactLogEncoder::collection_move(size_t from_ndx, size_t to_ndx) { // This test is to prevent some fuzzy testing on the server to crash - if (from_link_ndx != to_link_ndx) { - append_simple_instr(instr_ListMove, from_link_ndx, to_link_ndx); // Throws + if (from_ndx != to_ndx) { + append_simple_instr(instr_CollectionMove, from_ndx, to_ndx); // Throws } return true; } -inline bool TransactLogEncoder::list_erase(size_t list_ndx) +inline bool TransactLogEncoder::collection_erase(size_t ndx) { - append_simple_instr(instr_ListErase, list_ndx); // Throws + append_simple_instr(instr_CollectionErase, ndx); // Throws return true; } -inline bool TransactLogEncoder::list_clear(size_t old_list_size) +inline bool TransactLogEncoder::collection_clear(size_t old_size) { - append_simple_instr(instr_ListClear, old_list_size); // Throws + append_simple_instr(instr_CollectionClear, old_size); // Throws return true; } @@ -722,12 +717,6 @@ void TransactLogParser::parse_one(InstructionHandler& handler) case instr_SetDefault: // Should not appear in the transaction log parser_error(); - case instr_ListSet: { - size_t list_ndx = read_int(); - if (!handler.list_set(list_ndx)) // Throws - parser_error(); - return; - } case instr_CreateObject: { ObjKey key(read_int()); // Throws if (!handler.create_object(key)) // Throws @@ -748,40 +737,46 @@ void TransactLogParser::parse_one(InstructionHandler& handler) parser_error(); return; } + case instr_CollectionSet: { + size_t ndx = read_int(); + if (!handler.collection_set(ndx)) // Throws + parser_error(); + return; + } case instr_SetInsert: - case instr_ListInsert: { - size_t list_ndx = read_int(); - if (!handler.list_insert(list_ndx)) // Throws + case instr_CollectionInsert: { + size_t ndx = read_int(); + if (!handler.collection_insert(ndx)) // Throws parser_error(); return; } - case instr_ListMove: { - size_t from_link_ndx = read_int(); // Throws - size_t to_link_ndx = read_int(); // Throws - if (!handler.list_move(from_link_ndx, to_link_ndx)) // Throws + case instr_CollectionMove: { + size_t from_ndx = read_int(); // Throws + size_t to_ndx = read_int(); // Throws + if (!handler.collection_move(from_ndx, to_ndx)) // Throws parser_error(); return; } case instr_SetErase: - case instr_ListErase: { - size_t link_ndx = read_int(); // Throws - if (!handler.list_erase(link_ndx)) // Throws + case instr_CollectionErase: { + size_t ndx = read_int(); // Throws + if (!handler.collection_erase(ndx)) // Throws parser_error(); return; } case instr_SetClear: - case instr_ListClear: { - size_t old_list_size = read_int(); // Throws - if (!handler.list_clear(old_list_size)) // Throws + case instr_CollectionClear: { + size_t old_size = read_int(); // Throws + if (!handler.collection_clear(old_size)) // Throws parser_error(); return; } case instr_DictionaryInsert: { int type = read_int(); // Throws REALM_ASSERT(type == int(type_String)); - read_string(m_string_buffer); // skip key - size_t dict_ndx = read_int(); // Throws - if (!handler.list_insert(dict_ndx)) // Throws + read_string(m_string_buffer); // skip key + size_t dict_ndx = read_int(); // Throws + if (!handler.collection_insert(dict_ndx)) // Throws parser_error(); return; } @@ -790,7 +785,7 @@ void TransactLogParser::parse_one(InstructionHandler& handler) REALM_ASSERT(type == int(type_String)); read_string(m_string_buffer); // skip key size_t dict_ndx = read_int(); // Throws - if (!handler.list_set(dict_ndx)) // Throws + if (!handler.collection_set(dict_ndx)) // Throws parser_error(); return; } @@ -799,11 +794,11 @@ void TransactLogParser::parse_one(InstructionHandler& handler) REALM_ASSERT(type == int(type_String)); read_string(m_string_buffer); // skip key size_t dict_ndx = read_int(); // Throws - if (!handler.list_erase(dict_ndx)) // Throws + if (!handler.collection_erase(dict_ndx)) // Throws parser_error(); return; } - case instr_SelectList: { + case instr_SelectCollection: { ColKey col_key = ColKey(read_int()); // Throws ObjKey key = ObjKey(read_int()); // Throws if (!handler.select_collection(col_key, key)) // Throws diff --git a/src/realm/object-store/audit.mm b/src/realm/object-store/audit.mm index 1ae5734f2db..28a6bd58208 100644 --- a/src/realm/object-store/audit.mm +++ b/src/realm/object-store/audit.mm @@ -292,11 +292,11 @@ bool select_collection(ColKey, ObjKey obj) noexcept // clang-format off // We don't care about fine-grained changes to collections and just do // object-level change tracking, which is covered by select_collection() - bool list_set(size_t) { return true; } - bool list_insert(size_t) { return true; } - bool list_move(size_t, size_t) { return true; } - bool list_erase(size_t) { return true; } - bool list_clear(size_t) { return true; } + bool collection_set(size_t) { return true; } + bool collection_insert(size_t) { return true; } + bool collection_move(size_t, size_t) { return true; } + bool collection_erase(size_t) { return true; } + bool collection_clear(size_t) { return true; } // We don't run this code on arbitrary transactions that could perform schema changes bool insert_group_level_table(TableKey) { unexpected_instruction(); } diff --git a/src/realm/object-store/impl/deep_change_checker.hpp b/src/realm/object-store/impl/deep_change_checker.hpp index 3d069a191cb..5ed89deafa6 100644 --- a/src/realm/object-store/impl/deep_change_checker.hpp +++ b/src/realm/object-store/impl/deep_change_checker.hpp @@ -40,7 +40,7 @@ using ref_type = size_t; namespace _impl { class RealmCoordinator; -struct ListChangeInfo { +struct CollectionChangeInfo { TableKey table_key; ObjKey obj_key; ColKey col_key; @@ -48,7 +48,7 @@ struct ListChangeInfo { }; struct TransactionChangeInfo { - std::vector collections; + std::vector collections; std::unordered_map tables; bool schema_changed; }; diff --git a/src/realm/object-store/impl/transact_log_handler.cpp b/src/realm/object-store/impl/transact_log_handler.cpp index 449670e331d..36f617febbc 100644 --- a/src/realm/object-store/impl/transact_log_handler.cpp +++ b/src/realm/object-store/impl/transact_log_handler.cpp @@ -282,27 +282,27 @@ class TransactLogValidationMixin { { return true; } - bool list_set(size_t) + bool collection_set(size_t) { return true; } - bool list_insert(size_t) + bool collection_insert(size_t) { return true; } - bool list_erase(size_t) + bool collection_erase(size_t) { return true; } - bool list_clear(size_t) + bool collection_clear(size_t) { return true; } - bool list_move(size_t, size_t) + bool collection_move(size_t, size_t) { return true; } - bool list_swap(size_t, size_t) + bool collection_swap(size_t, size_t) { return true; } @@ -376,28 +376,28 @@ class TransactLogObserver : public TransactLogValidationMixin { return true; } - bool list_set(size_t index) + bool collection_set(size_t index) { if (m_active_collection) m_active_collection->modify(index); return true; } - bool list_insert(size_t index) + bool collection_insert(size_t index) { if (m_active_collection) m_active_collection->insert(index); return true; } - bool list_erase(size_t index) + bool collection_erase(size_t index) { if (m_active_collection) m_active_collection->erase(index); return true; } - bool list_swap(size_t index1, size_t index2) + bool collection_swap(size_t index1, size_t index2) { if (m_active_collection) { if (index1 > index2) @@ -409,14 +409,14 @@ class TransactLogObserver : public TransactLogValidationMixin { return true; } - bool list_clear(size_t old_size) + bool collection_clear(size_t old_size) { if (m_active_collection) m_active_collection->clear(old_size); return true; } - bool list_move(size_t from, size_t to) + bool collection_move(size_t from, size_t to) { if (m_active_collection) m_active_collection->move(from, to); diff --git a/src/realm/replication.cpp b/src/realm/replication.cpp index ac4588d43b7..074a78358bb 100644 --- a/src/realm/replication.cpp +++ b/src/realm/replication.cpp @@ -106,29 +106,29 @@ void Replication::do_select_collection(const CollectionBase& list) void Replication::list_clear(const CollectionBase& list) { select_collection(list); // Throws - m_encoder.list_clear(list.size()); // Throws + m_encoder.collection_clear(list.size()); // Throws } void Replication::link_list_nullify(const Lst& list, size_t link_ndx) { select_collection(list); - m_encoder.list_erase(link_ndx); + m_encoder.collection_erase(link_ndx); } void Replication::dictionary_insert(const CollectionBase& dict, size_t ndx, Mixed, Mixed) { select_collection(dict); - m_encoder.list_insert(ndx); + m_encoder.collection_insert(ndx); } void Replication::dictionary_set(const CollectionBase& dict, size_t ndx, Mixed, Mixed) { select_collection(dict); - m_encoder.list_set(ndx); + m_encoder.collection_set(ndx); } void Replication::dictionary_erase(const CollectionBase& dict, size_t ndx, Mixed) { select_collection(dict); - m_encoder.list_erase(ndx); + m_encoder.collection_erase(ndx); } diff --git a/src/realm/replication.hpp b/src/realm/replication.hpp index 371e0a9ab98..f3103207d41 100644 --- a/src/realm/replication.hpp +++ b/src/realm/replication.hpp @@ -554,31 +554,31 @@ inline void Replication::nullify_link(const Table* t, ColKey col_key, ObjKey key inline void Replication::list_set(const CollectionBase& list, size_t list_ndx, Mixed) { select_collection(list); // Throws - m_encoder.list_set(list.translate_index(list_ndx)); // Throws + m_encoder.collection_set(list.translate_index(list_ndx)); // Throws } inline void Replication::list_insert(const CollectionBase& list, size_t list_ndx, Mixed, size_t) { select_collection(list); // Throws - m_encoder.list_insert(list.translate_index(list_ndx)); // Throws + m_encoder.collection_insert(list.translate_index(list_ndx)); // Throws } inline void Replication::set_insert(const CollectionBase& set, size_t set_ndx, Mixed) { select_collection(set); // Throws - m_encoder.list_insert(set_ndx); // Throws + m_encoder.collection_insert(set_ndx); // Throws } inline void Replication::set_erase(const CollectionBase& set, size_t set_ndx, Mixed) { select_collection(set); // Throws - m_encoder.list_erase(set_ndx); // Throws + m_encoder.collection_erase(set_ndx); // Throws } inline void Replication::set_clear(const CollectionBase& set) { select_collection(set); // Throws - m_encoder.list_clear(set.size()); // Throws + m_encoder.collection_clear(set.size()); // Throws } inline void Replication::remove_object(const Table* t, ObjKey key) @@ -590,13 +590,13 @@ inline void Replication::remove_object(const Table* t, ObjKey key) inline void Replication::list_move(const CollectionBase& list, size_t from_link_ndx, size_t to_link_ndx) { select_collection(list); // Throws - m_encoder.list_move(list.translate_index(from_link_ndx), list.translate_index(to_link_ndx)); // Throws + m_encoder.collection_move(list.translate_index(from_link_ndx), list.translate_index(to_link_ndx)); // Throws } inline void Replication::list_erase(const CollectionBase& list, size_t link_ndx) { select_collection(list); // Throws - m_encoder.list_erase(list.translate_index(link_ndx)); // Throws + m_encoder.collection_erase(list.translate_index(link_ndx)); // Throws } inline void Replication::typed_link_change(const Table* source_table, ColKey col, TableKey dest_table) diff --git a/test/test_lang_bind_helper.cpp b/test/test_lang_bind_helper.cpp index 51ea67f33cb..f23ce7e0fec 100644 --- a/test/test_lang_bind_helper.cpp +++ b/test/test_lang_bind_helper.cpp @@ -2017,13 +2017,6 @@ class NoOpTransactionLogParser { return true; } - bool select_link_list(ColKey col_key, ObjKey obj_key, size_t) - { - m_current_linkview_col = col_key; - m_current_linkview_row = obj_key; - return true; - } - bool select_collection(ColKey col_key, ObjKey obj_key) { m_current_linkview_col = col_key; @@ -2031,13 +2024,7 @@ class NoOpTransactionLogParser { return true; } - // subtables not supported - bool select_descriptor(int, const size_t*) - { - return false; - } - - // Default no-op implmentations of all of the mutation instructions + // Default no-op implementations of all of the mutation instructions bool insert_group_level_table(TableKey) { return false; @@ -2054,38 +2041,14 @@ class NoOpTransactionLogParser { { return false; } - bool insert_link_column(ColKey, DataType, StringData, size_t, size_t) - { - return false; - } bool erase_column(ColKey) { return false; } - bool erase_link_column(size_t, size_t, size_t) - { - return false; - } bool rename_column(ColKey) { return false; } - bool add_search_index(size_t) - { - return false; - } - bool remove_search_index(size_t) - { - return false; - } - bool add_primary_key(size_t) - { - return false; - } - bool remove_primary_key() - { - return false; - } bool set_link_type(ColKey) { return false; @@ -2094,43 +2057,27 @@ class NoOpTransactionLogParser { { return false; } - bool add_row_with_key(size_t, size_t, size_t, int64_t) - { - return false; - } bool remove_object(ObjKey) { return false; } - bool swap_rows(size_t, size_t) + bool collection_set(size_t) { return false; } - bool move_row(size_t, size_t) + bool collection_clear(size_t) { return false; } - bool list_set(size_t) + bool collection_erase(size_t) { return false; } - bool list_clear(size_t) + bool collection_insert(size_t) { return false; } - bool list_erase(size_t) - { - return false; - } - bool link_list_nullify(size_t, size_t) - { - return false; - } - bool list_insert(size_t) - { - return false; - } - bool list_move(size_t, size_t) + bool collection_move(size_t, size_t) { return false; } @@ -2138,66 +2085,6 @@ class NoOpTransactionLogParser { { return false; } - bool add_int(size_t, size_t, int_fast64_t) - { - return false; - } - bool set_bool(size_t, size_t, bool, _impl::Instruction) - { - return false; - } - bool set_float(size_t, size_t, float, _impl::Instruction) - { - return false; - } - bool set_double(size_t, size_t, double, _impl::Instruction) - { - return false; - } - bool set_string(size_t, size_t, StringData, _impl::Instruction, size_t) - { - return false; - } - bool set_binary(size_t, size_t, BinaryData, _impl::Instruction) - { - return false; - } - bool set_timestamp(size_t, size_t, Timestamp, _impl::Instruction) - { - return false; - } - bool set_table(size_t, size_t, _impl::Instruction) - { - return false; - } - bool set_mixed(size_t, size_t, const Mixed&, _impl::Instruction) - { - return false; - } - bool set_link(size_t, size_t, size_t, size_t, _impl::Instruction) - { - return false; - } - bool set_null(size_t, size_t, _impl::Instruction, size_t) - { - return false; - } - bool nullify_link(size_t, size_t, size_t) - { - return false; - } - bool insert_substring(size_t, size_t, size_t, StringData) - { - return false; - } - bool erase_substring(size_t, size_t, size_t, size_t) - { - return false; - } - bool optimize_table() - { - return false; - } bool typed_link_change(ColKey, TableKey) { return true; @@ -2327,13 +2214,13 @@ TEST_TYPES(LangBindHelper_AdvanceReadTransact_TransactLog, AdvanceReadTransact, CHECK(o == o1 || o == o0); return true; } - bool select_link_list(ColKey col, ObjKey o) + bool select_collection(ColKey col, ObjKey o) { CHECK(col == link_list_col); CHECK(o == okey); return true; } - bool list_erase(size_t ndx) + bool collection_erase(size_t ndx) { CHECK(ndx == 0); return true; @@ -2375,7 +2262,7 @@ TEST_TYPES(LangBindHelper_AdvanceReadTransact_TransactLog, AdvanceReadTransact, struct : NoOpTransactionLogParser { using NoOpTransactionLogParser::NoOpTransactionLogParser; - bool list_clear(size_t old_size) const + bool collection_clear(size_t old_size) const { CHECK_EQUAL(3, old_size); return true;