2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-10-30 01:43:37 +01:00
|
|
|
|
2015-07-20 20:24:54 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2014-10-30 01:43:37 +01:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "rocksdb/cache.h"
|
|
|
|
#include "rocksdb/write_batch.h"
|
2016-06-21 03:01:03 +02:00
|
|
|
#include "rocksdb/write_buffer_manager.h"
|
2014-10-30 01:43:37 +01:00
|
|
|
|
|
|
|
#include "db/column_family.h"
|
2019-05-31 20:52:59 +02:00
|
|
|
#include "db/db_impl/db_impl.h"
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "db/log_writer.h"
|
2014-10-30 01:43:37 +01:00
|
|
|
#include "db/version_set.h"
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "db/wal_manager.h"
|
|
|
|
#include "env/mock_env.h"
|
2019-09-16 19:31:27 +02:00
|
|
|
#include "file/writable_file_writer.h"
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "table/mock_table.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/testharness.h"
|
|
|
|
#include "test_util/testutil.h"
|
2019-05-31 02:39:43 +02:00
|
|
|
#include "util/string_util.h"
|
2014-10-30 01:43:37 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2014-10-30 01:43:37 +01:00
|
|
|
|
|
|
|
// TODO(icanadi) mock out VersionSet
|
|
|
|
// TODO(icanadi) move other WalManager-specific tests from db_test here
|
2015-03-17 22:08:00 +01:00
|
|
|
class WalManagerTest : public testing::Test {
|
2014-10-30 01:43:37 +01:00
|
|
|
public:
|
|
|
|
WalManagerTest()
|
2015-04-14 01:15:05 +02:00
|
|
|
: env_(new MockEnv(Env::Default())),
|
2018-07-14 02:18:39 +02:00
|
|
|
dbname_(test::PerThreadDBPath("wal_manager_test")),
|
2016-09-24 01:34:04 +02:00
|
|
|
db_options_(),
|
2015-03-17 23:04:37 +01:00
|
|
|
table_cache_(NewLRUCache(50000, 16)),
|
2016-06-21 03:01:03 +02:00
|
|
|
write_buffer_manager_(db_options_.db_write_buffer_size),
|
2014-10-30 01:43:37 +01:00
|
|
|
current_log_number_(0) {
|
|
|
|
DestroyDB(dbname_, Options());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init() {
|
|
|
|
ASSERT_OK(env_->CreateDirIfMissing(dbname_));
|
|
|
|
ASSERT_OK(env_->CreateDirIfMissing(ArchivalDirectory(dbname_)));
|
|
|
|
db_options_.db_paths.emplace_back(dbname_,
|
|
|
|
std::numeric_limits<uint64_t>::max());
|
|
|
|
db_options_.wal_dir = dbname_;
|
2015-04-14 01:15:05 +02:00
|
|
|
db_options_.env = env_.get();
|
Introduce a new storage specific Env API (#5761)
Summary:
The current Env API encompasses both storage/file operations, as well as OS related operations. Most of the APIs return a Status, which does not have enough metadata about an error, such as whether its retry-able or not, scope (i.e fault domain) of the error etc., that may be required in order to properly handle a storage error. The file APIs also do not provide enough control over the IO SLA, such as timeout, prioritization, hinting about placement and redundancy etc.
This PR separates out the file/storage APIs from Env into a new FileSystem class. The APIs are updated to return an IOStatus with metadata about the error, as well as to take an IOOptions structure as input in order to allow more control over the IO.
The user can set both ```options.env``` and ```options.file_system``` to specify that RocksDB should use the former for OS related operations and the latter for storage operations. Internally, a ```CompositeEnvWrapper``` has been introduced that inherits from ```Env``` and redirects individual methods to either an ```Env``` implementation or the ```FileSystem``` as appropriate. When options are sanitized during ```DB::Open```, ```options.env``` is replaced with a newly allocated ```CompositeEnvWrapper``` instance if both env and file_system have been specified. This way, the rest of the RocksDB code can continue to function as before.
This PR also ports PosixEnv to the new API by splitting it into two - PosixEnv and PosixFileSystem. PosixEnv is defined as a sub-class of CompositeEnvWrapper, and threading/time functions are overridden with Posix specific implementations in order to avoid an extra level of indirection.
The ```CompositeEnvWrapper``` translates ```IOStatus``` return code to ```Status```, and sets the severity to ```kSoftError``` if the io_status is retryable. The error handling code in RocksDB can then recover the DB automatically.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5761
Differential Revision: D18868376
Pulled By: anand1976
fbshipit-source-id: 39efe18a162ea746fabac6360ff529baba48486f
2019-12-13 23:47:08 +01:00
|
|
|
fs_.reset(new LegacyFileSystemWrapper(env_.get()));
|
|
|
|
db_options_.fs = fs_;
|
2014-10-30 01:43:37 +01:00
|
|
|
|
2020-08-13 02:28:10 +02:00
|
|
|
versions_.reset(
|
|
|
|
new VersionSet(dbname_, &db_options_, env_options_, table_cache_.get(),
|
|
|
|
&write_buffer_manager_, &write_controller_,
|
|
|
|
/*block_cache_tracer=*/nullptr, /*io_tracer=*/nullptr));
|
2014-10-30 01:43:37 +01:00
|
|
|
|
2020-08-13 02:28:10 +02:00
|
|
|
wal_manager_.reset(
|
|
|
|
new WalManager(db_options_, env_options_, nullptr /*IOTracer*/));
|
2014-10-30 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Reopen() {
|
2020-08-13 02:28:10 +02:00
|
|
|
wal_manager_.reset(
|
|
|
|
new WalManager(db_options_, env_options_, nullptr /*IOTracer*/));
|
2014-10-30 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NOT thread safe
|
|
|
|
void Put(const std::string& key, const std::string& value) {
|
|
|
|
assert(current_log_writer_.get() != nullptr);
|
|
|
|
uint64_t seq = versions_->LastSequence() + 1;
|
|
|
|
WriteBatch batch;
|
|
|
|
batch.Put(key, value);
|
|
|
|
WriteBatchInternal::SetSequence(&batch, seq);
|
|
|
|
current_log_writer_->AddRecord(WriteBatchInternal::Contents(&batch));
|
2017-11-11 02:18:01 +01:00
|
|
|
versions_->SetLastAllocatedSequence(seq);
|
2017-12-01 08:39:56 +01:00
|
|
|
versions_->SetLastPublishedSequence(seq);
|
2014-10-30 01:43:37 +01:00
|
|
|
versions_->SetLastSequence(seq);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOT thread safe
|
2018-03-05 22:08:17 +01:00
|
|
|
void RollTheLog(bool /*archived*/) {
|
2014-10-30 01:43:37 +01:00
|
|
|
current_log_number_++;
|
|
|
|
std::string fname = ArchivedLogFileName(dbname_, current_log_number_);
|
2018-11-09 20:17:34 +01:00
|
|
|
std::unique_ptr<WritableFile> file;
|
2014-10-30 01:43:37 +01:00
|
|
|
ASSERT_OK(env_->NewWritableFile(fname, &file, env_options_));
|
Introduce a new storage specific Env API (#5761)
Summary:
The current Env API encompasses both storage/file operations, as well as OS related operations. Most of the APIs return a Status, which does not have enough metadata about an error, such as whether its retry-able or not, scope (i.e fault domain) of the error etc., that may be required in order to properly handle a storage error. The file APIs also do not provide enough control over the IO SLA, such as timeout, prioritization, hinting about placement and redundancy etc.
This PR separates out the file/storage APIs from Env into a new FileSystem class. The APIs are updated to return an IOStatus with metadata about the error, as well as to take an IOOptions structure as input in order to allow more control over the IO.
The user can set both ```options.env``` and ```options.file_system``` to specify that RocksDB should use the former for OS related operations and the latter for storage operations. Internally, a ```CompositeEnvWrapper``` has been introduced that inherits from ```Env``` and redirects individual methods to either an ```Env``` implementation or the ```FileSystem``` as appropriate. When options are sanitized during ```DB::Open```, ```options.env``` is replaced with a newly allocated ```CompositeEnvWrapper``` instance if both env and file_system have been specified. This way, the rest of the RocksDB code can continue to function as before.
This PR also ports PosixEnv to the new API by splitting it into two - PosixEnv and PosixFileSystem. PosixEnv is defined as a sub-class of CompositeEnvWrapper, and threading/time functions are overridden with Posix specific implementations in order to avoid an extra level of indirection.
The ```CompositeEnvWrapper``` translates ```IOStatus``` return code to ```Status```, and sets the severity to ```kSoftError``` if the io_status is retryable. The error handling code in RocksDB can then recover the DB automatically.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5761
Differential Revision: D18868376
Pulled By: anand1976
fbshipit-source-id: 39efe18a162ea746fabac6360ff529baba48486f
2019-12-13 23:47:08 +01:00
|
|
|
std::unique_ptr<WritableFileWriter> file_writer(new WritableFileWriter(
|
|
|
|
NewLegacyWritableFileWrapper(std::move(file)), fname, env_options_));
|
2015-10-08 19:07:15 +02:00
|
|
|
current_log_writer_.reset(new log::Writer(std::move(file_writer), 0, false));
|
2014-10-30 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreateArchiveLogs(int num_logs, int entries_per_log) {
|
|
|
|
for (int i = 1; i <= num_logs; ++i) {
|
|
|
|
RollTheLog(true);
|
|
|
|
for (int k = 0; k < entries_per_log; ++k) {
|
2014-11-25 05:44:49 +01:00
|
|
|
Put(ToString(k), std::string(1024, 'a'));
|
2014-10-30 01:43:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<TransactionLogIterator> OpenTransactionLogIter(
|
|
|
|
const SequenceNumber seq) {
|
2018-11-09 20:17:34 +01:00
|
|
|
std::unique_ptr<TransactionLogIterator> iter;
|
2014-10-30 01:43:37 +01:00
|
|
|
Status status = wal_manager_->GetUpdatesSince(
|
|
|
|
seq, &iter, TransactionLogIterator::ReadOptions(), versions_.get());
|
rocksdb: Replace ASSERT* with EXPECT* in functions that does not return void value
Summary:
gtest does not use exceptions to fail a unit test by design, and `ASSERT*`s are implemented using `return`. As a consequence we cannot use `ASSERT*` in a function that does not return `void` value ([[ https://code.google.com/p/googletest/wiki/AdvancedGuide#Assertion_Placement | 1]]), and have to fix our existing code. This diff does this in a generic way, with no manual changes.
In order to detect all existing `ASSERT*` that are used in functions that doesn't return void value, I change the code to generate compile errors for such cases.
In `util/testharness.h` I defined `EXPECT*` assertions, the same way as `ASSERT*`, and redefined `ASSERT*` to return `void`. Then executed:
```lang=bash
% USE_CLANG=1 make all -j55 -k 2> build.log
% perl -naF: -e 'print "-- -number=".$F[1]." ".$F[0]."\n" if /: error:/' \
build.log | xargs -L 1 perl -spi -e 's/ASSERT/EXPECT/g if $. == $number'
% make format
```
After that I reverted back change to `ASSERT*` in `util/testharness.h`. But preserved introduced `EXPECT*`, which is the same as `ASSERT*`. This will be deleted once switched to gtest.
This diff is independent and contains manual changes only in `util/testharness.h`.
Test Plan:
Make sure all tests are passing.
```lang=bash
% USE_CLANG=1 make check
```
Reviewers: igor, lgalanis, sdong, yufei.zhu, rven, meyering
Reviewed By: meyering
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D33333
2015-03-17 04:52:32 +01:00
|
|
|
EXPECT_OK(status);
|
2015-12-23 21:10:00 +01:00
|
|
|
return iter;
|
2014-10-30 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
2015-04-14 01:15:05 +02:00
|
|
|
std::unique_ptr<MockEnv> env_;
|
2014-10-30 01:43:37 +01:00
|
|
|
std::string dbname_;
|
2016-09-24 01:34:04 +02:00
|
|
|
ImmutableDBOptions db_options_;
|
2014-10-30 01:43:37 +01:00
|
|
|
WriteController write_controller_;
|
|
|
|
EnvOptions env_options_;
|
|
|
|
std::shared_ptr<Cache> table_cache_;
|
2016-06-21 03:01:03 +02:00
|
|
|
WriteBufferManager write_buffer_manager_;
|
2014-10-30 01:43:37 +01:00
|
|
|
std::unique_ptr<VersionSet> versions_;
|
|
|
|
std::unique_ptr<WalManager> wal_manager_;
|
Introduce a new storage specific Env API (#5761)
Summary:
The current Env API encompasses both storage/file operations, as well as OS related operations. Most of the APIs return a Status, which does not have enough metadata about an error, such as whether its retry-able or not, scope (i.e fault domain) of the error etc., that may be required in order to properly handle a storage error. The file APIs also do not provide enough control over the IO SLA, such as timeout, prioritization, hinting about placement and redundancy etc.
This PR separates out the file/storage APIs from Env into a new FileSystem class. The APIs are updated to return an IOStatus with metadata about the error, as well as to take an IOOptions structure as input in order to allow more control over the IO.
The user can set both ```options.env``` and ```options.file_system``` to specify that RocksDB should use the former for OS related operations and the latter for storage operations. Internally, a ```CompositeEnvWrapper``` has been introduced that inherits from ```Env``` and redirects individual methods to either an ```Env``` implementation or the ```FileSystem``` as appropriate. When options are sanitized during ```DB::Open```, ```options.env``` is replaced with a newly allocated ```CompositeEnvWrapper``` instance if both env and file_system have been specified. This way, the rest of the RocksDB code can continue to function as before.
This PR also ports PosixEnv to the new API by splitting it into two - PosixEnv and PosixFileSystem. PosixEnv is defined as a sub-class of CompositeEnvWrapper, and threading/time functions are overridden with Posix specific implementations in order to avoid an extra level of indirection.
The ```CompositeEnvWrapper``` translates ```IOStatus``` return code to ```Status```, and sets the severity to ```kSoftError``` if the io_status is retryable. The error handling code in RocksDB can then recover the DB automatically.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5761
Differential Revision: D18868376
Pulled By: anand1976
fbshipit-source-id: 39efe18a162ea746fabac6360ff529baba48486f
2019-12-13 23:47:08 +01:00
|
|
|
std::shared_ptr<LegacyFileSystemWrapper> fs_;
|
2014-10-30 01:43:37 +01:00
|
|
|
|
|
|
|
std::unique_ptr<log::Writer> current_log_writer_;
|
|
|
|
uint64_t current_log_number_;
|
|
|
|
};
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(WalManagerTest, ReadFirstRecordCache) {
|
2014-10-30 01:43:37 +01:00
|
|
|
Init();
|
|
|
|
std::string path = dbname_ + "/000001.log";
|
2018-11-09 20:17:34 +01:00
|
|
|
std::unique_ptr<WritableFile> file;
|
2014-10-30 01:43:37 +01:00
|
|
|
ASSERT_OK(env_->NewWritableFile(path, &file, EnvOptions()));
|
|
|
|
|
|
|
|
SequenceNumber s;
|
2016-09-15 18:55:02 +02:00
|
|
|
ASSERT_OK(wal_manager_->TEST_ReadFirstLine(path, 1 /* number */, &s));
|
2014-10-30 01:43:37 +01:00
|
|
|
ASSERT_EQ(s, 0U);
|
|
|
|
|
2016-09-15 18:55:02 +02:00
|
|
|
ASSERT_OK(
|
|
|
|
wal_manager_->TEST_ReadFirstRecord(kAliveLogFile, 1 /* number */, &s));
|
2014-10-30 01:43:37 +01:00
|
|
|
ASSERT_EQ(s, 0U);
|
|
|
|
|
Introduce a new storage specific Env API (#5761)
Summary:
The current Env API encompasses both storage/file operations, as well as OS related operations. Most of the APIs return a Status, which does not have enough metadata about an error, such as whether its retry-able or not, scope (i.e fault domain) of the error etc., that may be required in order to properly handle a storage error. The file APIs also do not provide enough control over the IO SLA, such as timeout, prioritization, hinting about placement and redundancy etc.
This PR separates out the file/storage APIs from Env into a new FileSystem class. The APIs are updated to return an IOStatus with metadata about the error, as well as to take an IOOptions structure as input in order to allow more control over the IO.
The user can set both ```options.env``` and ```options.file_system``` to specify that RocksDB should use the former for OS related operations and the latter for storage operations. Internally, a ```CompositeEnvWrapper``` has been introduced that inherits from ```Env``` and redirects individual methods to either an ```Env``` implementation or the ```FileSystem``` as appropriate. When options are sanitized during ```DB::Open```, ```options.env``` is replaced with a newly allocated ```CompositeEnvWrapper``` instance if both env and file_system have been specified. This way, the rest of the RocksDB code can continue to function as before.
This PR also ports PosixEnv to the new API by splitting it into two - PosixEnv and PosixFileSystem. PosixEnv is defined as a sub-class of CompositeEnvWrapper, and threading/time functions are overridden with Posix specific implementations in order to avoid an extra level of indirection.
The ```CompositeEnvWrapper``` translates ```IOStatus``` return code to ```Status```, and sets the severity to ```kSoftError``` if the io_status is retryable. The error handling code in RocksDB can then recover the DB automatically.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5761
Differential Revision: D18868376
Pulled By: anand1976
fbshipit-source-id: 39efe18a162ea746fabac6360ff529baba48486f
2019-12-13 23:47:08 +01:00
|
|
|
std::unique_ptr<WritableFileWriter> file_writer(new WritableFileWriter(
|
|
|
|
NewLegacyWritableFileWrapper(std::move(file)), path, EnvOptions()));
|
2015-10-08 19:07:15 +02:00
|
|
|
log::Writer writer(std::move(file_writer), 1,
|
2016-06-21 03:01:03 +02:00
|
|
|
db_options_.recycle_log_file_num > 0);
|
2014-10-30 01:43:37 +01:00
|
|
|
WriteBatch batch;
|
|
|
|
batch.Put("foo", "bar");
|
|
|
|
WriteBatchInternal::SetSequence(&batch, 10);
|
|
|
|
writer.AddRecord(WriteBatchInternal::Contents(&batch));
|
|
|
|
|
|
|
|
// TODO(icanadi) move SpecialEnv outside of db_test, so we can reuse it here.
|
|
|
|
// Waiting for lei to finish with db_test
|
|
|
|
// env_->count_sequential_reads_ = true;
|
|
|
|
// sequential_read_counter_ sanity test
|
|
|
|
// ASSERT_EQ(env_->sequential_read_counter_.Read(), 0);
|
|
|
|
|
|
|
|
ASSERT_OK(wal_manager_->TEST_ReadFirstRecord(kAliveLogFile, 1, &s));
|
|
|
|
ASSERT_EQ(s, 10U);
|
|
|
|
// did a read
|
|
|
|
// TODO(icanadi) move SpecialEnv outside of db_test, so we can reuse it here
|
|
|
|
// ASSERT_EQ(env_->sequential_read_counter_.Read(), 1);
|
|
|
|
|
|
|
|
ASSERT_OK(wal_manager_->TEST_ReadFirstRecord(kAliveLogFile, 1, &s));
|
|
|
|
ASSERT_EQ(s, 10U);
|
|
|
|
// no new reads since the value is cached
|
|
|
|
// TODO(icanadi) move SpecialEnv outside of db_test, so we can reuse it here
|
|
|
|
// ASSERT_EQ(env_->sequential_read_counter_.Read(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
uint64_t GetLogDirSize(std::string dir_path, Env* env) {
|
|
|
|
uint64_t dir_size = 0;
|
|
|
|
std::vector<std::string> files;
|
|
|
|
env->GetChildren(dir_path, &files);
|
|
|
|
for (auto& f : files) {
|
|
|
|
uint64_t number;
|
|
|
|
FileType type;
|
|
|
|
if (ParseFileName(f, &number, &type) && type == kLogFile) {
|
|
|
|
std::string const file_path = dir_path + "/" + f;
|
|
|
|
uint64_t file_size;
|
|
|
|
env->GetFileSize(file_path, &file_size);
|
|
|
|
dir_size += file_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dir_size;
|
|
|
|
}
|
|
|
|
std::vector<std::uint64_t> ListSpecificFiles(
|
|
|
|
Env* env, const std::string& path, const FileType expected_file_type) {
|
|
|
|
std::vector<std::string> files;
|
|
|
|
std::vector<uint64_t> file_numbers;
|
|
|
|
env->GetChildren(path, &files);
|
|
|
|
uint64_t number;
|
|
|
|
FileType type;
|
|
|
|
for (size_t i = 0; i < files.size(); ++i) {
|
|
|
|
if (ParseFileName(files[i], &number, &type)) {
|
|
|
|
if (type == expected_file_type) {
|
|
|
|
file_numbers.push_back(number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-23 21:10:00 +01:00
|
|
|
return file_numbers;
|
2014-10-30 01:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int CountRecords(TransactionLogIterator* iter) {
|
|
|
|
int count = 0;
|
|
|
|
SequenceNumber lastSequence = 0;
|
|
|
|
BatchResult res;
|
|
|
|
while (iter->Valid()) {
|
|
|
|
res = iter->GetBatch();
|
rocksdb: Replace ASSERT* with EXPECT* in functions that does not return void value
Summary:
gtest does not use exceptions to fail a unit test by design, and `ASSERT*`s are implemented using `return`. As a consequence we cannot use `ASSERT*` in a function that does not return `void` value ([[ https://code.google.com/p/googletest/wiki/AdvancedGuide#Assertion_Placement | 1]]), and have to fix our existing code. This diff does this in a generic way, with no manual changes.
In order to detect all existing `ASSERT*` that are used in functions that doesn't return void value, I change the code to generate compile errors for such cases.
In `util/testharness.h` I defined `EXPECT*` assertions, the same way as `ASSERT*`, and redefined `ASSERT*` to return `void`. Then executed:
```lang=bash
% USE_CLANG=1 make all -j55 -k 2> build.log
% perl -naF: -e 'print "-- -number=".$F[1]." ".$F[0]."\n" if /: error:/' \
build.log | xargs -L 1 perl -spi -e 's/ASSERT/EXPECT/g if $. == $number'
% make format
```
After that I reverted back change to `ASSERT*` in `util/testharness.h`. But preserved introduced `EXPECT*`, which is the same as `ASSERT*`. This will be deleted once switched to gtest.
This diff is independent and contains manual changes only in `util/testharness.h`.
Test Plan:
Make sure all tests are passing.
```lang=bash
% USE_CLANG=1 make check
```
Reviewers: igor, lgalanis, sdong, yufei.zhu, rven, meyering
Reviewed By: meyering
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D33333
2015-03-17 04:52:32 +01:00
|
|
|
EXPECT_TRUE(res.sequence > lastSequence);
|
2014-10-30 01:43:37 +01:00
|
|
|
++count;
|
|
|
|
lastSequence = res.sequence;
|
rocksdb: Replace ASSERT* with EXPECT* in functions that does not return void value
Summary:
gtest does not use exceptions to fail a unit test by design, and `ASSERT*`s are implemented using `return`. As a consequence we cannot use `ASSERT*` in a function that does not return `void` value ([[ https://code.google.com/p/googletest/wiki/AdvancedGuide#Assertion_Placement | 1]]), and have to fix our existing code. This diff does this in a generic way, with no manual changes.
In order to detect all existing `ASSERT*` that are used in functions that doesn't return void value, I change the code to generate compile errors for such cases.
In `util/testharness.h` I defined `EXPECT*` assertions, the same way as `ASSERT*`, and redefined `ASSERT*` to return `void`. Then executed:
```lang=bash
% USE_CLANG=1 make all -j55 -k 2> build.log
% perl -naF: -e 'print "-- -number=".$F[1]." ".$F[0]."\n" if /: error:/' \
build.log | xargs -L 1 perl -spi -e 's/ASSERT/EXPECT/g if $. == $number'
% make format
```
After that I reverted back change to `ASSERT*` in `util/testharness.h`. But preserved introduced `EXPECT*`, which is the same as `ASSERT*`. This will be deleted once switched to gtest.
This diff is independent and contains manual changes only in `util/testharness.h`.
Test Plan:
Make sure all tests are passing.
```lang=bash
% USE_CLANG=1 make check
```
Reviewers: igor, lgalanis, sdong, yufei.zhu, rven, meyering
Reviewed By: meyering
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D33333
2015-03-17 04:52:32 +01:00
|
|
|
EXPECT_OK(iter->status());
|
2014-10-30 01:43:37 +01:00
|
|
|
iter->Next();
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(WalManagerTest, WALArchivalSizeLimit) {
|
2016-09-24 01:34:04 +02:00
|
|
|
db_options_.wal_ttl_seconds = 0;
|
|
|
|
db_options_.wal_size_limit_mb = 1000;
|
2014-10-30 01:43:37 +01:00
|
|
|
Init();
|
|
|
|
|
|
|
|
// TEST : Create WalManager with huge size limit and no ttl.
|
|
|
|
// Create some archived files and call PurgeObsoleteWALFiles().
|
|
|
|
// Count the archived log files that survived.
|
|
|
|
// Assert that all of them did.
|
|
|
|
// Change size limit. Re-open WalManager.
|
2016-09-24 01:34:04 +02:00
|
|
|
// Assert that archive is not greater than wal_size_limit_mb after
|
2014-10-30 01:43:37 +01:00
|
|
|
// PurgeObsoleteWALFiles()
|
|
|
|
// Set ttl and time_to_check_ to small values. Re-open db.
|
|
|
|
// Assert that there are no archived logs left.
|
|
|
|
|
|
|
|
std::string archive_dir = ArchivalDirectory(dbname_);
|
|
|
|
CreateArchiveLogs(20, 5000);
|
|
|
|
|
|
|
|
std::vector<std::uint64_t> log_files =
|
2015-04-14 01:15:05 +02:00
|
|
|
ListSpecificFiles(env_.get(), archive_dir, kLogFile);
|
2014-10-30 01:43:37 +01:00
|
|
|
ASSERT_EQ(log_files.size(), 20U);
|
|
|
|
|
2016-09-24 01:34:04 +02:00
|
|
|
db_options_.wal_size_limit_mb = 8;
|
2014-10-30 01:43:37 +01:00
|
|
|
Reopen();
|
|
|
|
wal_manager_->PurgeObsoleteWALFiles();
|
|
|
|
|
2015-04-14 01:15:05 +02:00
|
|
|
uint64_t archive_size = GetLogDirSize(archive_dir, env_.get());
|
2016-09-24 01:34:04 +02:00
|
|
|
ASSERT_TRUE(archive_size <= db_options_.wal_size_limit_mb * 1024 * 1024);
|
2014-10-30 01:43:37 +01:00
|
|
|
|
2016-09-24 01:34:04 +02:00
|
|
|
db_options_.wal_ttl_seconds = 1;
|
2015-04-14 01:15:05 +02:00
|
|
|
env_->FakeSleepForMicroseconds(2 * 1000 * 1000);
|
2014-10-30 01:43:37 +01:00
|
|
|
Reopen();
|
|
|
|
wal_manager_->PurgeObsoleteWALFiles();
|
|
|
|
|
2015-04-14 01:15:05 +02:00
|
|
|
log_files = ListSpecificFiles(env_.get(), archive_dir, kLogFile);
|
2014-10-30 01:43:37 +01:00
|
|
|
ASSERT_TRUE(log_files.empty());
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(WalManagerTest, WALArchivalTtl) {
|
2016-09-24 01:34:04 +02:00
|
|
|
db_options_.wal_ttl_seconds = 1000;
|
2014-10-30 01:43:37 +01:00
|
|
|
Init();
|
|
|
|
|
|
|
|
// TEST : Create WalManager with a ttl and no size limit.
|
|
|
|
// Create some archived log files and call PurgeObsoleteWALFiles().
|
|
|
|
// Assert that files are not deleted
|
|
|
|
// Reopen db with small ttl.
|
|
|
|
// Assert that all archived logs was removed.
|
|
|
|
|
|
|
|
std::string archive_dir = ArchivalDirectory(dbname_);
|
|
|
|
CreateArchiveLogs(20, 5000);
|
|
|
|
|
|
|
|
std::vector<uint64_t> log_files =
|
2015-04-14 01:15:05 +02:00
|
|
|
ListSpecificFiles(env_.get(), archive_dir, kLogFile);
|
2014-10-30 01:43:37 +01:00
|
|
|
ASSERT_GT(log_files.size(), 0U);
|
|
|
|
|
2016-09-24 01:34:04 +02:00
|
|
|
db_options_.wal_ttl_seconds = 1;
|
2015-04-14 01:15:05 +02:00
|
|
|
env_->FakeSleepForMicroseconds(3 * 1000 * 1000);
|
2014-10-30 01:43:37 +01:00
|
|
|
Reopen();
|
|
|
|
wal_manager_->PurgeObsoleteWALFiles();
|
|
|
|
|
2015-04-14 01:15:05 +02:00
|
|
|
log_files = ListSpecificFiles(env_.get(), archive_dir, kLogFile);
|
2014-10-30 01:43:37 +01:00
|
|
|
ASSERT_TRUE(log_files.empty());
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(WalManagerTest, TransactionLogIteratorMoveOverZeroFiles) {
|
2014-10-30 01:43:37 +01:00
|
|
|
Init();
|
|
|
|
RollTheLog(false);
|
|
|
|
Put("key1", std::string(1024, 'a'));
|
|
|
|
// Create a zero record WAL file.
|
|
|
|
RollTheLog(false);
|
|
|
|
RollTheLog(false);
|
|
|
|
|
|
|
|
Put("key2", std::string(1024, 'a'));
|
|
|
|
|
|
|
|
auto iter = OpenTransactionLogIter(0);
|
|
|
|
ASSERT_EQ(2, CountRecords(iter.get()));
|
|
|
|
}
|
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
TEST_F(WalManagerTest, TransactionLogIteratorJustEmptyFile) {
|
2014-10-30 01:43:37 +01:00
|
|
|
Init();
|
|
|
|
RollTheLog(false);
|
|
|
|
auto iter = OpenTransactionLogIter(0);
|
|
|
|
// Check that an empty iterator is returned
|
|
|
|
ASSERT_TRUE(!iter->Valid());
|
|
|
|
}
|
2019-09-20 21:00:55 +02:00
|
|
|
|
2019-06-19 17:02:21 +02:00
|
|
|
TEST_F(WalManagerTest, TransactionLogIteratorNewFileWhileScanning) {
|
|
|
|
Init();
|
|
|
|
CreateArchiveLogs(2, 100);
|
|
|
|
auto iter = OpenTransactionLogIter(0);
|
|
|
|
CreateArchiveLogs(1, 100);
|
|
|
|
int i = 0;
|
|
|
|
for (; iter->Valid(); iter->Next()) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
ASSERT_EQ(i, 200);
|
|
|
|
// A new log file was added after the iterator was created.
|
|
|
|
// TryAgain indicates a new iterator is needed to fetch the new data
|
|
|
|
ASSERT_TRUE(iter->status().IsTryAgain());
|
2019-09-20 21:00:55 +02:00
|
|
|
|
2019-06-19 17:02:21 +02:00
|
|
|
iter = OpenTransactionLogIter(0);
|
|
|
|
i = 0;
|
|
|
|
for (; iter->Valid(); iter->Next()) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
ASSERT_EQ(i, 300);
|
|
|
|
ASSERT_TRUE(iter->status().ok());
|
|
|
|
}
|
2014-10-30 01:43:37 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2014-10-30 01:43:37 +01:00
|
|
|
|
2015-03-17 22:08:00 +01:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|
2015-07-20 20:24:54 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-04-16 02:19:57 +02:00
|
|
|
int main(int /*argc*/, char** /*argv*/) {
|
2015-07-20 20:24:54 +02:00
|
|
|
fprintf(stderr, "SKIPPED as WalManager is not supported in ROCKSDB_LITE\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !ROCKSDB_LITE
|