Skip to content

Commit

Permalink
Fix reading CT history from synchronized Realms in trawler
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Jun 4, 2024
1 parent 9affcbc commit 5d5e26d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
### Internals
* Removed references to `stitch_` fields in access tokens in sync unit tests ([PR #7769](https://github.com/realm/realm-core/pull/7769)).
* Added back iOS simulator testing to evergreen after Jenkins went away ([PR #7758](https://github.com/realm/realm-core/pull/7758)).
* `realm-trawler -c` did not work on Realm using SyncClient history ([PR #7734](https://github.com/realm/realm-core/pull/7734)).

----------------------------------------------

Expand Down
63 changes: 38 additions & 25 deletions src/realm/exec/realm_trawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void consolidate_lists(std::vector<T>& list, std::vector<T>& list2)
for (auto it = list.begin() + 1; it != list.end(); ++it) {
if (prev->start + prev->length != it->start) {
if (prev->start + prev->length > it->start) {
std::cout << "*** Overlapping entries:" << std::endl;
std::cout << "*** Overlapping entries:\n";
std::cout << std::hex;
std::cout << " 0x" << prev->start << "..0x" << prev->start + prev->length << std::endl;
std::cout << " 0x" << it->start << "..0x" << it->start + it->length << std::endl;
Expand Down Expand Up @@ -455,7 +455,16 @@ class Group : public Array {
for (size_t n = 0; n < m_history.size(); n++) {
ref = m_history.get_ref(n);
Node node(m_alloc, ref);
ret.emplace_back(node.data(), node.size());
if (!node.has_refs()) {
ret.emplace_back(node.data(), node.size());
continue;
}

Array array(m_alloc, ref);
for (size_t j = 0; j < array.size(); ++j) {
Node node(m_alloc, array.get_ref(j));
ret.emplace_back(node.data(), node.size());
}
}
}
return ret;
Expand All @@ -473,7 +482,7 @@ class Group : public Array {
if (m_evacuation_info.valid()) {
ostr << "Evacuation limit: " << size_t(m_evacuation_info.get_val(0));
if (m_evacuation_info.get_val(1)) {
ostr << " Scan done" << std::endl;
ostr << " Scan done\n";
}
else {
ostr << " Progress: [";
Expand All @@ -482,7 +491,7 @@ class Group : public Array {
ostr << ',';
ostr << m_evacuation_info.get_val(i);
}
ostr << "]" << std::endl;
ostr << "]\n";
}
}
}
Expand Down Expand Up @@ -588,14 +597,14 @@ std::ostream& operator<<(std::ostream& ostr, const Group& g)
}
}
else {
ostr << "*** Invalid group ***" << std::endl;
ostr << "*** Invalid group ***\n";
}
return ostr;
}

void Table::print_columns(const Group& group) const
{
std::cout << " <" << m_table_type << ">" << std::endl;
std::cout << " <" << m_table_type << ">\n";
for (unsigned i = 0; i < m_column_names.size(); i++) {
auto type = realm::ColumnType(m_column_types.get_val(i) & 0xFFFF);
auto attr = realm::ColumnAttr(m_column_attributes.get_val(i));
Expand Down Expand Up @@ -646,7 +655,7 @@ void Table::print_columns(const Group& group) const
void Group::print_schema() const
{
if (valid()) {
std::cout << "Tables: " << std::endl;
std::cout << "Tables: \n";

for (unsigned i = 0; i < get_nb_tables(); i++) {
Table* table = get_table(i);
Expand Down Expand Up @@ -808,7 +817,7 @@ void RealmFile::node_scan()
}
uint64_t bad_ref = 0;
if (free_list.empty()) {
std::cout << "*** No free list - results may be unreliable ***" << std::endl;
std::cout << "*** No free list - results may be unreliable ***\n";
}
std::cout << std::hex;
while (ref < end) {
Expand Down Expand Up @@ -847,7 +856,7 @@ void RealmFile::node_scan()
<< "Start: 0x" << bad_ref << "..0x" << end << std::endl;
}
std::cout << std::dec;
std::cout << "Allocated space:" << std::endl;
std::cout << "Allocated space:\n";
for (auto s : sizes) {
std::cout << " Size: " << s.first << " count: " << s.second << std::endl;
}
Expand All @@ -870,7 +879,7 @@ void RealmFile::memory_leaks()
consolidate_lists(nodes, free_blocks);
auto it = nodes.begin();
if (nodes.size() > 1) {
std::cout << "Memory leaked:" << std::endl;
std::cout << "Memory leaked:\n";
auto prev = it;
++it;
while (it != nodes.end()) {
Expand All @@ -882,7 +891,7 @@ void RealmFile::memory_leaks()
}
else {
REALM_ASSERT(it->length == m_group->get_file_size());
std::cout << "No memory leaks" << std::endl;
std::cout << "No memory leaks\n";
}
}
}
Expand All @@ -891,7 +900,7 @@ void RealmFile::free_list_info() const
{
std::map<uint64_t, unsigned> free_sizes;
std::map<uint64_t, unsigned> pinned_sizes;
std::cout << "Free space:" << std::endl;
std::cout << "Free space:\n";
auto free_list = m_group->get_free_list();
uint64_t pinned_free_list_size = 0;
uint64_t total_free_list_size = 0;
Expand All @@ -911,11 +920,11 @@ void RealmFile::free_list_info() const

++it;
}
std::cout << "Free space sizes:" << std::endl;
std::cout << "Free space sizes:\n";
for (auto s : free_sizes) {
std::cout << " Size: " << s.first << " count: " << s.second << std::endl;
}
std::cout << "Pinned sizes:" << std::endl;
std::cout << "Pinned sizes:\n";