Skip to content

Commit

Permalink
adjust comments and compress composite array
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-cab committed Mar 22, 2024
1 parent d8b9834 commit 45402aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/realm/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,9 +1666,10 @@ ref_type Cluster::typed_write(ref_type ref, _impl::ArrayWriterBase& out, const T
payload_idx_size
};
Note:
1. entry at index 0 is the composite array (where the actual data is stored)
1. entry at index 0 is the composite array (the main information about the data is stored, it can
either be a small int <32 bit or a ref to the array where the actual data is stored).
2. entries at indices 1 and 2 can be compressed (they are integers) .. but we gotta be careful, since
they can also contain floats, doubles, timestamps
they can also contain floats, doubles, timestamps. Controlling the col_type should prevent this.
3. entry at index 3 is for strings and binary data (no compression for now)
4. entry at index 4 is actually storing refs to collections,
They can only be BPlusTree<int, Mixed> or BPlusTree<string, Mixed>.
Expand All @@ -1677,22 +1678,24 @@ ref_type Cluster::typed_write(ref_type ref, _impl::ArrayWriterBase& out, const T
for (size_t i = 0; i < sz; ++i) {
auto rot = leaf.get_as_ref_or_tagged(i);
if (rot.is_ref() && rot.get_as_ref()) {
if (i == 1 || i == 2) {
if (i < 3) { // composite, int, and pair_int
// integer arrays
written_leaf.set_as_ref(
i, Array::write(rot.get_as_ref(), m_alloc, out, only_modified, true));
}
else if (i == 4) {
// collection in mixed
else if (i == 4) { // collection in mixed
// we need to differenciate between a mixed that contains
// an objlink and a mixed that contains a collection.
// This flag is used to differentiate this while descending the
// cluster.
const bool collection_in_mixed = true;
const bool compress = true;
const auto new_ref =
BPlusTreeBase::typed_write(rot.get_as_ref(), out, m_alloc, col_type, deep,
only_modified, compress, collection_in_mixed);
written_leaf.set_as_ref(i, new_ref);
}
else if (i == 5) {
// unique keys associated to collections in mixed
else if (i == 5) { // unique keys associated to collections in mixed
written_leaf.set_as_ref(
i, Array::write(rot.get_as_ref(), m_alloc, out, only_modified, true));
}
Expand All @@ -1703,8 +1706,7 @@ ref_type Cluster::typed_write(ref_type ref, _impl::ArrayWriterBase& out, const T
}
}
else {
// what about integers that are max 32 bits and we store stuff straight in the composite
// array. we are not compressing those.
// all the other data types that we don't compress
written_leaf.set(i, rot);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ TEST(List_AggOps)
test_lists_numeric_agg<Decimal128>(test_context, sg, type_Decimal, Decimal128(realm::null()), true);
}

ONLY(Test_Write_List_Nested_In_Mixed)
TEST(Test_Write_List_Nested_In_Mixed)
{
SHARED_GROUP_TEST_PATH(path);
std::string message;
Expand Down

0 comments on commit 45402aa

Please sign in to comment.