Skip to content

Commit

Permalink
Output InRealmHistory when compacting (#7753)
Browse files Browse the repository at this point in the history
This will ensure that the current history version is written, so that
an upgrade will not be required when opening the file.
  • Loading branch information
jedelbo authored May 31, 2024
1 parent 25212bc commit df4a632
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Add a missing file from the bid library to the android blueprint. (PR [#7738](https://github.com/realm/realm-core/pull/7738))
<<<<<<< HEAD
* After compacting, a file upgrade would be triggered. This could cause loss of data if schema mode is SoftResetFile ([#7747](https://github.com/realm/realm-core/issues/7747), since 14.0.0)
=======
* Add missing `REALM_APP_SERVICES` flag to the android blueprint. (PR [#7755](https://github.com/realm/realm-core/pull/7755))
>>>>>>> master
### Breaking changes
* None.
Expand Down
3 changes: 1 addition & 2 deletions src/realm/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,7 @@ auto Group::DefaultTableWriter::write_history(_impl::OutputStream& out) -> Histo
m_group->m_top.get_ref(), version, history_type,
history_schema_version);
REALM_ASSERT(history_type != Replication::hist_None);
if (!m_should_write_history ||
(history_type != Replication::hist_SyncClient && history_type != Replication::hist_SyncServer)) {
if (!m_should_write_history || history_type == Replication::hist_None) {
return info; // Only sync history should be preserved when writing to a new file
}
info.type = history_type;
Expand Down
45 changes: 34 additions & 11 deletions test/test_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,25 +495,48 @@ TEST(Shared_CompactingOnTheFly)
TEST(Shared_ReadAfterCompact)
{
SHARED_GROUP_TEST_PATH(path);
DBRef sg = get_test_db(path);
{
DBRef sg = DB::create(make_in_realm_history(), path);
WriteTransaction wt(sg);
auto table = wt.add_table("table");
table->add_column(type_Int, "col");
table->create_object().set_all(1);
wt.commit();
sg->compact();
}
sg->compact();
auto rt = sg->start_read();
auto table = rt->get_table("table");
for (int i = 2; i < 4; ++i) {
WriteTransaction wt(sg);
wt.get_table("table")->create_object().set_all(i);
wt.commit();
}
{
DBOptions options;
options.allow_file_format_upgrade = false;
DBRef sg = DB::create(make_in_realm_history(), path, options);
auto rt = sg->start_read();
auto table = rt->get_table("table");
for (int i = 2; i < 4; ++i) {
WriteTransaction wt(sg);
wt.get_table("table")->create_object().set_all(i);
wt.commit();
}

CHECK_EQUAL(table->size(), 1);
CHECK_EQUAL(table->get_object(0).get<int64_t>("col"), 1);
CHECK_EQUAL(table->size(), 1);
auto obj = table->get_object(0);
CHECK_EQUAL(obj.get<int64_t>("col"), 1);

struct Parser : _impl::NoOpTransactionLogParser {
bool create_object(ObjKey)
{
nb_objects++;
return true;
}
bool modify_object(ColKey, ObjKey)
{
return true;
}
void parse_complete() {}
int nb_objects = 0;
} parser;

rt->advance_read(&parser);
CHECK_EQUAL(parser.nb_objects, 2);
}
}

TEST(Shared_ReadOverRead)
Expand Down

0 comments on commit df4a632

Please sign in to comment.