From f7cbfa3acd7b1eb0ec6f9ff4a82fb14c0d058f1b Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Tue, 6 Apr 2021 23:30:55 -0700 Subject: [PATCH] Fix crash test with backup as read-only DB (#8161) Summary: Forgot to re-test crash test after adding read-only filesystem enforcement to https://github.com/facebook/rocksdb/issues/8142. The problem is ReadOnlyFileSystem would reject CreateDirIfMissing whenever DBOptions::create_if_missing=true. The fix that is better for users is to allow CreateDirIfMissing in ReadOnlyFileSystem if the directory exists, so that they don't cause a failure on using create_if_missing with opening backups as read-only DBs. Added this option test to the unit test (in addition to being in the crash test). Also fixed a couple of lints. And some better messaging from 'make format' so that when you run it with uncommitted changes, it's clear that it's only checking the uncommitted changes. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8161 Test Plan: local blackbox_crash_test with amplified backup_one_in Reviewed By: ajkr Differential Revision: D27614409 Pulled By: pdillinger fbshipit-source-id: 63ccb626c7e34c200d61c6bca2a8f60da9015179 Signed-off-by: Changlong Chen --- env/fs_readonly.h | 17 ++++++++++++----- env/fs_remap.h | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/env/fs_readonly.h b/env/fs_readonly.h index 77ea1ded8d..89875106ee 100644 --- a/env/fs_readonly.h +++ b/env/fs_readonly.h @@ -23,7 +23,7 @@ class ReadOnlyFileSystem : public FileSystemWrapper { } public: - ReadOnlyFileSystem(const std::shared_ptr& base) + explicit ReadOnlyFileSystem(const std::shared_ptr& base) : FileSystemWrapper(base) {} IOStatus NewWritableFile(const std::string& /*fname*/, @@ -61,10 +61,17 @@ class ReadOnlyFileSystem : public FileSystemWrapper { IODebugContext* /*dbg*/) override { return FailReadOnly(); } - IOStatus CreateDirIfMissing(const std::string& /*dirname*/, - const IOOptions& /*options*/, - IODebugContext* /*dbg*/) override { - return FailReadOnly(); + IOStatus CreateDirIfMissing(const std::string& dirname, + const IOOptions& options, + IODebugContext* dbg) override { + // Allow if dir already exists + bool is_dir = false; + IOStatus s = IsDirectory(dirname, options, &is_dir, dbg); + if (s.ok() && is_dir) { + return s; + } else { + return FailReadOnly(); + } } IOStatus DeleteDir(const std::string& /*dirname*/, const IOOptions& /*options*/, diff --git a/env/fs_remap.h b/env/fs_remap.h index f95ff9de29..4975822f66 100644 --- a/env/fs_remap.h +++ b/env/fs_remap.h @@ -20,7 +20,7 @@ namespace ROCKSDB_NAMESPACE { // guarantees. class RemapFileSystem : public FileSystemWrapper { public: - RemapFileSystem(const std::shared_ptr& base); + explicit RemapFileSystem(const std::shared_ptr& base); protected: // Returns status and mapped-to path in the wrapped filesystem.