From a4e82a3cca04411529d32905731e712d86e40aa8 Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Wed, 7 Apr 2021 10:25:35 -0700 Subject: [PATCH] Fix read-only DB writing to filesystem with write_dbid_to_manifest (#8164) Summary: Fixing another crash test failure in the case of write_dbid_to_manifest=true and reading a backup as read-only DB. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8164 Test Plan: enhanced unit test for backup as read-only DB, ran blackbox_crash_test more with elevated backup_one_in Reviewed By: zhichao-cao Differential Revision: D27622237 Pulled By: pdillinger fbshipit-source-id: 680d0f99ddb465a601737f2e3f2c80efd47384fb --- db/db_impl/db_impl_files.cc | 2 +- utilities/backupable/backupable_db_test.cc | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/db/db_impl/db_impl_files.cc b/db/db_impl/db_impl_files.cc index c71dc8c83..42f9c0683 100644 --- a/db/db_impl/db_impl_files.cc +++ b/db/db_impl/db_impl_files.cc @@ -890,7 +890,7 @@ Status DBImpl::SetDBId(bool read_only) { mutable_cf_options, &edit, &mutex_, nullptr, /* new_descriptor_log */ false); } - } else { + } else if (!read_only) { s = SetIdentityFile(env_, dbname_, db_id_); } return s; diff --git a/utilities/backupable/backupable_db_test.cc b/utilities/backupable/backupable_db_test.cc index 7d24936f5..fdaf4a149 100644 --- a/utilities/backupable/backupable_db_test.cc +++ b/utilities/backupable/backupable_db_test.cc @@ -2616,11 +2616,17 @@ TEST_F(BackupableDBTest, ReadOnlyBackupEngine) { TEST_F(BackupableDBTest, OpenBackupAsReadOnlyDB) { DestroyDB(dbname_, options_); + options_.write_dbid_to_manifest = false; + OpenDBAndBackupEngine(true); FillDB(db_.get(), 0, 100); - ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), true)); + ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), /*flush*/ false)); + + options_.write_dbid_to_manifest = true; // exercises some read-only DB code + CloseAndReopenDB(); + FillDB(db_.get(), 100, 200); - ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), true)); + ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), /*flush*/ false)); db_.reset(); // CloseDB DestroyDB(dbname_, options_); std::vector backup_info;