Skip to content

Commit

Permalink
Rename instructions from "list" to "collection" to reflect how they'r…
Browse files Browse the repository at this point in the history
…e actually used now
  • Loading branch information
tgoyne committed Apr 27, 2023
1 parent 8713b66 commit ed9acbb
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 223 deletions.
10 changes: 5 additions & 5 deletions src/realm/exec/realm_trawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/realm/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/realm/impl/transact_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
113 changes: 54 additions & 59 deletions src/realm/impl/transact_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -131,10 +131,6 @@ class NullInstructionObserver {
{
return true;
}
bool select_link_list(ColKey, ObjKey)
{
return true;
}
bool insert_group_level_table(TableKey)
{
return true;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<size_t>();
if (!handler.list_set(list_ndx)) // Throws
parser_error();
return;
}
case instr_CreateObject: {
ObjKey key(read_int<int64_t>()); // Throws
if (!handler.create_object(key)) // Throws
Expand All @@ -748,40 +737,46 @@ void TransactLogParser::parse_one(InstructionHandler& handler)
parser_error();
return;
}
case instr_CollectionSet: {
size_t ndx = read_int<size_t>();
if (!handler.collection_set(ndx)) // Throws
parser_error();
return;
}
case instr_SetInsert:
case instr_ListInsert: {
size_t list_ndx = read_int<size_t>();
if (!handler.list_insert(list_ndx)) // Throws
case instr_CollectionInsert: {
size_t ndx = read_int<size_t>();
if (!handler.collection_insert(ndx)) // Throws
parser_error();
return;
}
case instr_ListMove: {
size_t from_link_ndx = read_int<size_t>(); // Throws
size_t to_link_ndx = read_int<size_t>(); // Throws
if (!handler.list_move(from_link_ndx, to_link_ndx)) // Throws
case instr_CollectionMove: {
size_t from_ndx = read_int<size_t>(); // Throws
size_t to_ndx = read_int<size_t>(); // 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<size_t>(); // Throws
if (!handler.list_erase(link_ndx)) // Throws
case instr_CollectionErase: {
size_t ndx = read_int<size_t>(); // Throws
if (!handler.collection_erase(ndx)) // Throws
parser_error();
return;
}
case instr_SetClear:
case instr_ListClear: {
size_t old_list_size = read_int<size_t>(); // Throws
if (!handler.list_clear(old_list_size)) // Throws
case instr_CollectionClear: {
size_t old_size = read_int<size_t>(); // Throws
if (!handler.collection_clear(old_size)) // Throws
parser_error();
return;
}
case instr_DictionaryInsert: {
int type = read_int<int>(); // Throws
REALM_ASSERT(type == int(type_String));
read_string(m_string_buffer); // skip key
size_t dict_ndx = read_int<size_t>(); // Throws
if (!handler.list_insert(dict_ndx)) // Throws
read_string(m_string_buffer); // skip key
size_t dict_ndx = read_int<size_t>(); // Throws
if (!handler.collection_insert(dict_ndx)) // Throws
parser_error();
return;
}
Expand All @@ -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<size_t>(); // Throws
if (!handler.list_set(dict_ndx)) // Throws
if (!handler.collection_set(dict_ndx)) // Throws
parser_error();
return;
}
Expand All @@ -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<size_t>(); // 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<int64_t>()); // Throws
ObjKey key = ObjKey(read_int<int64_t>()); // Throws
if (!handler.select_collection(col_key, key)) // Throws
Expand Down
10 changes: 5 additions & 5 deletions src/realm/object-store/audit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
4 changes: 2 additions & 2 deletions src/realm/object-store/impl/deep_change_checker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ using ref_type = size_t;
namespace _impl {
class RealmCoordinator;

struct ListChangeInfo {
struct CollectionChangeInfo {
TableKey table_key;
ObjKey obj_key;
ColKey col_key;
CollectionChangeBuilder* changes;
};

struct TransactionChangeInfo {
std::vector<ListChangeInfo> collections;
std::vector<CollectionChangeInfo> collections;
std::unordered_map<TableKey, ObjectChangeSet> tables;
bool schema_changed;
};
Expand Down
Loading

0 comments on commit ed9acbb

Please sign in to comment.