Skip to content

Commit

Permalink
Fix many tests to run with MEM_ENV and ENCRYPTED_ENV; Introduce a Mem…
Browse files Browse the repository at this point in the history
…oryFileSystem class (facebook#7566)

Summary:
This PR does a few things:

1.  The MockFileSystem class was split out from the MockEnv.  This change would theoretically allow a MockFileSystem to be used by other Environments as well (if we created a means of constructing one).  The MockFileSystem implements a FileSystem in its entirety and does not rely on any Wrapper implementation.

2.  Make the RocksDB test suite work when MOCK_ENV=1 and ENCRYPTED_ENV=1 are set.  To accomplish this, a few things were needed:
- The tests that tried to use the "wrong" environment (Env::Default() instead of env_) were updated
- The MockFileSystem was changed to support the features it was missing or mishandled (such as recursively deleting files in a directory or supporting renaming of a directory).

3.  Updated the test framework to have a ROCKSDB_GTEST_SKIP macro.  This can be used to flag tests that are skipped.  Currently, this defaults to doing nothing (marks the test as SUCCESS) but will mark the tests as SKIPPED when RocksDB is upgraded to a version of gtest that supports this (gtest-1.10).

I have run a full "make check" with MEM_ENV, ENCRYPTED_ENV,  both, and neither under both MacOS and RedHat.  A few tests were disabled/skipped for the MEM/ENCRYPTED cases.  The error_handler_fs_test fails/hangs for MEM_ENV (presumably a timing problem) and I will introduce another PR/issue to track that problem.  (I will also push a change to disable those tests soon).  There is one more test in DBTest2 that also fails which I need to investigate or skip before this PR is merged.

Theoretically, this PR should also allow the test suite to run against an Env loaded from the registry, though I do not have one to try it with currently.

Finally, once this is accepted, it would be nice if there was a CircleCI job to run these tests on a checkin so this effort does not become stale.  I do not know how to do that, so if someone could write that job, it would be appreciated :)

Pull Request resolved: facebook#7566

Reviewed By: zhichao-cao

Differential Revision: D24408980

Pulled By: jay-zhuang

fbshipit-source-id: 911b1554a4d0da06fd51feca0c090a4abdcb4a5f
  • Loading branch information
mrambacher authored and facebook-github-bot committed Oct 27, 2020
1 parent 6134ce6 commit f35f7f2
Show file tree
Hide file tree
Showing 43 changed files with 957 additions and 714 deletions.
26 changes: 26 additions & 0 deletions .circleci/config.yml
Expand Up @@ -108,6 +108,26 @@ jobs:
- run: make V=1 J=32 -j32 check | .circleci/cat_ignore_eagain
- post-steps

build-linux-mem-env:
machine:
image: ubuntu-1604:202007-01
resource_class: 2xlarge
steps:
- pre-steps
- install-gflags
- run: MEM_ENV=1 make V=1 J=32 -j32 check | .circleci/cat_ignore_eagain
- post-steps

build-linux-encrypted-env:
machine:
image: ubuntu-1604:202007-01
resource_class: 2xlarge
steps:
- pre-steps
- install-gflags
- run: ENCRYPTED_ENV=1 make V=1 J=32 -j32 check | .circleci/cat_ignore_eagain
- post-steps

build-linux-shared_lib-alt_namespace-status_checked:
machine:
image: ubuntu-1604:202007-01
Expand Down Expand Up @@ -378,6 +398,12 @@ workflows:
build-linux:
jobs:
- build-linux
build-linux-mem-env:
jobs:
- build-linux-mem-env
build-linux-encrypted-env:
jobs:
- build-linux-encrypted-env
build-linux-shared_lib-alt_namespace-status_checked:
jobs:
- build-linux-shared_lib-alt_namespace-status_checked
Expand Down
21 changes: 11 additions & 10 deletions db/blob/db_blob_basic_test.cc
Expand Up @@ -18,7 +18,7 @@ class DBBlobBasicTest : public DBTestBase {
};

