Skip to content

Commit df4a632

Browse files
authored
Output InRealmHistory when compacting (#7753)
This will ensure that the current history version is written, so that an upgrade will not be required when opening the file.
1 parent 25212bc commit df4a632

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
### Fixed
88
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
99
* Add a missing file from the bid library to the android blueprint. (PR [#7738](https://github.com/realm/realm-core/pull/7738))
10+
<<<<<<< HEAD
11+
* 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)
12+
=======
1013
* Add missing `REALM_APP_SERVICES` flag to the android blueprint. (PR [#7755](https://github.com/realm/realm-core/pull/7755))
14+
>>>>>>> master
1115
1216
### Breaking changes
1317
* None.

src/realm/group.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,7 @@ auto Group::DefaultTableWriter::write_history(_impl::OutputStream& out) -> Histo
951951
m_group->m_top.get_ref(), version, history_type,
952952
history_schema_version);
953953
REALM_ASSERT(history_type != Replication::hist_None);
954-
if (!m_should_write_history ||
955-
(history_type != Replication::hist_SyncClient && history_type != Replication::hist_SyncServer)) {
954+
if (!m_should_write_history || history_type == Replication::hist_None) {
956955
return info; // Only sync history should be preserved when writing to a new file
957956
}
958957
info.type = history_type;

test/test_shared.cpp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -495,25 +495,48 @@ TEST(Shared_CompactingOnTheFly)
495495
TEST(Shared_ReadAfterCompact)
496496
{
497497
SHARED_GROUP_TEST_PATH(path);
498-
DBRef sg = get_test_db(path);
499498
{
499+
DBRef sg = DB::create(make_in_realm_history(), path);
500500
WriteTransaction wt(sg);
501501
auto table = wt.add_table("table");
502502
table->add_column(type_Int, "col");
503503
table->create_object().set_all(1);
504504
wt.commit();
505+
sg->compact();
505506
}
506-
sg->compact();
507-
auto rt = sg->start_read();
508-
auto table = rt->get_table("table");
509-
for (int i = 2; i < 4; ++i) {
510-
WriteTransaction wt(sg);
511-
wt.get_table("table")->create_object().set_all(i);
512-
wt.commit();
513-
}
507+
{
508+
DBOptions options;
509+
options.allow_file_format_upgrade = false;
510+
DBRef sg = DB::create(make_in_realm_history(), path, options);
511+
auto rt = sg->start_read();
512+
auto table = rt->get_table("table");
513+
for (int i = 2; i < 4; ++i) {
514+
WriteTransaction wt(sg);
515+
wt.get_table("table")->create_object().set_all(i);
516+
wt.commit();
517+
}
514518

515-
CHECK_EQUAL(table->size(), 1);
516-
CHECK_EQUAL(table->get_object(0).get<int64_t>("col"), 1);
519+
CHECK_EQUAL(table->size(), 1);
520+
auto obj = table->get_object(0);
521+
CHECK_EQUAL(obj.get<int64_t>("col"), 1);
522+
523+
struct Parser : _impl::NoOpTransactionLogParser {
524+
bool create_object(ObjKey)
525+
{
526+
nb_objects++;
527+
return true;
528+
}
529+
bool modify_object(ColKey, ObjKey)
530+
{
531+
return true;
532+
}
533+
void parse_complete() {}
534+
int nb_objects = 0;
535+
} parser;
536+
537+
rt->advance_read(&parser);
538+
CHECK_EQUAL(parser.nb_objects, 2);
539+
}
517540
}
518541

519542
TEST(Shared_ReadOverRead)

0 commit comments

Comments
 (0)