Skip to content

Commit

Permalink
Fix crash test with backup as read-only DB (facebook#8161)
Browse files Browse the repository at this point in the history
Summary:
Forgot to re-test crash test after adding read-only filesystem
enforcement to facebook#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: facebook#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
  • Loading branch information
pdillinger authored and facebook-github-bot committed Apr 7, 2021
1 parent 6db3af1 commit 35af043
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions build_tools/format-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ then
FORMAT_UPSTREAM_MERGE_BASE="$(git merge-base "$FORMAT_UPSTREAM" HEAD)"
# Get the differences
diffs=$(git diff -U0 "$FORMAT_UPSTREAM_MERGE_BASE" | $CLANG_FORMAT_DIFF -p 1)
echo "Checking format of changes not yet in $FORMAT_UPSTREAM..."
else
# Check the format of uncommitted lines,
diffs=$(git diff -U0 HEAD | $CLANG_FORMAT_DIFF -p 1)
echo "Checking format of uncommitted changes..."
fi

if [ -z "$diffs" ]
Expand Down
17 changes: 12 additions & 5 deletions env/fs_readonly.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ReadOnlyFileSystem : public FileSystemWrapper {
}

public:
ReadOnlyFileSystem(const std::shared_ptr<FileSystem>& base)
explicit ReadOnlyFileSystem(const std::shared_ptr<FileSystem>& base)
: FileSystemWrapper(base) {}

IOStatus NewWritableFile(const std::string& /*fname*/,
Expand Down Expand Up @@ -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*/,
Expand Down
2 changes: 1 addition & 1 deletion env/fs_remap.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ROCKSDB_NAMESPACE {
// guarantees.
class RemapFileSystem : public FileSystemWrapper {
public:
RemapFileSystem(const std::shared_ptr<FileSystem>& base);
explicit RemapFileSystem(const std::shared_ptr<FileSystem>& base);

protected:
// Returns status and mapped-to path in the wrapped filesystem.
Expand Down
1 change: 1 addition & 0 deletions utilities/backupable/backupable_db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,7 @@ TEST_F(BackupableDBTest, OpenBackupAsReadOnlyDB) {
backup_engine_->GetBackupInfo(&backup_info, /*with file details*/ true);
ASSERT_EQ(backup_info.size(), 2);
CloseBackupEngine();
opts.create_if_missing = true; // check also OK (though pointless)
opts.env = backup_info[1].env_for_open.get();
name = backup_info[1].name_for_open;
// Note: keeping backup_info[1] alive
Expand Down

0 comments on commit 35af043

Please sign in to comment.