TEST_F(DBBlobBasicTest, GetBlob) {
Options options;
Options options = GetDefaultOptions();
options.enable_blob_files = true;
options.min_blob_size = 0;

Expand All @@ -45,7 +45,7 @@ TEST_F(DBBlobBasicTest, GetBlob) {
}

TEST_F(DBBlobBasicTest, GetBlob_CorruptIndex) {
Options options;
Options options = GetDefaultOptions();
options.enable_blob_files = true;
options.min_blob_size = 0;

Expand All @@ -70,7 +70,7 @@ TEST_F(DBBlobBasicTest, GetBlob_CorruptIndex) {
TEST_F(DBBlobBasicTest, GetBlob_InlinedTTLIndex) {
constexpr uint64_t min_blob_size = 10;

Options options;
Options options = GetDefaultOptions();
options.enable_blob_files = true;
options.min_blob_size = min_blob_size;

Expand Down Expand Up @@ -100,7 +100,7 @@ TEST_F(DBBlobBasicTest, GetBlob_InlinedTTLIndex) {
}

TEST_F(DBBlobBasicTest, GetBlob_IndexWithInvalidFileNumber) {
Options options;
Options options = GetDefaultOptions();
options.enable_blob_files = true;
options.min_blob_size = 0;

Expand Down Expand Up @@ -132,11 +132,12 @@ TEST_F(DBBlobBasicTest, GetBlob_IndexWithInvalidFileNumber) {
class DBBlobBasicIOErrorTest : public DBBlobBasicTest,
public testing::WithParamInterface<std::string> {
protected:
DBBlobBasicIOErrorTest()
: fault_injection_env_(Env::Default()), sync_point_(GetParam()) {}
DBBlobBasicIOErrorTest() : sync_point_(GetParam()) {
fault_injection_env_.reset(new FaultInjectionTestEnv(env_));
}
~DBBlobBasicIOErrorTest() { Close(); }

FaultInjectionTestEnv fault_injection_env_;
std::unique_ptr<FaultInjectionTestEnv> fault_injection_env_;
std::string sync_point_;
};

Expand All @@ -147,7 +148,7 @@ INSTANTIATE_TEST_CASE_P(DBBlobBasicTest, DBBlobBasicIOErrorTest,

TEST_P(DBBlobBasicIOErrorTest, GetBlob_IOError) {
Options options;
options.env = &fault_injection_env_;
options.env = fault_injection_env_.get();
options.enable_blob_files = true;
options.min_blob_size = 0;

Expand All @@ -161,8 +162,8 @@ TEST_P(DBBlobBasicIOErrorTest, GetBlob_IOError) {
ASSERT_OK(Flush());

SyncPoint::GetInstance()->SetCallBack(sync_point_, [this](void* /* arg */) {
fault_injection_env_.SetFilesystemActive(false,
Status::IOError(sync_point_));
fault_injection_env_->SetFilesystemActive(false,
Status::IOError(sync_point_));
});
SyncPoint::GetInstance()->EnableProcessing();

Expand Down
1 change: 1 addition & 0 deletions db/blob/db_blob_index_test.cc
Expand Up @@ -103,6 +103,7 @@ class DBBlobIndexTest : public DBTestBase {

Options GetTestOptions() {
Options options;
options.env = CurrentOptions().env;
options.create_if_missing = true;
options.num_levels = 2;
options.disable_auto_compactions = true;
Expand Down
8 changes: 5 additions & 3 deletions db/corruption_test.cc
Expand Up @@ -184,7 +184,7 @@ class CorruptionTest : public testing::Test {
}
ASSERT_TRUE(!fname.empty()) << filetype;

test::CorruptFile(fname, offset, bytes_to_corrupt);
ASSERT_OK(test::CorruptFile(&env_, fname, offset, bytes_to_corrupt));
}

// corrupts exactly one file at level `level`. if no file found at level,
Expand All @@ -194,7 +194,8 @@ class CorruptionTest : public testing::Test {
db_->GetLiveFilesMetaData(&metadata);
for (const auto& m : metadata) {
if (m.level == level) {
test::CorruptFile(dbname_ + "/" + m.name, offset, bytes_to_corrupt);
ASSERT_OK(test::CorruptFile(&env_, dbname_ + "/" + m.name, offset,
bytes_to_corrupt));
return;
}
}
Expand Down Expand Up @@ -529,7 +530,8 @@ TEST_F(CorruptionTest, RangeDeletionCorrupted) {
ImmutableCFOptions(options_), kRangeDelBlock, &range_del_handle));

ASSERT_OK(TryReopen());
test::CorruptFile(filename, static_cast<int>(range_del_handle.offset()), 1);
ASSERT_OK(test::CorruptFile(&env_, filename,
static_cast<int>(range_del_handle.offset()), 1));
ASSERT_TRUE(TryReopen().IsCorruption());
}

Expand Down
15 changes: 8 additions & 7 deletions db/db_basic_test.cc
Expand Up @@ -12,6 +12,7 @@

#include "db/db_test_util.h"
#include "port/stack_trace.h"
#include "rocksdb/flush_block_policy.h"
#include "rocksdb/merge_operator.h"
#include "rocksdb/perf_context.h"
#include "rocksdb/utilities/debug.h"
Expand Down Expand Up @@ -409,8 +410,7 @@ TEST_F(DBBasicTest, CheckLock) {
Status s = DB::Open(options, dbname_, &localdb);
ASSERT_NOK(s);
#ifdef OS_LINUX
ASSERT_TRUE(s.ToString().find("lock hold by current process") !=
std::string::npos);
ASSERT_TRUE(s.ToString().find("lock ") != std::string::npos);
#endif // OS_LINUX
} while (ChangeCompactOptions());
}
Expand Down Expand Up @@ -1875,6 +1875,7 @@ TEST_F(DBBasicTest, MultiGetStats) {
Options options;
options.create_if_missing = true;
options.disable_auto_compactions = true;
options.env = env_;
options.statistics = ROCKSDB_NAMESPACE::CreateDBStatistics();
BlockBasedTableOptions table_options;
table_options.block_size = 1;
Expand All @@ -1884,7 +1885,7 @@ TEST_F(DBBasicTest, MultiGetStats) {
table_options.no_block_cache = true;
table_options.cache_index_and_filter_blocks = false;
table_options.filter_policy.reset(NewBloomFilterPolicy(10, false));
options.table_factory.reset(new BlockBasedTableFactory(table_options));
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
CreateAndReopenWithCF({"pikachu"}, options);

int total_keys = 2000;
Expand Down Expand Up @@ -2168,7 +2169,7 @@ TEST_F(DBBasicTest, MultiGetIOBufferOverrun) {
table_options.block_size = 16 * 1024;
ASSERT_TRUE(table_options.block_size >
BlockBasedTable::kMultiGetReadStackBufSize);
options.table_factory.reset(new BlockBasedTableFactory(table_options));
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
Reopen(options);

std::string zero_str(128, '\0');
Expand Down Expand Up @@ -2549,7 +2550,7 @@ class DBBasicTestMultiGet : public DBTestBase {
table_options.block_cache_compressed = compressed_cache_;
table_options.flush_block_policy_factory.reset(
new MyFlushBlockPolicyFactory());
options.table_factory.reset(new BlockBasedTableFactory(table_options));
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
if (!compression_enabled_) {
options.compression = kNoCompression;
} else {
Expand Down Expand Up @@ -2976,7 +2977,7 @@ class DeadlineFS : public FileSystemWrapper {
// or to simply delay but return success anyway. The latter mimics the
// behavior of PosixFileSystem, which does not enforce any timeout
explicit DeadlineFS(SpecialEnv* env, bool error_on_delay)
: FileSystemWrapper(FileSystem::Default()),
: FileSystemWrapper(env->GetFileSystem()),
deadline_(std::chrono::microseconds::zero()),
io_timeout_(std::chrono::microseconds::zero()),
env_(env),
Expand Down Expand Up @@ -3151,7 +3152,7 @@ TEST_F(DBBasicTestMultiGetDeadline, MultiGetDeadlineExceeded) {
std::shared_ptr<Cache> cache = NewLRUCache(1048576);
BlockBasedTableOptions table_options;
table_options.block_cache = cache;
options.table_factory.reset(new BlockBasedTableFactory(table_options));
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
options.env = env.get();
SetTimeElapseOnlySleepOnReopen(&options);
ReopenWithColumnFamilies(GetCFNames(), options);
Expand Down
3 changes: 3 additions & 0 deletions db/db_bloom_filter_test.cc
Expand Up @@ -1730,6 +1730,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterUpperBound) {
int using_full_builder = bfp_impl != BFP::kDeprecatedBlock;
Options options;
options.create_if_missing = true;
options.env = CurrentOptions().env;
options.prefix_extractor.reset(NewCappedPrefixTransform(4));
options.disable_auto_compactions = true;
options.statistics = CreateDBStatistics();
Expand Down Expand Up @@ -1860,6 +1861,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterMultipleSST) {
for (auto bfp_impl : BFP::kAllFixedImpls) {
int using_full_builder = bfp_impl != BFP::kDeprecatedBlock;
Options options;
options.env = CurrentOptions().env;
options.create_if_missing = true;
options.prefix_extractor.reset(NewFixedPrefixTransform(1));
options.disable_auto_compactions = true;
Expand Down Expand Up @@ -2052,6 +2054,7 @@ TEST_F(DBBloomFilterTest, DynamicBloomFilterNewColumnFamily) {
TEST_F(DBBloomFilterTest, DynamicBloomFilterOptions) {
for (auto bfp_impl : BFP::kAllFixedImpls) {
Options options;
options.env = CurrentOptions().env;
options.create_if_missing = true;
options.prefix_extractor.reset(NewFixedPrefixTransform(1));
options.disable_auto_compactions = true;
Expand Down
6 changes: 3 additions & 3 deletions db/db_compaction_test.cc
Expand Up @@ -3270,7 +3270,7 @@ TEST_P(DBCompactionTestWithParam, IntraL0Compaction) {
table_options.block_cache = NewLRUCache(64 << 20); // 64MB
table_options.cache_index_and_filter_blocks = true;
table_options.pin_l0_filter_and_index_blocks_in_cache = true;
options.table_factory.reset(new BlockBasedTableFactory(table_options));
options.table_factory.reset(NewBlockBasedTableFactory(table_options));

DestroyAndReopen(options);

Expand Down Expand Up @@ -5023,7 +5023,7 @@ TEST_F(DBCompactionTest, ManualCompactionFailsInReadOnlyMode) {
// is in read-only mode. Verify it now at least returns, despite failing.
const int kNumL0Files = 4;
std::unique_ptr<FaultInjectionTestEnv> mock_env(
new FaultInjectionTestEnv(Env::Default()));
new FaultInjectionTestEnv(env_));
Options opts = CurrentOptions();
opts.disable_auto_compactions = true;
opts.env = mock_env.get();
Expand Down Expand Up @@ -5250,7 +5250,7 @@ TEST_F(DBCompactionTest, ConsistencyFailTest2) {
options.level0_file_num_compaction_trigger = 2;
BlockBasedTableOptions bbto;
bbto.block_size = 400; // small block size
options.table_factory.reset(new BlockBasedTableFactory(bbto));
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
DestroyAndReopen(options);

ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
Expand Down
17 changes: 12 additions & 5 deletions db/db_encryption_test.cc
Expand Up @@ -18,6 +18,13 @@ class DBEncryptionTest : public DBTestBase {
public:
DBEncryptionTest()
: DBTestBase("/db_encryption_test", /*env_do_fsync=*/true) {}
Env* GetTargetEnv() {
if (encrypted_env_ != nullptr) {
return (static_cast<EnvWrapper*>(encrypted_env_))->target();
} else {
return env_;
}
}
};

#ifndef ROCKSDB_LITE
Expand All @@ -34,20 +41,20 @@ TEST_F(DBEncryptionTest, CheckEncrypted) {
auto status = env_->GetChildren(dbname_, &fileNames);
ASSERT_OK(status);

auto defaultEnv = Env::Default();
Env* target = GetTargetEnv();
int hits = 0;
for (auto it = fileNames.begin() ; it != fileNames.end(); ++it) {
if ((*it == "..") || (*it == ".")) {
if ((*it == "..") || (*it == ".") || (*it == "LOCK")) {
continue;
}
auto filePath = dbname_ + "/" + *it;
std::unique_ptr<SequentialFile> seqFile;
auto envOptions = EnvOptions(CurrentOptions());
status = defaultEnv->NewSequentialFile(filePath, &seqFile, envOptions);
status = target->NewSequentialFile(filePath, &seqFile, envOptions);
ASSERT_OK(status);

uint64_t fileSize;
status = defaultEnv->GetFileSize(filePath, &fileSize);
status = target->GetFileSize(filePath, &fileSize);
ASSERT_OK(status);

std::string scratch;
Expand Down Expand Up @@ -85,7 +92,7 @@ TEST_F(DBEncryptionTest, CheckEncrypted) {
}

TEST_F(DBEncryptionTest, ReadEmptyFile) {
auto defaultEnv = Env::Default();
auto defaultEnv = GetTargetEnv();

// create empty file for reading it back in later
auto envOptions = EnvOptions(CurrentOptions());
Expand Down
1 change: 1 addition & 0 deletions db/db_flush_test.cc
Expand Up @@ -450,6 +450,7 @@ TEST_F(DBFlushTest, FlushWithBlob) {
constexpr uint64_t min_blob_size = 10;

Options options;
options.env = CurrentOptions().env;
options.enable_blob_files = true;
options.min_blob_size = min_blob_size;
options.disable_auto_compactions = true;
Expand Down
2 changes: 1 addition & 1 deletion db/db_impl/db_impl.cc
Expand Up @@ -637,7 +637,7 @@ Status DBImpl::CloseHelper() {

if (immutable_db_options_.info_log && own_info_log_) {
Status s = immutable_db_options_.info_log->Close();
if (!s.ok() && ret.ok()) {
if (!s.ok() && !s.IsNotSupported() && ret.ok()) {
ret = s;
}
}
Expand Down
2 changes: 2 additions & 0 deletions db/db_impl/db_secondary_test.cc
Expand Up @@ -883,6 +883,7 @@ TEST_F(DBSecondaryTest, StartFromInconsistent) {
});
SyncPoint::GetInstance()->EnableProcessing();
Options options1;
options1.env = env_;
Status s = TryOpenSecondary(options1);
ASSERT_TRUE(s.IsCorruption());
}
Expand All @@ -894,6 +895,7 @@ TEST_F(DBSecondaryTest, InconsistencyDuringCatchUp) {
ASSERT_OK(Flush());

Options options1;
options1.env = env_;
OpenSecondary(options1);

{
Expand Down
1 change: 1 addition & 0 deletions db/db_memtable_test.cc
Expand Up @@ -316,6 +316,7 @@ TEST_F(DBMemTableTest, InsertWithHint) {
TEST_F(DBMemTableTest, ColumnFamilyId) {
// Verifies MemTableRepFactory is told the right column family id.
Options options;
options.env = CurrentOptions().env;
options.allow_concurrent_memtable_write = false;
options.create_if_missing = true;
options.memtable_factory.reset(new MockMemTableRepFactory());
Expand Down

0 comments on commit f35f7f2

Please sign in to comment.