Skip to content

Commit

Permalink
Honor disable_sync_to_disk() for encrypted Realms
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed May 29, 2024
1 parent 274dc32 commit 275822a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
### Internals
* Work around a bug in VC++ that resulted in runtime errors when running the tests in a debug build (#[7741](https://github.com/realm/realm-core/issues/7741)).
* `File::Map`'s move constructor and assignment operator left `m_fd` unchanged, which appears to have never actually resulted in problems with how it was used ([PR #7698](https://github.com/realm/realm-core/pull/7698)).
* `disable_sync_to_disk()` was not fully honored for encrypted Realms and they would be partially synced ([PR #7698](https://github.com/realm/realm-core/pull/7698)).

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

Expand Down
2 changes: 1 addition & 1 deletion src/realm/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,7 @@ void DB::low_level_commit(uint_fast64_t new_version, Transaction& transaction, b
m_new_commit_available.notify_all();
}
auto t2 = std::chrono::steady_clock::now();
if (m_logger) {
if (m_logger && m_logger->would_log(util::Logger::Level::debug)) {
std::string to_disk_str = commit_to_disk ? util::format(" ref %1", new_top_ref) : " (no commit to disk)";
m_logger->log(util::LogCategory::transaction, util::Logger::Level::debug, "Commit of size %1 done in %2 us%3",
commit_size, std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count(),
Expand Down
14 changes: 6 additions & 8 deletions src/realm/group_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ bool WriteWindowMgr::MapWindow::extends_to_match(util::File& f, ref_type start_r
if (aligned_ref != m_base_ref)
return false;
size_t window_size = get_window_size(f, start_ref, size);
m_map.sync();
m_map.unmap();
m_map.map(f, File::access_ReadWrite, window_size, m_base_ref);
return true;
Expand All @@ -170,11 +169,7 @@ WriteWindowMgr::MapWindow::MapWindow(size_t alignment, util::File& f, ref_type s
#endif
}

WriteWindowMgr::MapWindow::~MapWindow()
{
m_map.sync();
m_map.unmap();
}
WriteWindowMgr::MapWindow::~MapWindow() = default;

void WriteWindowMgr::MapWindow::flush()
{
Expand Down Expand Up @@ -310,8 +305,11 @@ void GroupWriter::sync_according_to_durability()
switch (m_durability) {
case Durability::Full:
case Durability::Unsafe:
m_window_mgr.sync_all_mappings();
break;
if (!get_disable_sync_to_disk()) {
m_window_mgr.sync_all_mappings();
break;
}
[[fallthrough]];
case Durability::MemOnly:
m_window_mgr.flush_all_mappings();
}
Expand Down
2 changes: 1 addition & 1 deletion src/realm/util/encrypted_file_mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class EncryptedFileMapping {

// Encrypt all dirty blocks, push them to shared cache and mark them read-only
// Does not call fsync
void flush(bool skip_validate) noexcept REQUIRES(!m_file.mutex);
void flush(bool skip_validate = false) noexcept REQUIRES(!m_file.mutex);

// Flush and then sync the image of this file in shared cache to disk.
void sync() noexcept REQUIRES(!m_file.mutex);
Expand Down
3 changes: 3 additions & 0 deletions src/realm/util/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,9 @@ void File::MapBase::unmap() noexcept
return;
REALM_ASSERT(m_reservation_size);
#if REALM_ENABLE_ENCRYPTION
if (m_encrypted_mapping) {
m_encrypted_mapping->flush();
}
m_encrypted_mapping = nullptr;
#endif
munmap(m_addr, m_reservation_size);
Expand Down

0 comments on commit 275822a

Please sign in to comment.