Skip to content

Commit e2d8efe

Browse files
committed
revert group::write change + more tests for checking compression
1 parent 2864568 commit e2d8efe

File tree

3 files changed

+101
-14
lines changed

3 files changed

+101
-14
lines changed

src/realm/group.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -1012,10 +1012,6 @@ ref_type Group::DefaultTableWriter::write_names(_impl::OutputStream& out)
10121012
}
10131013
ref_type Group::DefaultTableWriter::write_tables(_impl::OutputStream& out)
10141014
{
1015-
// bool deep = true; // Deep
1016-
// bool only_if_modified = false; // Always
1017-
// bool compress = false; // true;
1018-
// return m_group->m_tables.write(out, deep, only_if_modified, compress); // Throws
10191015
return m_group->typed_write_tables(out);
10201016
}
10211017

@@ -1151,12 +1147,7 @@ void Group::write(std::ostream& out, int file_format_version, TableWriter& table
11511147
// DB to compact the database by writing only the live data
11521148
// into a separate file.
11531149
ref_type names_ref = table_writer.write_names(out_2); // Throws
1154-
1155-
// compress the tables
1156-
out_2.only_modified = false;
1157-
out_2.compress = true;
1158-
ref_type tables_ref = table_writer.typed_write_tables(out_2); // Throws
1159-
out_2.compress = false; // disable compression for other tables/arrays
1150+
ref_type tables_ref = table_writer.write_tables(out_2);
11601151

11611152
SlabAlloc new_alloc;
11621153
new_alloc.attach_empty(); // Throws

src/realm/group.hpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -1133,10 +1133,7 @@ class Group::TableWriter {
11331133
{
11341134
m_group->typed_print(prefix);
11351135
}
1136-
ref_type typed_write_tables(_impl::OutputStream& out)
1137-
{
1138-
return m_group->typed_write_tables(out);
1139-
}
1136+
11401137
virtual ~TableWriter() noexcept {}
11411138

11421139
void set_group(const Group* g)

test/test_group.cpp

+99
Original file line numberDiff line numberDiff line change
@@ -2363,4 +2363,103 @@ TEST(Group_ArrayCompression_Correctness)
23632363
#endif
23642364
}
23652365

2366+
TEST(Group_ArrayCompression_Correctness_Negative)
2367+
{
2368+
GROUP_TEST_PATH(path);
2369+
2370+
// Create group with one list<int> which maps to array_integer
2371+
Group to_disk;
2372+
TableRef table = to_disk.add_table("test");
2373+
auto col_key = table->add_column_list(type_Int, "lint");
2374+
auto obj = table->create_object();
2375+
auto array = obj.get_list<int64_t>(col_key);
2376+
2377+
array.add(-1);
2378+
array.add(-1);
2379+
array.add(-1);
2380+
array.add(-1);
2381+
array.add(std::numeric_limits<int64_t>::max());
2382+
array.add(std::numeric_limits<int64_t>::max());
2383+
2384+
CHECK_EQUAL(array.size(), 6);
2385+
CHECK_EQUAL(array.get_any(0).get_int(), -1);
2386+
CHECK_EQUAL(array.get_any(1).get_int(), -1);
2387+
CHECK_EQUAL(array.get_any(2).get_int(), -1);
2388+
CHECK_EQUAL(array.get_any(3).get_int(), -1);
2389+
CHECK_EQUAL(array.get_any(4).get_int(), std::numeric_limits<int64_t>::max());
2390+
CHECK_EQUAL(array.get_any(5).get_int(), std::numeric_limits<int64_t>::max());
2391+
2392+
// Serialize to disk (compression should happen when the proper leaf array is serialized to disk)
2393+
to_disk.write(path, crypt_key());
2394+
2395+
#ifdef REALM_DEBUG
2396+
to_disk.verify();
2397+
#endif
2398+
2399+
// Load the tables
2400+
Group from_disk(path, crypt_key());
2401+
TableRef read_table = from_disk.get_table("test");
2402+
auto col_key1 = read_table->get_column_key("lint");
2403+
auto obj1 = read_table->get_object(0);
2404+
auto l1 = obj1.get_list<int64_t>(col_key1);
2405+
CHECK(l1.size() == array.size());
2406+
CHECK(*read_table == *table);
2407+
for (size_t i = 0; i < l1.size(); ++i) {
2408+
CHECK_EQUAL(l1.get_any(i), array.get_any(i));
2409+
}
2410+
2411+
#ifdef REALM_DEBUG
2412+
from_disk.verify();
2413+
#endif
2414+
}
2415+
2416+
TEST(Group_ArrayCompression_Correctness_Random_Input)
2417+
{
2418+
GROUP_TEST_PATH(path);
2419+
2420+
// Create group with one list<int> which maps to array_integer
2421+
Group to_disk;
2422+
TableRef table = to_disk.add_table("test");
2423+
auto col_key = table->add_column_list(type_Int, "lint");
2424+
auto obj = table->create_object();
2425+
auto array = obj.get_list<int64_t>(col_key);
2426+
2427+
std::random_device dev;
2428+
std::mt19937 rng(dev());
2429+
constexpr auto min = std::numeric_limits<int64_t>::min();
2430+
constexpr auto max = std::numeric_limits<int64_t>::max();
2431+
std::uniform_int_distribution<std::mt19937::result_type> dist6(static_cast<unsigned int>(min),
2432+
static_cast<unsigned int>(max));
2433+
for (size_t i = 0; i < 1000; ++i) {
2434+
const auto v = dist6(rng);
2435+
array.add(v);
2436+
const auto stored_v = array.get_any(i).get_int();
2437+
CHECK_EQUAL(stored_v, v);
2438+
}
2439+
2440+
// Serialize to disk (compression should happen when the proper leaf array is serialized to disk)
2441+
to_disk.write(path, crypt_key());
2442+
2443+
#ifdef REALM_DEBUG
2444+
to_disk.verify();
2445+
#endif
2446+
2447+
// Load the tables
2448+
Group from_disk(path, crypt_key());
2449+
TableRef read_table = from_disk.get_table("test");
2450+
auto col_key1 = read_table->get_column_key("lint");
2451+
auto obj1 = read_table->get_object(0);
2452+
auto l1 = obj1.get_list<int64_t>(col_key1);
2453+
CHECK(l1.size() == array.size());
2454+
CHECK(*read_table == *table);
2455+
for (size_t i = 0; i < l1.size(); ++i) {
2456+
CHECK_EQUAL(l1.get_any(i), array.get_any(i));
2457+
}
2458+
2459+
#ifdef REALM_DEBUG
2460+
from_disk.verify();
2461+
#endif
2462+
}
2463+
2464+
23662465
#endif // TEST_GROUP

0 commit comments

Comments
 (0)