Update all unique/shared_ptr instances to be qualified with namespace std (#4638)

Summary:
Ran the following commands to recursively change all the files under RocksDB:
```
find . -type f -name "*.cc" -exec sed -i 's/ unique_ptr/ std::unique_ptr/g' {} +
find . -type f -name "*.cc" -exec sed -i 's/<unique_ptr/<std::unique_ptr/g' {} +
find . -type f -name "*.cc" -exec sed -i 's/ shared_ptr/ std::shared_ptr/g' {} +
find . -type f -name "*.cc" -exec sed -i 's/<shared_ptr/<std::shared_ptr/g' {} +
```
Running `make format` updated some formatting on the files touched.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4638

Differential Revision: D12934992

Pulled By: sagar0

fbshipit-source-id: 45a15d23c230cdd64c08f9c0243e5183934338a8
This commit is contained in:
Sagar Vemuri 2018-11-09 11:17:34 -08:00 committed by Facebook Github Bot
parent 8ba17f382e
commit dc3528077a
139 changed files with 656 additions and 619 deletions

8
cache/cache_test.cc vendored
View File

@ -64,8 +64,8 @@ class CacheTest : public testing::TestWithParam<std::string> {
std::vector<int> deleted_keys_; std::vector<int> deleted_keys_;
std::vector<int> deleted_values_; std::vector<int> deleted_values_;
shared_ptr<Cache> cache_; std::shared_ptr<Cache> cache_;
shared_ptr<Cache> cache2_; std::shared_ptr<Cache> cache2_;
CacheTest() CacheTest()
: cache_(NewCache(kCacheSize, kNumShardBits, false)), : cache_(NewCache(kCacheSize, kNumShardBits, false)),
@ -145,7 +145,7 @@ class CacheTest : public testing::TestWithParam<std::string> {
CacheTest* CacheTest::current_; CacheTest* CacheTest::current_;
TEST_P(CacheTest, UsageTest) { TEST_P(CacheTest, UsageTest) {
// cache is shared_ptr and will be automatically cleaned up. // cache is std::shared_ptr and will be automatically cleaned up.
const uint64_t kCapacity = 100000; const uint64_t kCapacity = 100000;
auto cache = NewCache(kCapacity, 8, false); auto cache = NewCache(kCapacity, 8, false);
@ -173,7 +173,7 @@ TEST_P(CacheTest, UsageTest) {
} }
TEST_P(CacheTest, PinnedUsageTest) { TEST_P(CacheTest, PinnedUsageTest) {
// cache is shared_ptr and will be automatically cleaned up. // cache is std::shared_ptr and will be automatically cleaned up.
const uint64_t kCapacity = 100000; const uint64_t kCapacity = 100000;
auto cache = NewCache(kCapacity, 8, false); auto cache = NewCache(kCapacity, 8, false);

View File

@ -104,9 +104,9 @@ Status BuildTable(
if (iter->Valid() || !range_del_agg->IsEmpty()) { if (iter->Valid() || !range_del_agg->IsEmpty()) {
TableBuilder* builder; TableBuilder* builder;
unique_ptr<WritableFileWriter> file_writer; std::unique_ptr<WritableFileWriter> file_writer;
{ {
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
#ifndef NDEBUG #ifndef NDEBUG
bool use_direct_writes = env_options.use_direct_writes; bool use_direct_writes = env_options.use_direct_writes;
TEST_SYNC_POINT_CALLBACK("BuildTable:create_file", &use_direct_writes); TEST_SYNC_POINT_CALLBACK("BuildTable:create_file", &use_direct_writes);

12
db/c.cc
View File

@ -151,14 +151,20 @@ struct rocksdb_writablefile_t { WritableFile* rep; };
struct rocksdb_wal_iterator_t { TransactionLogIterator* rep; }; struct rocksdb_wal_iterator_t { TransactionLogIterator* rep; };
struct rocksdb_wal_readoptions_t { TransactionLogIterator::ReadOptions rep; }; struct rocksdb_wal_readoptions_t { TransactionLogIterator::ReadOptions rep; };
struct rocksdb_filelock_t { FileLock* rep; }; struct rocksdb_filelock_t { FileLock* rep; };
struct rocksdb_logger_t { shared_ptr<Logger> rep; }; struct rocksdb_logger_t {
struct rocksdb_cache_t { shared_ptr<Cache> rep; }; std::shared_ptr<Logger> rep;
};
struct rocksdb_cache_t {
std::shared_ptr<Cache> rep;
};
struct rocksdb_livefiles_t { std::vector<LiveFileMetaData> rep; }; struct rocksdb_livefiles_t { std::vector<LiveFileMetaData> rep; };
struct rocksdb_column_family_handle_t { ColumnFamilyHandle* rep; }; struct rocksdb_column_family_handle_t { ColumnFamilyHandle* rep; };
struct rocksdb_envoptions_t { EnvOptions rep; }; struct rocksdb_envoptions_t { EnvOptions rep; };
struct rocksdb_ingestexternalfileoptions_t { IngestExternalFileOptions rep; }; struct rocksdb_ingestexternalfileoptions_t { IngestExternalFileOptions rep; };
struct rocksdb_sstfilewriter_t { SstFileWriter* rep; }; struct rocksdb_sstfilewriter_t { SstFileWriter* rep; };
struct rocksdb_ratelimiter_t { shared_ptr<RateLimiter> rep; }; struct rocksdb_ratelimiter_t {
std::shared_ptr<RateLimiter> rep;
};
struct rocksdb_perfcontext_t { PerfContext* rep; }; struct rocksdb_perfcontext_t { PerfContext* rep; };
struct rocksdb_pinnableslice_t { struct rocksdb_pinnableslice_t {
PinnableSlice rep; PinnableSlice rep;

View File

@ -47,7 +47,7 @@ class EnvCounter : public EnvWrapper {
int GetNumberOfNewWritableFileCalls() { int GetNumberOfNewWritableFileCalls() {
return num_new_writable_file_; return num_new_writable_file_;
} }
Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r, Status NewWritableFile(const std::string& f, std::unique_ptr<WritableFile>* r,
const EnvOptions& soptions) override { const EnvOptions& soptions) override {
++num_new_writable_file_; ++num_new_writable_file_;
return EnvWrapper::NewWritableFile(f, r, soptions); return EnvWrapper::NewWritableFile(f, r, soptions);
@ -486,9 +486,9 @@ class ColumnFamilyTestBase : public testing::Test {
void CopyFile(const std::string& source, const std::string& destination, void CopyFile(const std::string& source, const std::string& destination,
uint64_t size = 0) { uint64_t size = 0) {
const EnvOptions soptions; const EnvOptions soptions;
unique_ptr<SequentialFile> srcfile; std::unique_ptr<SequentialFile> srcfile;
ASSERT_OK(env_->NewSequentialFile(source, &srcfile, soptions)); ASSERT_OK(env_->NewSequentialFile(source, &srcfile, soptions));
unique_ptr<WritableFile> destfile; std::unique_ptr<WritableFile> destfile;
ASSERT_OK(env_->NewWritableFile(destination, &destfile, soptions)); ASSERT_OK(env_->NewWritableFile(destination, &destfile, soptions));
if (size == 0) { if (size == 0) {

View File

@ -200,7 +200,7 @@ struct CompactionJob::SubcompactionState {
return *this; return *this;
} }
// Because member unique_ptrs do not have these. // Because member std::unique_ptrs do not have these.
SubcompactionState(const SubcompactionState&) = delete; SubcompactionState(const SubcompactionState&) = delete;
SubcompactionState& operator=(const SubcompactionState&) = delete; SubcompactionState& operator=(const SubcompactionState&) = delete;
@ -1445,7 +1445,7 @@ Status CompactionJob::OpenCompactionOutputFile(
TableFileCreationReason::kCompaction); TableFileCreationReason::kCompaction);
#endif // !ROCKSDB_LITE #endif // !ROCKSDB_LITE
// Make the output file // Make the output file
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
#ifndef NDEBUG #ifndef NDEBUG
bool syncpoint_arg = env_options_.use_direct_writes; bool syncpoint_arg = env_options_.use_direct_writes;
TEST_SYNC_POINT_CALLBACK("CompactionJob::OpenCompactionOutputFile", TEST_SYNC_POINT_CALLBACK("CompactionJob::OpenCompactionOutputFile",

View File

@ -200,11 +200,11 @@ class CompactionJobTest : public testing::Test {
new_db.SetLastSequence(0); new_db.SetLastSequence(0);
const std::string manifest = DescriptorFileName(dbname_, 1); const std::string manifest = DescriptorFileName(dbname_, 1);
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
Status s = env_->NewWritableFile( Status s = env_->NewWritableFile(
manifest, &file, env_->OptimizeForManifestWrite(env_options_)); manifest, &file, env_->OptimizeForManifestWrite(env_options_));
ASSERT_OK(s); ASSERT_OK(s);
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(file), manifest, env_options_)); new WritableFileWriter(std::move(file), manifest, env_options_));
{ {
log::Writer log(std::move(file_writer), 0, false); log::Writer log(std::move(file_writer), 0, false);

View File

@ -35,7 +35,7 @@ Status DeleteFilesInRanges(DB* db, ColumnFamilyHandle* column_family,
Status VerifySstFileChecksum(const Options& options, Status VerifySstFileChecksum(const Options& options,
const EnvOptions& env_options, const EnvOptions& env_options,
const std::string& file_path) { const std::string& file_path) {
unique_ptr<RandomAccessFile> file; std::unique_ptr<RandomAccessFile> file;
uint64_t file_size; uint64_t file_size;
InternalKeyComparator internal_comparator(options.comparator); InternalKeyComparator internal_comparator(options.comparator);
ImmutableCFOptions ioptions(options); ImmutableCFOptions ioptions(options);
@ -46,7 +46,7 @@ Status VerifySstFileChecksum(const Options& options,
} else { } else {
return s; return s;
} }
unique_ptr<TableReader> table_reader; std::unique_ptr<TableReader> table_reader;
std::unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
new RandomAccessFileReader(std::move(file), file_path)); new RandomAccessFileReader(std::move(file), file_path));
const bool kImmortal = true; const bool kImmortal = true;

View File

@ -37,7 +37,7 @@ class CorruptionTest : public testing::Test {
public: public:
test::ErrorEnv env_; test::ErrorEnv env_;
std::string dbname_; std::string dbname_;
shared_ptr<Cache> tiny_cache_; std::shared_ptr<Cache> tiny_cache_;
Options options_; Options options_;
DB* db_; DB* db_;
@ -485,7 +485,7 @@ TEST_F(CorruptionTest, FileSystemStateCorrupted) {
db_ = nullptr; db_ = nullptr;
if (iter == 0) { // corrupt file size if (iter == 0) { // corrupt file size
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
env_.NewWritableFile(filename, &file, EnvOptions()); env_.NewWritableFile(filename, &file, EnvOptions());
file->Append(Slice("corrupted sst")); file->Append(Slice("corrupted sst"));
file.reset(); file.reset();

View File

@ -881,7 +881,7 @@ class TestEnv : public EnvWrapper {
int GetCloseCount() { return close_count; } int GetCloseCount() { return close_count; }
virtual Status NewLogger(const std::string& /*fname*/, virtual Status NewLogger(const std::string& /*fname*/,
shared_ptr<Logger>* result) { std::shared_ptr<Logger>* result) {
result->reset(new TestLogger(this)); result->reset(new TestLogger(this));
return Status::OK(); return Status::OK();
} }

View File

@ -897,7 +897,7 @@ TEST_P(BloomStatsTestWithParam, BloomStatsTestWithIter) {
ASSERT_OK(Put(key1, value1, WriteOptions())); ASSERT_OK(Put(key1, value1, WriteOptions()));
ASSERT_OK(Put(key3, value3, WriteOptions())); ASSERT_OK(Put(key3, value3, WriteOptions()));
unique_ptr<Iterator> iter(dbfull()->NewIterator(ReadOptions())); std::unique_ptr<Iterator> iter(dbfull()->NewIterator(ReadOptions()));
// check memtable bloom stats // check memtable bloom stats
iter->Seek(key1); iter->Seek(key1);

View File

@ -27,7 +27,7 @@ TEST_F(DBTestDynamicLevel, DynamicLevelMaxBytesBase) {
return; return;
} }
// Use InMemoryEnv, or it would be too slow. // Use InMemoryEnv, or it would be too slow.
unique_ptr<Env> env(new MockEnv(env_)); std::unique_ptr<Env> env(new MockEnv(env_));
const int kNKeys = 1000; const int kNKeys = 1000;
int keys[kNKeys]; int keys[kNKeys];

View File

@ -40,7 +40,7 @@ TEST_F(DBEncryptionTest, CheckEncrypted) {
continue; continue;
} }
auto filePath = dbname_ + "/" + *it; auto filePath = dbname_ + "/" + *it;
unique_ptr<SequentialFile> seqFile; std::unique_ptr<SequentialFile> seqFile;
auto envOptions = EnvOptions(CurrentOptions()); auto envOptions = EnvOptions(CurrentOptions());
status = defaultEnv->NewSequentialFile(filePath, &seqFile, envOptions); status = defaultEnv->NewSequentialFile(filePath, &seqFile, envOptions);
ASSERT_OK(status); ASSERT_OK(status);

View File

@ -2295,9 +2295,8 @@ void DBImpl::ReleaseFileNumberFromPendingOutputs(
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
Status DBImpl::GetUpdatesSince( Status DBImpl::GetUpdatesSince(
SequenceNumber seq, unique_ptr<TransactionLogIterator>* iter, SequenceNumber seq, std::unique_ptr<TransactionLogIterator>* iter,
const TransactionLogIterator::ReadOptions& read_options) { const TransactionLogIterator::ReadOptions& read_options) {
RecordTick(stats_, GET_UPDATES_SINCE_CALLS); RecordTick(stats_, GET_UPDATES_SINCE_CALLS);
if (seq > versions_->LastSequence()) { if (seq > versions_->LastSequence()) {
return Status::NotFound("Requested sequence not yet written in the db"); return Status::NotFound("Requested sequence not yet written in the db");
@ -2545,10 +2544,10 @@ Status DBImpl::CheckConsistency() {
Status DBImpl::GetDbIdentity(std::string& identity) const { Status DBImpl::GetDbIdentity(std::string& identity) const {
std::string idfilename = IdentityFileName(dbname_); std::string idfilename = IdentityFileName(dbname_);
const EnvOptions soptions; const EnvOptions soptions;
unique_ptr<SequentialFileReader> id_file_reader; std::unique_ptr<SequentialFileReader> id_file_reader;
Status s; Status s;
{ {
unique_ptr<SequentialFile> idfile; std::unique_ptr<SequentialFile> idfile;
s = env_->NewSequentialFile(idfilename, &idfile, soptions); s = env_->NewSequentialFile(idfilename, &idfile, soptions);
if (!s.ok()) { if (!s.ok()) {
return s; return s;

View File

@ -259,9 +259,9 @@ class DBImpl : public DB {
virtual Status GetSortedWalFiles(VectorLogPtr& files) override; virtual Status GetSortedWalFiles(VectorLogPtr& files) override;
virtual Status GetUpdatesSince( virtual Status GetUpdatesSince(
SequenceNumber seq_number, unique_ptr<TransactionLogIterator>* iter, SequenceNumber seq_number, std::unique_ptr<TransactionLogIterator>* iter,
const TransactionLogIterator::ReadOptions& const TransactionLogIterator::ReadOptions& read_options =
read_options = TransactionLogIterator::ReadOptions()) override; TransactionLogIterator::ReadOptions()) override;
virtual Status DeleteFile(std::string name) override; virtual Status DeleteFile(std::string name) override;
Status DeleteFilesInRanges(ColumnFamilyHandle* column_family, Status DeleteFilesInRanges(ColumnFamilyHandle* column_family,
const RangePtr* ranges, size_t n, const RangePtr* ranges, size_t n,
@ -714,7 +714,7 @@ class DBImpl : public DB {
protected: protected:
Env* const env_; Env* const env_;
const std::string dbname_; const std::string dbname_;
unique_ptr<VersionSet> versions_; std::unique_ptr<VersionSet> versions_;
// Flag to check whether we allocated and own the info log file // Flag to check whether we allocated and own the info log file
bool own_info_log_; bool own_info_log_;
const DBOptions initial_db_options_; const DBOptions initial_db_options_;
@ -1190,7 +1190,7 @@ class DBImpl : public DB {
bool log_empty_; bool log_empty_;
ColumnFamilyHandleImpl* default_cf_handle_; ColumnFamilyHandleImpl* default_cf_handle_;
InternalStats* default_cf_internal_stats_; InternalStats* default_cf_internal_stats_;
unique_ptr<ColumnFamilyMemTablesImpl> column_family_memtables_; std::unique_ptr<ColumnFamilyMemTablesImpl> column_family_memtables_;
struct LogFileNumberSize { struct LogFileNumberSize {
explicit LogFileNumberSize(uint64_t _number) explicit LogFileNumberSize(uint64_t _number)
: number(_number) {} : number(_number) {}
@ -1218,7 +1218,7 @@ class DBImpl : public DB {
uint64_t number; uint64_t number;
// Visual Studio doesn't support deque's member to be noncopyable because // Visual Studio doesn't support deque's member to be noncopyable because
// of a unique_ptr as a member. // of a std::unique_ptr as a member.
log::Writer* writer; // own log::Writer* writer; // own
// true for some prefix of logs_ // true for some prefix of logs_
bool getting_synced = false; bool getting_synced = false;
@ -1304,7 +1304,7 @@ class DBImpl : public DB {
WriteController write_controller_; WriteController write_controller_;
unique_ptr<RateLimiter> low_pri_write_rate_limiter_; std::unique_ptr<RateLimiter> low_pri_write_rate_limiter_;
// Size of the last batch group. In slowdown mode, next write needs to // Size of the last batch group. In slowdown mode, next write needs to
// sleep if it uses up the quota. // sleep if it uses up the quota.

View File

@ -820,7 +820,7 @@ Status DBImpl::CompactFilesImpl(
// At this point, CompactFiles will be run. // At this point, CompactFiles will be run.
bg_compaction_scheduled_++; bg_compaction_scheduled_++;
unique_ptr<Compaction> c; std::unique_ptr<Compaction> c;
assert(cfd->compaction_picker()); assert(cfd->compaction_picker());
c.reset(cfd->compaction_picker()->CompactFiles( c.reset(cfd->compaction_picker()->CompactFiles(
compact_options, input_files, output_level, version->storage_info(), compact_options, input_files, output_level, version->storage_info(),
@ -2145,7 +2145,7 @@ Status DBImpl::BackgroundCompaction(bool* made_progress,
TEST_SYNC_POINT("DBImpl::BackgroundCompaction:Start"); TEST_SYNC_POINT("DBImpl::BackgroundCompaction:Start");
bool is_manual = (manual_compaction != nullptr); bool is_manual = (manual_compaction != nullptr);
unique_ptr<Compaction> c; std::unique_ptr<Compaction> c;
if (prepicked_compaction != nullptr && if (prepicked_compaction != nullptr &&
prepicked_compaction->compaction != nullptr) { prepicked_compaction->compaction != nullptr) {
c.reset(prepicked_compaction->compaction); c.reset(prepicked_compaction->compaction);

View File

@ -230,7 +230,7 @@ Status DBImpl::NewDB() {
ROCKS_LOG_INFO(immutable_db_options_.info_log, "Creating manifest 1 \n"); ROCKS_LOG_INFO(immutable_db_options_.info_log, "Creating manifest 1 \n");
const std::string manifest = DescriptorFileName(dbname_, 1); const std::string manifest = DescriptorFileName(dbname_, 1);
{ {
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
EnvOptions env_options = env_->OptimizeForManifestWrite(env_options_); EnvOptions env_options = env_->OptimizeForManifestWrite(env_options_);
s = NewWritableFile(env_, manifest, &file, env_options); s = NewWritableFile(env_, manifest, &file, env_options);
if (!s.ok()) { if (!s.ok()) {
@ -238,7 +238,7 @@ Status DBImpl::NewDB() {
} }
file->SetPreallocationBlockSize( file->SetPreallocationBlockSize(
immutable_db_options_.manifest_preallocation_size); immutable_db_options_.manifest_preallocation_size);
unique_ptr<WritableFileWriter> file_writer(new WritableFileWriter( std::unique_ptr<WritableFileWriter> file_writer(new WritableFileWriter(
std::move(file), manifest, env_options, nullptr /* stats */, std::move(file), manifest, env_options, nullptr /* stats */,
immutable_db_options_.listeners)); immutable_db_options_.listeners));
log::Writer log(std::move(file_writer), 0, false); log::Writer log(std::move(file_writer), 0, false);
@ -362,7 +362,7 @@ Status DBImpl::Recover(
} }
// Verify compatibility of env_options_ and filesystem // Verify compatibility of env_options_ and filesystem
{ {
unique_ptr<RandomAccessFile> idfile; std::unique_ptr<RandomAccessFile> idfile;
EnvOptions customized_env(env_options_); EnvOptions customized_env(env_options_);
customized_env.use_direct_reads |= customized_env.use_direct_reads |=
immutable_db_options_.use_direct_io_for_flush_and_compaction; immutable_db_options_.use_direct_io_for_flush_and_compaction;
@ -573,9 +573,9 @@ Status DBImpl::RecoverLogFiles(const std::vector<uint64_t>& log_numbers,
continue; continue;
} }
unique_ptr<SequentialFileReader> file_reader; std::unique_ptr<SequentialFileReader> file_reader;
{ {
unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
status = env_->NewSequentialFile(fname, &file, status = env_->NewSequentialFile(fname, &file,
env_->OptimizeForLogRead(env_options_)); env_->OptimizeForLogRead(env_options_));
if (!status.ok()) { if (!status.ok()) {
@ -1129,7 +1129,7 @@ Status DBImpl::Open(const DBOptions& db_options, const std::string& dbname,
s = impl->Recover(column_families); s = impl->Recover(column_families);
if (s.ok()) { if (s.ok()) {
uint64_t new_log_number = impl->versions_->NewFileNumber(); uint64_t new_log_number = impl->versions_->NewFileNumber();
unique_ptr<WritableFile> lfile; std::unique_ptr<WritableFile> lfile;
EnvOptions soptions(db_options); EnvOptions soptions(db_options);
EnvOptions opt_env_options = EnvOptions opt_env_options =
impl->immutable_db_options_.env->OptimizeForLogWrite( impl->immutable_db_options_.env->OptimizeForLogWrite(
@ -1147,7 +1147,7 @@ Status DBImpl::Open(const DBOptions& db_options, const std::string& dbname,
InstrumentedMutexLock wl(&impl->log_write_mutex_); InstrumentedMutexLock wl(&impl->log_write_mutex_);
impl->logfile_number_ = new_log_number; impl->logfile_number_ = new_log_number;
const auto& listeners = impl->immutable_db_options_.listeners; const auto& listeners = impl->immutable_db_options_.listeners;
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(lfile), log_fname, opt_env_options, new WritableFileWriter(std::move(lfile), log_fname, opt_env_options,
nullptr /* stats */, listeners)); nullptr /* stats */, listeners));
impl->logs_.emplace_back( impl->logs_.emplace_back(

View File

@ -1371,7 +1371,7 @@ Status DBImpl::SwitchMemtable(ColumnFamilyData* cfd, WriteContext* context) {
nonmem_write_thread_.EnterUnbatched(&nonmem_w, &mutex_); nonmem_write_thread_.EnterUnbatched(&nonmem_w, &mutex_);
} }
unique_ptr<WritableFile> lfile; std::unique_ptr<WritableFile> lfile;
log::Writer* new_log = nullptr; log::Writer* new_log = nullptr;
MemTable* new_mem = nullptr; MemTable* new_mem = nullptr;
@ -1455,7 +1455,7 @@ Status DBImpl::SwitchMemtable(ColumnFamilyData* cfd, WriteContext* context) {
// of calling GetWalPreallocateBlockSize() // of calling GetWalPreallocateBlockSize()
lfile->SetPreallocationBlockSize(preallocate_block_size); lfile->SetPreallocationBlockSize(preallocate_block_size);
lfile->SetWriteLifeTimeHint(write_hint); lfile->SetWriteLifeTimeHint(write_hint);
unique_ptr<WritableFileWriter> file_writer(new WritableFileWriter( std::unique_ptr<WritableFileWriter> file_writer(new WritableFileWriter(
std::move(lfile), log_fname, opt_env_opt, nullptr /* stats */, std::move(lfile), log_fname, opt_env_opt, nullptr /* stats */,
immutable_db_options_.listeners)); immutable_db_options_.listeners));
new_log = new log::Writer( new_log = new log::Writer(

View File

@ -85,7 +85,7 @@ TEST_P(DBIteratorTest, IteratorProperty) {
ReadOptions ropt; ReadOptions ropt;
ropt.pin_data = false; ropt.pin_data = false;
{ {
unique_ptr<Iterator> iter(NewIterator(ropt, handles_[1])); std::unique_ptr<Iterator> iter(NewIterator(ropt, handles_[1]));
iter->SeekToFirst(); iter->SeekToFirst();
std::string prop_value; std::string prop_value;
ASSERT_NOK(iter->GetProperty("non_existing.value", &prop_value)); ASSERT_NOK(iter->GetProperty("non_existing.value", &prop_value));
@ -2373,7 +2373,7 @@ TEST_P(DBIteratorTest, SeekAfterHittingManyInternalKeys) {
Delete("5"); Delete("5");
Put("6", "val_6"); Put("6", "val_6");
unique_ptr<Iterator> iter(NewIterator(ropts)); std::unique_ptr<Iterator> iter(NewIterator(ropts));
iter->SeekToFirst(); iter->SeekToFirst();
ASSERT_TRUE(iter->Valid()); ASSERT_TRUE(iter->Valid());
@ -2392,7 +2392,7 @@ TEST_P(DBIteratorTest, SeekAfterHittingManyInternalKeys) {
ASSERT_EQ("4", prop_value); ASSERT_EQ("4", prop_value);
// Create a new iterator to seek to the internal key. // Create a new iterator to seek to the internal key.
unique_ptr<Iterator> iter2(NewIterator(ropts)); std::unique_ptr<Iterator> iter2(NewIterator(ropts));
iter2->Seek(prop_value); iter2->Seek(prop_value);
ASSERT_TRUE(iter2->Valid()); ASSERT_TRUE(iter2->Valid());
ASSERT_OK(iter2->status()); ASSERT_OK(iter2->status());
@ -2420,7 +2420,7 @@ TEST_P(DBIteratorTest, NonBlockingIterationBugRepro) {
// Create a nonblocking iterator before writing to memtable. // Create a nonblocking iterator before writing to memtable.
ReadOptions ropt; ReadOptions ropt;
ropt.read_tier = kBlockCacheTier; ropt.read_tier = kBlockCacheTier;
unique_ptr<Iterator> iter(NewIterator(ropt)); std::unique_ptr<Iterator> iter(NewIterator(ropt));
// Overwrite a key in memtable many times to hit // Overwrite a key in memtable many times to hit
// max_sequential_skip_in_iterations (which is 8 by default). // max_sequential_skip_in_iterations (which is 8 by default).
@ -2430,7 +2430,7 @@ TEST_P(DBIteratorTest, NonBlockingIterationBugRepro) {
// Load the second block in sst file into the block cache. // Load the second block in sst file into the block cache.
{ {
unique_ptr<Iterator> iter2(NewIterator(ReadOptions())); std::unique_ptr<Iterator> iter2(NewIterator(ReadOptions()));
iter2->Seek("d"); iter2->Seek("d");
} }

View File

@ -23,7 +23,7 @@ class DBTestXactLogIterator : public DBTestBase {
std::unique_ptr<TransactionLogIterator> OpenTransactionLogIter( std::unique_ptr<TransactionLogIterator> OpenTransactionLogIter(
const SequenceNumber seq) { const SequenceNumber seq) {
unique_ptr<TransactionLogIterator> iter; std::unique_ptr<TransactionLogIterator> iter;
Status status = dbfull()->GetUpdatesSince(seq, &iter); Status status = dbfull()->GetUpdatesSince(seq, &iter);
EXPECT_OK(status); EXPECT_OK(status);
EXPECT_TRUE(iter->Valid()); EXPECT_TRUE(iter->Valid());

View File

@ -446,7 +446,7 @@ TEST_F(DBPropertiesTest, ReadLatencyHistogramByLevel) {
ASSERT_EQ(std::string::npos, prop.find("** Level 1 read latency histogram")); ASSERT_EQ(std::string::npos, prop.find("** Level 1 read latency histogram"));
ASSERT_EQ(std::string::npos, prop.find("** Level 2 read latency histogram")); ASSERT_EQ(std::string::npos, prop.find("** Level 2 read latency histogram"));
{ {
unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions())); std::unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions()));
for (iter->Seek(Key(0)); iter->Valid(); iter->Next()) { for (iter->Seek(Key(0)); iter->Valid(); iter->Next()) {
} }
} }

View File

@ -93,7 +93,7 @@ class DBTestWithParam
}; };
TEST_F(DBTest, MockEnvTest) { TEST_F(DBTest, MockEnvTest) {
unique_ptr<MockEnv> env{new MockEnv(Env::Default())}; std::unique_ptr<MockEnv> env{new MockEnv(Env::Default())};
Options options; Options options;
options.create_if_missing = true; options.create_if_missing = true;
options.env = env.get(); options.env = env.get();
@ -143,7 +143,7 @@ TEST_F(DBTest, MockEnvTest) {
// defined. // defined.
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
TEST_F(DBTest, MemEnvTest) { TEST_F(DBTest, MemEnvTest) {
unique_ptr<Env> env{NewMemEnv(Env::Default())}; std::unique_ptr<Env> env{NewMemEnv(Env::Default())};
Options options; Options options;
options.create_if_missing = true; options.create_if_missing = true;
options.env = env.get(); options.env = env.get();
@ -2689,7 +2689,8 @@ class ModelDB : public DB {
} }
virtual Status GetUpdatesSince( virtual Status GetUpdatesSince(
rocksdb::SequenceNumber, unique_ptr<rocksdb::TransactionLogIterator>*, rocksdb::SequenceNumber,
std::unique_ptr<rocksdb::TransactionLogIterator>*,
const TransactionLogIterator::ReadOptions& /*read_options*/ = const TransactionLogIterator::ReadOptions& /*read_options*/ =
TransactionLogIterator::ReadOptions()) override { TransactionLogIterator::ReadOptions()) override {
return Status::NotSupported("Not supported in Model DB"); return Status::NotSupported("Not supported in Model DB");

View File

@ -61,7 +61,7 @@ TEST_P(PrefixFullBloomWithReverseComparator,
bbto.block_cache->EraseUnRefEntries(); bbto.block_cache->EraseUnRefEntries();
} }
unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions())); std::unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions()));
iter->Seek("bar345"); iter->Seek("bar345");
ASSERT_OK(iter->status()); ASSERT_OK(iter->status());
ASSERT_TRUE(iter->Valid()); ASSERT_TRUE(iter->Valid());
@ -2692,7 +2692,7 @@ TEST_F(DBTest2, DISABLED_IteratorPinnedMemory) {
// Verify that iterators don't pin more than one data block in block cache // Verify that iterators don't pin more than one data block in block cache
// at each time. // at each time.
{ {
unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions())); std::unique_ptr<Iterator> iter(db_->NewIterator(ReadOptions()));
iter->SeekToFirst(); iter->SeekToFirst();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {

View File

@ -653,12 +653,13 @@ Status DBTestBase::ReadOnlyReopen(const Options& options) {
Status DBTestBase::TryReopen(const Options& options) { Status DBTestBase::TryReopen(const Options& options) {
Close(); Close();
last_options_.table_factory.reset(); last_options_.table_factory.reset();
// Note: operator= is an unsafe approach here since it destructs shared_ptr in // Note: operator= is an unsafe approach here since it destructs
// the same order of their creation, in contrast to destructors which // std::shared_ptr in the same order of their creation, in contrast to
// destructs them in the opposite order of creation. One particular problme is // destructors which destructs them in the opposite order of creation. One
// that the cache destructor might invoke callback functions that use Option // particular problme is that the cache destructor might invoke callback
// members such as statistics. To work around this problem, we manually call // functions that use Option members such as statistics. To work around this
// destructor of table_facotry which eventually clears the block cache. // problem, we manually call destructor of table_facotry which eventually
// clears the block cache.
last_options_ = options; last_options_ = options;
return DB::Open(options, dbname_, &db_); return DB::Open(options, dbname_, &db_);
} }
@ -670,7 +671,7 @@ bool DBTestBase::IsDirectIOSupported() {
std::string tmp = TempFileName(dbname_, 999); std::string tmp = TempFileName(dbname_, 999);
Status s; Status s;
{ {
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
s = env_->NewWritableFile(tmp, &file, env_options); s = env_->NewWritableFile(tmp, &file, env_options);
} }
if (s.ok()) { if (s.ok()) {
@ -1264,9 +1265,9 @@ void DBTestBase::validateNumberOfEntries(int numValues, int cf) {
void DBTestBase::CopyFile(const std::string& source, void DBTestBase::CopyFile(const std::string& source,
const std::string& destination, uint64_t size) { const std::string& destination, uint64_t size) {
const EnvOptions soptions; const EnvOptions soptions;
unique_ptr<SequentialFile> srcfile; std::unique_ptr<SequentialFile> srcfile;
ASSERT_OK(env_->NewSequentialFile(source, &srcfile, soptions)); ASSERT_OK(env_->NewSequentialFile(source, &srcfile, soptions));
unique_ptr<WritableFile> destfile; std::unique_ptr<WritableFile> destfile;
ASSERT_OK(env_->NewWritableFile(destination, &destfile, soptions)); ASSERT_OK(env_->NewWritableFile(destination, &destfile, soptions));
if (size == 0) { if (size == 0) {

View File

@ -169,7 +169,7 @@ class SpecialMemTableRep : public MemTableRep {
virtual ~SpecialMemTableRep() override {} virtual ~SpecialMemTableRep() override {}
private: private:
unique_ptr<MemTableRep> memtable_; std::unique_ptr<MemTableRep> memtable_;
int num_entries_flush_; int num_entries_flush_;
int num_entries_; int num_entries_;
}; };
@ -207,15 +207,15 @@ class SpecialEnv : public EnvWrapper {
public: public:
explicit SpecialEnv(Env* base); explicit SpecialEnv(Env* base);
Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r, Status NewWritableFile(const std::string& f, std::unique_ptr<WritableFile>* r,
const EnvOptions& soptions) override { const EnvOptions& soptions) override {
class SSTableFile : public WritableFile { class SSTableFile : public WritableFile {
private: private:
SpecialEnv* env_; SpecialEnv* env_;
unique_ptr<WritableFile> base_; std::unique_ptr<WritableFile> base_;
public: public:
SSTableFile(SpecialEnv* env, unique_ptr<WritableFile>&& base) SSTableFile(SpecialEnv* env, std::unique_ptr<WritableFile>&& base)
: env_(env), base_(std::move(base)) {} : env_(env), base_(std::move(base)) {}
Status Append(const Slice& data) override { Status Append(const Slice& data) override {
if (env_->table_write_callback_) { if (env_->table_write_callback_) {
@ -295,7 +295,7 @@ class SpecialEnv : public EnvWrapper {
}; };
class ManifestFile : public WritableFile { class ManifestFile : public WritableFile {
public: public:
ManifestFile(SpecialEnv* env, unique_ptr<WritableFile>&& b) ManifestFile(SpecialEnv* env, std::unique_ptr<WritableFile>&& b)
: env_(env), base_(std::move(b)) {} : env_(env), base_(std::move(b)) {}
Status Append(const Slice& data) override { Status Append(const Slice& data) override {
if (env_->manifest_write_error_.load(std::memory_order_acquire)) { if (env_->manifest_write_error_.load(std::memory_order_acquire)) {
@ -322,11 +322,11 @@ class SpecialEnv : public EnvWrapper {
private: private:
SpecialEnv* env_; SpecialEnv* env_;
unique_ptr<WritableFile> base_; std::unique_ptr<WritableFile> base_;
}; };
class WalFile : public WritableFile { class WalFile : public WritableFile {
public: public:
WalFile(SpecialEnv* env, unique_ptr<WritableFile>&& b) WalFile(SpecialEnv* env, std::unique_ptr<WritableFile>&& b)
: env_(env), base_(std::move(b)) { : env_(env), base_(std::move(b)) {
env_->num_open_wal_file_.fetch_add(1); env_->num_open_wal_file_.fetch_add(1);
} }
@ -378,7 +378,7 @@ class SpecialEnv : public EnvWrapper {
private: private:
SpecialEnv* env_; SpecialEnv* env_;
unique_ptr<WritableFile> base_; std::unique_ptr<WritableFile> base_;
}; };
if (non_writeable_rate_.load(std::memory_order_acquire) > 0) { if (non_writeable_rate_.load(std::memory_order_acquire) > 0) {
@ -420,11 +420,11 @@ class SpecialEnv : public EnvWrapper {
} }
Status NewRandomAccessFile(const std::string& f, Status NewRandomAccessFile(const std::string& f,
unique_ptr<RandomAccessFile>* r, std::unique_ptr<RandomAccessFile>* r,
const EnvOptions& soptions) override { const EnvOptions& soptions) override {
class CountingFile : public RandomAccessFile { class CountingFile : public RandomAccessFile {
public: public:
CountingFile(unique_ptr<RandomAccessFile>&& target, CountingFile(std::unique_ptr<RandomAccessFile>&& target,
anon::AtomicCounter* counter, anon::AtomicCounter* counter,
std::atomic<size_t>* bytes_read) std::atomic<size_t>* bytes_read)
: target_(std::move(target)), : target_(std::move(target)),
@ -439,7 +439,7 @@ class SpecialEnv : public EnvWrapper {
} }
private: private:
unique_ptr<RandomAccessFile> target_; std::unique_ptr<RandomAccessFile> target_;
anon::AtomicCounter* counter_; anon::AtomicCounter* counter_;
std::atomic<size_t>* bytes_read_; std::atomic<size_t>* bytes_read_;
}; };
@ -457,11 +457,11 @@ class SpecialEnv : public EnvWrapper {
} }
virtual Status NewSequentialFile(const std::string& f, virtual Status NewSequentialFile(const std::string& f,
unique_ptr<SequentialFile>* r, std::unique_ptr<SequentialFile>* r,
const EnvOptions& soptions) override { const EnvOptions& soptions) override {
class CountingFile : public SequentialFile { class CountingFile : public SequentialFile {
public: public:
CountingFile(unique_ptr<SequentialFile>&& target, CountingFile(std::unique_ptr<SequentialFile>&& target,
anon::AtomicCounter* counter) anon::AtomicCounter* counter)
: target_(std::move(target)), counter_(counter) {} : target_(std::move(target)), counter_(counter) {}
virtual Status Read(size_t n, Slice* result, char* scratch) override { virtual Status Read(size_t n, Slice* result, char* scratch) override {
@ -471,7 +471,7 @@ class SpecialEnv : public EnvWrapper {
virtual Status Skip(uint64_t n) override { return target_->Skip(n); } virtual Status Skip(uint64_t n) override { return target_->Skip(n); }
private: private:
unique_ptr<SequentialFile> target_; std::unique_ptr<SequentialFile> target_;
anon::AtomicCounter* counter_; anon::AtomicCounter* counter_;
}; };

View File

@ -33,7 +33,8 @@ class DBWALTest : public DBTestBase {
class EnrichedSpecialEnv : public SpecialEnv { class EnrichedSpecialEnv : public SpecialEnv {
public: public:
explicit EnrichedSpecialEnv(Env* base) : SpecialEnv(base) {} explicit EnrichedSpecialEnv(Env* base) : SpecialEnv(base) {}
Status NewSequentialFile(const std::string& f, unique_ptr<SequentialFile>* r, Status NewSequentialFile(const std::string& f,
std::unique_ptr<SequentialFile>* r,
const EnvOptions& soptions) override { const EnvOptions& soptions) override {
InstrumentedMutexLock l(&env_mutex_); InstrumentedMutexLock l(&env_mutex_);
if (f == skipped_wal) { if (f == skipped_wal) {
@ -802,12 +803,12 @@ class RecoveryTestHelper {
*count = 0; *count = 0;
shared_ptr<Cache> table_cache = NewLRUCache(50, 0); std::shared_ptr<Cache> table_cache = NewLRUCache(50, 0);
EnvOptions env_options; EnvOptions env_options;
WriteBufferManager write_buffer_manager(db_options.db_write_buffer_size); WriteBufferManager write_buffer_manager(db_options.db_write_buffer_size);
unique_ptr<VersionSet> versions; std::unique_ptr<VersionSet> versions;
unique_ptr<WalManager> wal_manager; std::unique_ptr<WalManager> wal_manager;
WriteController write_controller; WriteController write_controller;
versions.reset(new VersionSet(test->dbname_, &db_options, env_options, versions.reset(new VersionSet(test->dbname_, &db_options, env_options,
@ -821,9 +822,9 @@ class RecoveryTestHelper {
for (size_t j = kWALFileOffset; j < wal_count + kWALFileOffset; j++) { for (size_t j = kWALFileOffset; j < wal_count + kWALFileOffset; j++) {
uint64_t current_log_number = j; uint64_t current_log_number = j;
std::string fname = LogFileName(test->dbname_, current_log_number); std::string fname = LogFileName(test->dbname_, current_log_number);
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
ASSERT_OK(db_options.env->NewWritableFile(fname, &file, env_options)); ASSERT_OK(db_options.env->NewWritableFile(fname, &file, env_options));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(file), fname, env_options)); new WritableFileWriter(std::move(file), fname, env_options));
current_log_writer.reset( current_log_writer.reset(
new log::Writer(std::move(file_writer), current_log_number, new log::Writer(std::move(file_writer), current_log_number,

View File

@ -70,7 +70,7 @@ class FaultInjectionTest
std::unique_ptr<Env> base_env_; std::unique_ptr<Env> base_env_;
FaultInjectionTestEnv* env_; FaultInjectionTestEnv* env_;
std::string dbname_; std::string dbname_;
shared_ptr<Cache> tiny_cache_; std::shared_ptr<Cache> tiny_cache_;
Options options_; Options options_;
DB* db_; DB* db_;

View File

@ -73,11 +73,11 @@ class FlushJobTest : public testing::Test {
} }
const std::string manifest = DescriptorFileName(dbname_, 1); const std::string manifest = DescriptorFileName(dbname_, 1);
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
Status s = env_->NewWritableFile( Status s = env_->NewWritableFile(
manifest, &file, env_->OptimizeForManifestWrite(env_options_)); manifest, &file, env_->OptimizeForManifestWrite(env_options_));
ASSERT_OK(s); ASSERT_OK(s);
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(file), manifest, EnvOptions())); new WritableFileWriter(std::move(file), manifest, EnvOptions()));
{ {
log::Writer log(std::move(file_writer), 0, false); log::Writer log(std::move(file_writer), 0, false);

View File

@ -30,7 +30,8 @@ struct SuperVersionContext {
#ifndef ROCKSDB_DISABLE_STALL_NOTIFICATION #ifndef ROCKSDB_DISABLE_STALL_NOTIFICATION
autovector<WriteStallNotification> write_stall_notifications; autovector<WriteStallNotification> write_stall_notifications;
#endif #endif
unique_ptr<SuperVersion> new_superversion; // if nullptr no new superversion std::unique_ptr<SuperVersion>
new_superversion; // if nullptr no new superversion
explicit SuperVersionContext(bool create_superversion = false) explicit SuperVersionContext(bool create_superversion = false)
: new_superversion(create_superversion ? new SuperVersion() : nullptr) {} : new_superversion(create_superversion ? new SuperVersion() : nullptr) {}
@ -44,7 +45,7 @@ struct SuperVersionContext {
} }
void NewSuperVersion() { void NewSuperVersion() {
new_superversion = unique_ptr<SuperVersion>(new SuperVersion()); new_superversion = std::unique_ptr<SuperVersion>(new SuperVersion());
} }
inline bool HaveSomethingToDelete() const { inline bool HaveSomethingToDelete() const {

View File

@ -23,8 +23,9 @@ Reader::Reporter::~Reporter() {
} }
Reader::Reader(std::shared_ptr<Logger> info_log, Reader::Reader(std::shared_ptr<Logger> info_log,
unique_ptr<SequentialFileReader>&& _file, Reporter* reporter, std::unique_ptr<SequentialFileReader>&& _file,
bool checksum, uint64_t log_num, bool retry_after_eof) Reporter* reporter, bool checksum, uint64_t log_num,
bool retry_after_eof)
: info_log_(info_log), : info_log_(info_log),
file_(std::move(_file)), file_(std::move(_file)),
reporter_(reporter), reporter_(reporter),

View File

@ -52,7 +52,7 @@ class Reader {
// If "checksum" is true, verify checksums if available. // If "checksum" is true, verify checksums if available.
Reader(std::shared_ptr<Logger> info_log, Reader(std::shared_ptr<Logger> info_log,
// @lint-ignore TXT2 T25377293 Grandfathered in // @lint-ignore TXT2 T25377293 Grandfathered in
unique_ptr<SequentialFileReader>&& file, Reporter* reporter, std::unique_ptr<SequentialFileReader>&& file, Reporter* reporter,
bool checksum, uint64_t log_num, bool retry_after_eof); bool checksum, uint64_t log_num, bool retry_after_eof);
~Reader(); ~Reader();
@ -87,7 +87,7 @@ class Reader {
private: private:
std::shared_ptr<Logger> info_log_; std::shared_ptr<Logger> info_log_;
const unique_ptr<SequentialFileReader> file_; const std::unique_ptr<SequentialFileReader> file_;
Reporter* const reporter_; Reporter* const reporter_;
bool const checksum_; bool const checksum_;
char* const backing_store_; char* const backing_store_;

View File

@ -145,8 +145,8 @@ class LogTest : public ::testing::TestWithParam<int> {
} }
Slice reader_contents_; Slice reader_contents_;
unique_ptr<WritableFileWriter> dest_holder_; std::unique_ptr<WritableFileWriter> dest_holder_;
unique_ptr<SequentialFileReader> source_holder_; std::unique_ptr<SequentialFileReader> source_holder_;
ReportCollector report_; ReportCollector report_;
Writer writer_; Writer writer_;
Reader reader_; Reader reader_;
@ -639,7 +639,7 @@ TEST_P(LogTest, Recycle) {
while (get_reader_contents()->size() < log::kBlockSize * 2) { while (get_reader_contents()->size() < log::kBlockSize * 2) {
Write("xxxxxxxxxxxxxxxx"); Write("xxxxxxxxxxxxxxxx");
} }
unique_ptr<WritableFileWriter> dest_holder(test::GetWritableFileWriter( std::unique_ptr<WritableFileWriter> dest_holder(test::GetWritableFileWriter(
new test::OverwritingStringSink(get_reader_contents()), new test::OverwritingStringSink(get_reader_contents()),
"" /* don't care */)); "" /* don't care */));
Writer recycle_writer(std::move(dest_holder), 123, true); Writer recycle_writer(std::move(dest_holder), 123, true);
@ -668,16 +668,16 @@ class RetriableLogTest : public ::testing::TestWithParam<int> {
}; };
Slice contents_; Slice contents_;
unique_ptr<WritableFileWriter> dest_holder_; std::unique_ptr<WritableFileWriter> dest_holder_;
unique_ptr<Writer> log_writer_; std::unique_ptr<Writer> log_writer_;
Env* env_; Env* env_;
EnvOptions env_options_; EnvOptions env_options_;
const std::string test_dir_; const std::string test_dir_;
const std::string log_file_; const std::string log_file_;
unique_ptr<WritableFileWriter> writer_; std::unique_ptr<WritableFileWriter> writer_;
unique_ptr<SequentialFileReader> reader_; std::unique_ptr<SequentialFileReader> reader_;
ReportCollector report_; ReportCollector report_;
unique_ptr<Reader> log_reader_; std::unique_ptr<Reader> log_reader_;
public: public:
RetriableLogTest() RetriableLogTest()
@ -700,7 +700,7 @@ class RetriableLogTest : public ::testing::TestWithParam<int> {
Status s; Status s;
s = env_->CreateDirIfMissing(test_dir_); s = env_->CreateDirIfMissing(test_dir_);
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
if (s.ok()) { if (s.ok()) {
s = env_->NewWritableFile(log_file_, &writable_file, env_options_); s = env_->NewWritableFile(log_file_, &writable_file, env_options_);
} }
@ -709,7 +709,7 @@ class RetriableLogTest : public ::testing::TestWithParam<int> {
env_options_)); env_options_));
assert(writer_ != nullptr); assert(writer_ != nullptr);
} }
unique_ptr<SequentialFile> seq_file; std::unique_ptr<SequentialFile> seq_file;
if (s.ok()) { if (s.ok()) {
s = env_->NewSequentialFile(log_file_, &seq_file, env_options_); s = env_->NewSequentialFile(log_file_, &seq_file, env_options_);
} }

View File

@ -88,7 +88,7 @@ class Writer {
bool TEST_BufferIsEmpty(); bool TEST_BufferIsEmpty();
private: private:
unique_ptr<WritableFileWriter> dest_; std::unique_ptr<WritableFileWriter> dest_;
size_t block_offset_; // Current offset in block size_t block_offset_; // Current offset in block
uint64_t log_number_; uint64_t log_number_;
bool recycle_log_files_; bool recycle_log_files_;

View File

@ -406,8 +406,8 @@ class MemTable {
const size_t kArenaBlockSize; const size_t kArenaBlockSize;
AllocTracker mem_tracker_; AllocTracker mem_tracker_;
ConcurrentArena arena_; ConcurrentArena arena_;
unique_ptr<MemTableRep> table_; std::unique_ptr<MemTableRep> table_;
unique_ptr<MemTableRep> range_del_table_; std::unique_ptr<MemTableRep> range_del_table_;
bool is_range_del_table_empty_; bool is_range_del_table_empty_;
// Total data size of all data inserted // Total data size of all data inserted

View File

@ -110,7 +110,7 @@ class MemTableListTest : public testing::Test {
DBOptions db_options; DBOptions db_options;
ImmutableDBOptions immutable_db_options(db_options); ImmutableDBOptions immutable_db_options(db_options);
EnvOptions env_options; EnvOptions env_options;
shared_ptr<Cache> table_cache(NewLRUCache(50000, 16)); std::shared_ptr<Cache> table_cache(NewLRUCache(50000, 16));
WriteBufferManager write_buffer_manager(db_options.db_write_buffer_size); WriteBufferManager write_buffer_manager(db_options.db_write_buffer_size);
WriteController write_controller(10000000u); WriteController write_controller(10000000u);

View File

@ -246,7 +246,7 @@ class MergeBasedCounters : public Counters {
}; };
void dumpDb(DB* db) { void dumpDb(DB* db) {
auto it = unique_ptr<Iterator>(db->NewIterator(ReadOptions())); auto it = std::unique_ptr<Iterator>(db->NewIterator(ReadOptions()));
for (it->SeekToFirst(); it->Valid(); it->Next()) { for (it->SeekToFirst(); it->Valid(); it->Next()) {
//uint64_t value = DecodeFixed64(it->value().data()); //uint64_t value = DecodeFixed64(it->value().data());
//std::cout << it->key().ToString() << ": " << value << std::endl; //std::cout << it->key().ToString() << ": " << value << std::endl;

View File

@ -50,10 +50,11 @@ TEST_F(PlainTableKeyDecoderTest, ReadNonMmap) {
test::StringSource* string_source = test::StringSource* string_source =
new test::StringSource(contents, 0, false); new test::StringSource(contents, 0, false);
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
test::GetRandomAccessFileReader(string_source)); test::GetRandomAccessFileReader(string_source));
unique_ptr<PlainTableReaderFileInfo> file_info(new PlainTableReaderFileInfo( std::unique_ptr<PlainTableReaderFileInfo> file_info(
std::move(file_reader), EnvOptions(), kLength)); new PlainTableReaderFileInfo(std::move(file_reader), EnvOptions(),
kLength));
{ {
PlainTableFileReader reader(file_info.get()); PlainTableFileReader reader(file_info.get());
@ -260,7 +261,7 @@ class TestPlainTableReader : public PlainTableReader {
int bloom_bits_per_key, double hash_table_ratio, int bloom_bits_per_key, double hash_table_ratio,
size_t index_sparseness, size_t index_sparseness,
const TableProperties* table_properties, const TableProperties* table_properties,
unique_ptr<RandomAccessFileReader>&& file, std::unique_ptr<RandomAccessFileReader>&& file,
const ImmutableCFOptions& ioptions, const ImmutableCFOptions& ioptions,
const SliceTransform* prefix_extractor, const SliceTransform* prefix_extractor,
bool* expect_bloom_not_match, bool store_index_in_file, bool* expect_bloom_not_match, bool store_index_in_file,
@ -327,8 +328,8 @@ class TestPlainTableFactory : public PlainTableFactory {
Status NewTableReader( Status NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table, std::unique_ptr<TableReader>* table,
bool /*prefetch_index_and_filter_in_cache*/) const override { bool /*prefetch_index_and_filter_in_cache*/) const override {
TableProperties* props = nullptr; TableProperties* props = nullptr;
auto s = auto s =

View File

@ -344,13 +344,13 @@ class Repairer {
// Open the log file // Open the log file
std::string logname = LogFileName(db_options_.wal_dir, log); std::string logname = LogFileName(db_options_.wal_dir, log);
unique_ptr<SequentialFile> lfile; std::unique_ptr<SequentialFile> lfile;
Status status = env_->NewSequentialFile( Status status = env_->NewSequentialFile(
logname, &lfile, env_->OptimizeForLogRead(env_options_)); logname, &lfile, env_->OptimizeForLogRead(env_options_));
if (!status.ok()) { if (!status.ok()) {
return status; return status;
} }
unique_ptr<SequentialFileReader> lfile_reader( std::unique_ptr<SequentialFileReader> lfile_reader(
new SequentialFileReader(std::move(lfile), logname)); new SequentialFileReader(std::move(lfile), logname));
// Create the log reader. // Create the log reader.

View File

@ -92,12 +92,12 @@ Status TableCache::GetTableReader(
const EnvOptions& env_options, const EnvOptions& env_options,
const InternalKeyComparator& internal_comparator, const FileDescriptor& fd, const InternalKeyComparator& internal_comparator, const FileDescriptor& fd,
bool sequential_mode, size_t readahead, bool record_read_stats, bool sequential_mode, size_t readahead, bool record_read_stats,
HistogramImpl* file_read_hist, unique_ptr<TableReader>* table_reader, HistogramImpl* file_read_hist, std::unique_ptr<TableReader>* table_reader,
const SliceTransform* prefix_extractor, bool skip_filters, int level, const SliceTransform* prefix_extractor, bool skip_filters, int level,
bool prefetch_index_and_filter_in_cache, bool for_compaction) { bool prefetch_index_and_filter_in_cache, bool for_compaction) {
std::string fname = std::string fname =
TableFileName(ioptions_.cf_paths, fd.GetNumber(), fd.GetPathId()); TableFileName(ioptions_.cf_paths, fd.GetNumber(), fd.GetPathId());
unique_ptr<RandomAccessFile> file; std::unique_ptr<RandomAccessFile> file;
Status s = ioptions_.env->NewRandomAccessFile(fname, &file, env_options); Status s = ioptions_.env->NewRandomAccessFile(fname, &file, env_options);
RecordTick(ioptions_.statistics, NO_FILE_OPENS); RecordTick(ioptions_.statistics, NO_FILE_OPENS);
@ -157,7 +157,7 @@ Status TableCache::FindTable(const EnvOptions& env_options,
if (no_io) { // Don't do IO and return a not-found status if (no_io) { // Don't do IO and return a not-found status
return Status::Incomplete("Table not found in table_cache, no_io is set"); return Status::Incomplete("Table not found in table_cache, no_io is set");
} }
unique_ptr<TableReader> table_reader; std::unique_ptr<TableReader> table_reader;
s = GetTableReader(env_options, internal_comparator, fd, s = GetTableReader(env_options, internal_comparator, fd,
false /* sequential mode */, 0 /* readahead */, false /* sequential mode */, 0 /* readahead */,
record_read_stats, file_read_hist, &table_reader, record_read_stats, file_read_hist, &table_reader,
@ -217,7 +217,7 @@ InternalIterator* TableCache::NewIterator(
auto& fd = file_meta.fd; auto& fd = file_meta.fd;
if (create_new_table_reader) { if (create_new_table_reader) {
unique_ptr<TableReader> table_reader_unique_ptr; std::unique_ptr<TableReader> table_reader_unique_ptr;
s = GetTableReader( s = GetTableReader(
env_options, icomparator, fd, true /* sequential_mode */, readahead, env_options, icomparator, fd, true /* sequential_mode */, readahead,
!for_compaction /* record stats */, nullptr, &table_reader_unique_ptr, !for_compaction /* record stats */, nullptr, &table_reader_unique_ptr,

View File

@ -141,7 +141,7 @@ class TableCache {
const FileDescriptor& fd, bool sequential_mode, const FileDescriptor& fd, bool sequential_mode,
size_t readahead, bool record_read_stats, size_t readahead, bool record_read_stats,
HistogramImpl* file_read_hist, HistogramImpl* file_read_hist,
unique_ptr<TableReader>* table_reader, std::unique_ptr<TableReader>* table_reader,
const SliceTransform* prefix_extractor = nullptr, const SliceTransform* prefix_extractor = nullptr,
bool skip_filters = false, int level = -1, bool skip_filters = false, int level = -1,
bool prefetch_index_and_filter_in_cache = true, bool prefetch_index_and_filter_in_cache = true,

View File

@ -45,7 +45,7 @@ void MakeBuilder(const Options& options, const ImmutableCFOptions& ioptions,
int_tbl_prop_collector_factories, int_tbl_prop_collector_factories,
std::unique_ptr<WritableFileWriter>* writable, std::unique_ptr<WritableFileWriter>* writable,
std::unique_ptr<TableBuilder>* builder) { std::unique_ptr<TableBuilder>* builder) {
unique_ptr<WritableFile> wf(new test::StringSink); std::unique_ptr<WritableFile> wf(new test::StringSink);
writable->reset( writable->reset(
new WritableFileWriter(std::move(wf), "" /* don't care */, EnvOptions())); new WritableFileWriter(std::move(wf), "" /* don't care */, EnvOptions()));
int unknown_level = -1; int unknown_level = -1;
@ -415,7 +415,8 @@ void TestInternalKeyPropertiesCollector(
test::StringSink* fwf = test::StringSink* fwf =
static_cast<test::StringSink*>(writable->writable_file()); static_cast<test::StringSink*>(writable->writable_file());
unique_ptr<RandomAccessFileReader> reader(test::GetRandomAccessFileReader( std::unique_ptr<RandomAccessFileReader> reader(
test::GetRandomAccessFileReader(
new test::StringSource(fwf->contents()))); new test::StringSource(fwf->contents())));
TableProperties* props; TableProperties* props;
Status s = Status s =

View File

@ -43,9 +43,10 @@ TransactionLogIteratorImpl::TransactionLogIteratorImpl(
} }
Status TransactionLogIteratorImpl::OpenLogFile( Status TransactionLogIteratorImpl::OpenLogFile(
const LogFile* logFile, unique_ptr<SequentialFileReader>* file_reader) { const LogFile* logFile,
std::unique_ptr<SequentialFileReader>* file_reader) {
Env* env = options_->env; Env* env = options_->env;
unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
std::string fname; std::string fname;
Status s; Status s;
EnvOptions optimized_env_options = env->OptimizeForLogRead(soptions_); EnvOptions optimized_env_options = env->OptimizeForLogRead(soptions_);
@ -306,7 +307,7 @@ void TransactionLogIteratorImpl::UpdateCurrentWriteBatch(const Slice& record) {
} }
Status TransactionLogIteratorImpl::OpenLogReader(const LogFile* logFile) { Status TransactionLogIteratorImpl::OpenLogReader(const LogFile* logFile) {
unique_ptr<SequentialFileReader> file; std::unique_ptr<SequentialFileReader> file;
Status s = OpenLogFile(logFile, &file); Status s = OpenLogFile(logFile, &file);
if (!s.ok()) { if (!s.ok()) {
return s; return s;

View File

@ -85,9 +85,9 @@ class TransactionLogIteratorImpl : public TransactionLogIterator {
Status currentStatus_; Status currentStatus_;
size_t currentFileIndex_; size_t currentFileIndex_;
std::unique_ptr<WriteBatch> currentBatch_; std::unique_ptr<WriteBatch> currentBatch_;
unique_ptr<log::Reader> currentLogReader_; std::unique_ptr<log::Reader> currentLogReader_;
Status OpenLogFile(const LogFile* logFile, Status OpenLogFile(const LogFile* logFile,
unique_ptr<SequentialFileReader>* file); std::unique_ptr<SequentialFileReader>* file);
struct LogReporter : public log::Reader::Reporter { struct LogReporter : public log::Reader::Reporter {
Env* env; Env* env;

View File

@ -2939,14 +2939,14 @@ Status VersionSet::ProcessManifestWrites(
pending_manifest_file_number_); pending_manifest_file_number_);
std::string descriptor_fname = std::string descriptor_fname =
DescriptorFileName(dbname_, pending_manifest_file_number_); DescriptorFileName(dbname_, pending_manifest_file_number_);
unique_ptr<WritableFile> descriptor_file; std::unique_ptr<WritableFile> descriptor_file;
s = NewWritableFile(env_, descriptor_fname, &descriptor_file, s = NewWritableFile(env_, descriptor_fname, &descriptor_file,
opt_env_opts); opt_env_opts);
if (s.ok()) { if (s.ok()) {
descriptor_file->SetPreallocationBlockSize( descriptor_file->SetPreallocationBlockSize(
db_options_->manifest_preallocation_size); db_options_->manifest_preallocation_size);
unique_ptr<WritableFileWriter> file_writer(new WritableFileWriter( std::unique_ptr<WritableFileWriter> file_writer(new WritableFileWriter(
std::move(descriptor_file), descriptor_fname, opt_env_opts, nullptr, std::move(descriptor_file), descriptor_fname, opt_env_opts, nullptr,
db_options_->listeners)); db_options_->listeners));
descriptor_log_.reset( descriptor_log_.reset(
@ -3410,9 +3410,9 @@ Status VersionSet::Recover(
manifest_filename.c_str()); manifest_filename.c_str());
manifest_filename = dbname_ + "/" + manifest_filename; manifest_filename = dbname_ + "/" + manifest_filename;
unique_ptr<SequentialFileReader> manifest_file_reader; std::unique_ptr<SequentialFileReader> manifest_file_reader;
{ {
unique_ptr<SequentialFile> manifest_file; std::unique_ptr<SequentialFile> manifest_file;
s = env_->NewSequentialFile(manifest_filename, &manifest_file, s = env_->NewSequentialFile(manifest_filename, &manifest_file,
env_->OptimizeForManifestRead(env_options_)); env_->OptimizeForManifestRead(env_options_));
if (!s.ok()) { if (!s.ok()) {
@ -3660,9 +3660,9 @@ Status VersionSet::ListColumnFamilies(std::vector<std::string>* column_families,
std::string dscname = dbname + "/" + current; std::string dscname = dbname + "/" + current;
unique_ptr<SequentialFileReader> file_reader; std::unique_ptr<SequentialFileReader> file_reader;
{ {
unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
s = env->NewSequentialFile(dscname, &file, soptions); s = env->NewSequentialFile(dscname, &file, soptions);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
@ -3803,10 +3803,10 @@ Status VersionSet::ReduceNumberOfLevels(const std::string& dbname,
Status VersionSet::DumpManifest(Options& options, std::string& dscname, Status VersionSet::DumpManifest(Options& options, std::string& dscname,
bool verbose, bool hex, bool json) { bool verbose, bool hex, bool json) {
// Open the specified manifest file. // Open the specified manifest file.
unique_ptr<SequentialFileReader> file_reader; std::unique_ptr<SequentialFileReader> file_reader;
Status s; Status s;
{ {
unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
s = options.env->NewSequentialFile( s = options.env->NewSequentialFile(
dscname, &file, env_->OptimizeForManifestRead(env_options_)); dscname, &file, env_->OptimizeForManifestRead(env_options_));
if (!s.ok()) { if (!s.ok()) {

View File

@ -605,7 +605,7 @@ class Version {
// REQUIRES: lock is held // REQUIRES: lock is held
// On success, *props will be populated with all SSTables' table properties. // On success, *props will be populated with all SSTables' table properties.
// The keys of `props` are the sst file name, the values of `props` are the // The keys of `props` are the sst file name, the values of `props` are the
// tables' properties, represented as shared_ptr. // tables' properties, represented as std::shared_ptr.
Status GetPropertiesOfAllTables(TablePropertiesCollection* props); Status GetPropertiesOfAllTables(TablePropertiesCollection* props);
Status GetPropertiesOfAllTables(TablePropertiesCollection* props, int level); Status GetPropertiesOfAllTables(TablePropertiesCollection* props, int level);
Status GetPropertiesOfTablesInRange(const Range* range, std::size_t n, Status GetPropertiesOfTablesInRange(const Range* range, std::size_t n,
@ -1053,7 +1053,7 @@ class VersionSet {
uint64_t prev_log_number_; // 0 or backing store for memtable being compacted uint64_t prev_log_number_; // 0 or backing store for memtable being compacted
// Opened lazily // Opened lazily
unique_ptr<log::Writer> descriptor_log_; std::unique_ptr<log::Writer> descriptor_log_;
// generates a increasing version number for every new version // generates a increasing version number for every new version
uint64_t current_version_number_; uint64_t current_version_number_;

View File

@ -653,11 +653,11 @@ class VersionSetTest : public testing::Test {
*last_seqno = last_seq; *last_seqno = last_seq;
const std::string manifest = DescriptorFileName(dbname_, 1); const std::string manifest = DescriptorFileName(dbname_, 1);
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
Status s = env_->NewWritableFile( Status s = env_->NewWritableFile(
manifest, &file, env_->OptimizeForManifestWrite(env_options_)); manifest, &file, env_->OptimizeForManifestWrite(env_options_));
ASSERT_OK(s); ASSERT_OK(s);
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(file), manifest, env_options_)); new WritableFileWriter(std::move(file), manifest, env_options_));
{ {
log_writer->reset(new log::Writer(std::move(file_writer), 0, false)); log_writer->reset(new log::Writer(std::move(file_writer), 0, false));

View File

@ -443,7 +443,7 @@ Status WalManager::ReadFirstLine(const std::string& fname,
std::unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
Status status = env_->NewSequentialFile( Status status = env_->NewSequentialFile(
fname, &file, env_->OptimizeForLogRead(env_options_)); fname, &file, env_->OptimizeForLogRead(env_options_));
unique_ptr<SequentialFileReader> file_reader( std::unique_ptr<SequentialFileReader> file_reader(
new SequentialFileReader(std::move(file), fname)); new SequentialFileReader(std::move(file), fname));
if (!status.ok()) { if (!status.ok()) {

View File

@ -76,9 +76,9 @@ class WalManagerTest : public testing::Test {
void RollTheLog(bool /*archived*/) { void RollTheLog(bool /*archived*/) {
current_log_number_++; current_log_number_++;
std::string fname = ArchivedLogFileName(dbname_, current_log_number_); std::string fname = ArchivedLogFileName(dbname_, current_log_number_);
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
ASSERT_OK(env_->NewWritableFile(fname, &file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(file), fname, env_options_)); new WritableFileWriter(std::move(file), fname, env_options_));
current_log_writer_.reset(new log::Writer(std::move(file_writer), 0, false)); current_log_writer_.reset(new log::Writer(std::move(file_writer), 0, false));
} }
@ -94,7 +94,7 @@ class WalManagerTest : public testing::Test {
std::unique_ptr<TransactionLogIterator> OpenTransactionLogIter( std::unique_ptr<TransactionLogIterator> OpenTransactionLogIter(
const SequenceNumber seq) { const SequenceNumber seq) {
unique_ptr<TransactionLogIterator> iter; std::unique_ptr<TransactionLogIterator> iter;
Status status = wal_manager_->GetUpdatesSince( Status status = wal_manager_->GetUpdatesSince(
seq, &iter, TransactionLogIterator::ReadOptions(), versions_.get()); seq, &iter, TransactionLogIterator::ReadOptions(), versions_.get());
EXPECT_OK(status); EXPECT_OK(status);
@ -118,7 +118,7 @@ class WalManagerTest : public testing::Test {
TEST_F(WalManagerTest, ReadFirstRecordCache) { TEST_F(WalManagerTest, ReadFirstRecordCache) {
Init(); Init();
std::string path = dbname_ + "/000001.log"; std::string path = dbname_ + "/000001.log";
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
ASSERT_OK(env_->NewWritableFile(path, &file, EnvOptions())); ASSERT_OK(env_->NewWritableFile(path, &file, EnvOptions()));
SequenceNumber s; SequenceNumber s;
@ -129,7 +129,7 @@ TEST_F(WalManagerTest, ReadFirstRecordCache) {
wal_manager_->TEST_ReadFirstRecord(kAliveLogFile, 1 /* number */, &s)); wal_manager_->TEST_ReadFirstRecord(kAliveLogFile, 1 /* number */, &s));
ASSERT_EQ(s, 0U); ASSERT_EQ(s, 0U);
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(file), path, EnvOptions())); new WritableFileWriter(std::move(file), path, EnvOptions()));
log::Writer writer(std::move(file_writer), 1, log::Writer writer(std::move(file_writer), 1,
db_options_.recycle_log_file_num > 0); db_options_.recycle_log_file_num > 0);

View File

@ -1053,7 +1053,7 @@ class MemTableInserter : public WriteBatch::Handler {
// a map is too expensive in the Write() path as they // a map is too expensive in the Write() path as they
// cause memory allocations though unused. // cause memory allocations though unused.
// Make creation optional but do not incur // Make creation optional but do not incur
// unique_ptr additional allocation // std::unique_ptr additional allocation
using MemPostInfoMap = std::map<MemTable*, MemTablePostProcessInfo>; using MemPostInfoMap = std::map<MemTable*, MemTablePostProcessInfo>;
using PostMapType = std::aligned_storage<sizeof(MemPostInfoMap)>::type; using PostMapType = std::aligned_storage<sizeof(MemPostInfoMap)>::type;
PostMapType mem_post_info_map_; PostMapType mem_post_info_map_;

24
env/env.cc vendored
View File

@ -43,7 +43,7 @@ uint64_t Env::GetThreadID() const {
Status Env::ReuseWritableFile(const std::string& fname, Status Env::ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) { const EnvOptions& options) {
Status s = RenameFile(old_fname, fname); Status s = RenameFile(old_fname, fname);
if (!s.ok()) { if (!s.ok()) {
@ -242,11 +242,11 @@ void Fatal(Logger* info_log, const char* format, ...) {
va_end(ap); va_end(ap);
} }
void LogFlush(const shared_ptr<Logger>& info_log) { void LogFlush(const std::shared_ptr<Logger>& info_log) {
LogFlush(info_log.get()); LogFlush(info_log.get());
} }
void Log(const InfoLogLevel log_level, const shared_ptr<Logger>& info_log, void Log(const InfoLogLevel log_level, const std::shared_ptr<Logger>& info_log,
const char* format, ...) { const char* format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@ -254,49 +254,49 @@ void Log(const InfoLogLevel log_level, const shared_ptr<Logger>& info_log,
va_end(ap); va_end(ap);
} }
void Header(const shared_ptr<Logger>& info_log, const char* format, ...) { void Header(const std::shared_ptr<Logger>& info_log, const char* format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
Headerv(info_log.get(), format, ap); Headerv(info_log.get(), format, ap);
va_end(ap); va_end(ap);
} }
void Debug(const shared_ptr<Logger>& info_log, const char* format, ...) { void Debug(const std::shared_ptr<Logger>& info_log, const char* format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
Debugv(info_log.get(), format, ap); Debugv(info_log.get(), format, ap);
va_end(ap); va_end(ap);
} }
void Info(const shared_ptr<Logger>& info_log, const char* format, ...) { void Info(const std::shared_ptr<Logger>& info_log, const char* format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
Infov(info_log.get(), format, ap); Infov(info_log.get(), format, ap);
va_end(ap); va_end(ap);
} }
void Warn(const shared_ptr<Logger>& info_log, const char* format, ...) { void Warn(const std::shared_ptr<Logger>& info_log, const char* format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
Warnv(info_log.get(), format, ap); Warnv(info_log.get(), format, ap);
va_end(ap); va_end(ap);
} }
void Error(const shared_ptr<Logger>& info_log, const char* format, ...) { void Error(const std::shared_ptr<Logger>& info_log, const char* format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
Errorv(info_log.get(), format, ap); Errorv(info_log.get(), format, ap);
va_end(ap); va_end(ap);
} }
void Fatal(const shared_ptr<Logger>& info_log, const char* format, ...) { void Fatal(const std::shared_ptr<Logger>& info_log, const char* format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
Fatalv(info_log.get(), format, ap); Fatalv(info_log.get(), format, ap);
va_end(ap); va_end(ap);
} }
void Log(const shared_ptr<Logger>& info_log, const char* format, ...) { void Log(const std::shared_ptr<Logger>& info_log, const char* format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
Logv(info_log.get(), format, ap); Logv(info_log.get(), format, ap);
@ -305,7 +305,7 @@ void Log(const shared_ptr<Logger>& info_log, const char* format, ...) {
Status WriteStringToFile(Env* env, const Slice& data, const std::string& fname, Status WriteStringToFile(Env* env, const Slice& data, const std::string& fname,
bool should_sync) { bool should_sync) {
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
EnvOptions soptions; EnvOptions soptions;
Status s = env->NewWritableFile(fname, &file, soptions); Status s = env->NewWritableFile(fname, &file, soptions);
if (!s.ok()) { if (!s.ok()) {
@ -324,7 +324,7 @@ Status WriteStringToFile(Env* env, const Slice& data, const std::string& fname,
Status ReadFileToString(Env* env, const std::string& fname, std::string* data) { Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
EnvOptions soptions; EnvOptions soptions;
data->clear(); data->clear();
unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
Status s = env->NewSequentialFile(fname, &file, soptions); Status s = env->NewSequentialFile(fname, &file, soptions);
if (!s.ok()) { if (!s.ok()) {
return s; return s;

20
env/env_basic_test.cc vendored
View File

@ -133,7 +133,7 @@ INSTANTIATE_TEST_CASE_P(CustomEnv, EnvMoreTestWithParam,
TEST_P(EnvBasicTestWithParam, Basics) { TEST_P(EnvBasicTestWithParam, Basics) {
uint64_t file_size; uint64_t file_size;
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
std::vector<std::string> children; std::vector<std::string> children;
// Check that the directory is empty. // Check that the directory is empty.
@ -186,8 +186,8 @@ TEST_P(EnvBasicTestWithParam, Basics) {
ASSERT_EQ(0U, file_size); ASSERT_EQ(0U, file_size);
// Check that opening non-existent file fails. // Check that opening non-existent file fails.
unique_ptr<SequentialFile> seq_file; std::unique_ptr<SequentialFile> seq_file;
unique_ptr<RandomAccessFile> rand_file; std::unique_ptr<RandomAccessFile> rand_file;
ASSERT_TRUE(!env_->NewSequentialFile(test_dir_ + "/non_existent", &seq_file, ASSERT_TRUE(!env_->NewSequentialFile(test_dir_ + "/non_existent", &seq_file,
soptions_) soptions_)
.ok()); .ok());
@ -208,9 +208,9 @@ TEST_P(EnvBasicTestWithParam, Basics) {
} }
TEST_P(EnvBasicTestWithParam, ReadWrite) { TEST_P(EnvBasicTestWithParam, ReadWrite) {
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
unique_ptr<SequentialFile> seq_file; std::unique_ptr<SequentialFile> seq_file;
unique_ptr<RandomAccessFile> rand_file; std::unique_ptr<RandomAccessFile> rand_file;
Slice result; Slice result;
char scratch[100]; char scratch[100];
@ -247,7 +247,7 @@ TEST_P(EnvBasicTestWithParam, ReadWrite) {
} }
TEST_P(EnvBasicTestWithParam, Misc) { TEST_P(EnvBasicTestWithParam, Misc) {
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
ASSERT_OK(env_->NewWritableFile(test_dir_ + "/b", &writable_file, soptions_)); ASSERT_OK(env_->NewWritableFile(test_dir_ + "/b", &writable_file, soptions_));
// These are no-ops, but we test they return success. // These are no-ops, but we test they return success.
@ -266,14 +266,14 @@ TEST_P(EnvBasicTestWithParam, LargeWrite) {
write_data.append(1, static_cast<char>(i)); write_data.append(1, static_cast<char>(i));
} }
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
ASSERT_OK(env_->NewWritableFile(test_dir_ + "/f", &writable_file, soptions_)); ASSERT_OK(env_->NewWritableFile(test_dir_ + "/f", &writable_file, soptions_));
ASSERT_OK(writable_file->Append("foo")); ASSERT_OK(writable_file->Append("foo"));
ASSERT_OK(writable_file->Append(write_data)); ASSERT_OK(writable_file->Append(write_data));
ASSERT_OK(writable_file->Close()); ASSERT_OK(writable_file->Close());
writable_file.reset(); writable_file.reset();
unique_ptr<SequentialFile> seq_file; std::unique_ptr<SequentialFile> seq_file;
Slice result; Slice result;
ASSERT_OK(env_->NewSequentialFile(test_dir_ + "/f", &seq_file, soptions_)); ASSERT_OK(env_->NewSequentialFile(test_dir_ + "/f", &seq_file, soptions_));
ASSERT_OK(seq_file->Read(3, &result, scratch)); // Read "foo". ASSERT_OK(seq_file->Read(3, &result, scratch)); // Read "foo".
@ -340,7 +340,7 @@ TEST_P(EnvMoreTestWithParam, GetChildren) {
// if dir is a file, returns IOError // if dir is a file, returns IOError
ASSERT_OK(env_->CreateDir(test_dir_)); ASSERT_OK(env_->CreateDir(test_dir_));
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
ASSERT_OK( ASSERT_OK(
env_->NewWritableFile(test_dir_ + "/file", &writable_file, soptions_)); env_->NewWritableFile(test_dir_ + "/file", &writable_file, soptions_));
ASSERT_OK(writable_file->Close()); ASSERT_OK(writable_file->Close());

12
env/env_chroot.cc vendored
View File

@ -50,7 +50,7 @@ class ChrootEnv : public EnvWrapper {
} }
virtual Status NewRandomAccessFile(const std::string& fname, virtual Status NewRandomAccessFile(const std::string& fname,
unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -61,7 +61,7 @@ class ChrootEnv : public EnvWrapper {
} }
virtual Status NewWritableFile(const std::string& fname, virtual Status NewWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -73,7 +73,7 @@ class ChrootEnv : public EnvWrapper {
virtual Status ReuseWritableFile(const std::string& fname, virtual Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -89,7 +89,7 @@ class ChrootEnv : public EnvWrapper {
} }
virtual Status NewRandomRWFile(const std::string& fname, virtual Status NewRandomRWFile(const std::string& fname,
unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
@ -100,7 +100,7 @@ class ChrootEnv : public EnvWrapper {
} }
virtual Status NewDirectory(const std::string& dir, virtual Status NewDirectory(const std::string& dir,
unique_ptr<Directory>* result) override { std::unique_ptr<Directory>* result) override {
auto status_and_enc_path = EncodePathWithNewBasename(dir); auto status_and_enc_path = EncodePathWithNewBasename(dir);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;
@ -238,7 +238,7 @@ class ChrootEnv : public EnvWrapper {
} }
virtual Status NewLogger(const std::string& fname, virtual Status NewLogger(const std::string& fname,
shared_ptr<Logger>* result) override { std::shared_ptr<Logger>* result) override {
auto status_and_enc_path = EncodePathWithNewBasename(fname); auto status_and_enc_path = EncodePathWithNewBasename(fname);
if (!status_and_enc_path.first.ok()) { if (!status_and_enc_path.first.ok()) {
return status_and_enc_path.first; return status_and_enc_path.first;

27
env/env_encryption.cc vendored
View File

@ -422,7 +422,7 @@ class EncryptedEnv : public EnvWrapper {
// NewRandomAccessFile opens a file for random read access. // NewRandomAccessFile opens a file for random read access.
virtual Status NewRandomAccessFile(const std::string& fname, virtual Status NewRandomAccessFile(const std::string& fname,
unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
if (options.use_mmap_reads) { if (options.use_mmap_reads) {
@ -459,7 +459,7 @@ class EncryptedEnv : public EnvWrapper {
// NewWritableFile opens a file for sequential writing. // NewWritableFile opens a file for sequential writing.
virtual Status NewWritableFile(const std::string& fname, virtual Status NewWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
if (options.use_mmap_writes) { if (options.use_mmap_writes) {
@ -505,7 +505,7 @@ class EncryptedEnv : public EnvWrapper {
// //
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status ReopenWritableFile(const std::string& fname, virtual Status ReopenWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
if (options.use_mmap_writes) { if (options.use_mmap_writes) {
@ -546,7 +546,7 @@ class EncryptedEnv : public EnvWrapper {
// Reuse an existing file by renaming it and opening it as writable. // Reuse an existing file by renaming it and opening it as writable.
virtual Status ReuseWritableFile(const std::string& fname, virtual Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
if (options.use_mmap_writes) { if (options.use_mmap_writes) {
@ -590,7 +590,7 @@ class EncryptedEnv : public EnvWrapper {
// //
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status NewRandomRWFile(const std::string& fname, virtual Status NewRandomRWFile(const std::string& fname,
unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
if (options.use_mmap_reads || options.use_mmap_writes) { if (options.use_mmap_reads || options.use_mmap_writes) {
@ -692,7 +692,7 @@ Status BlockAccessCipherStream::Encrypt(uint64_t fileOffset, char *data, size_t
auto blockSize = BlockSize(); auto blockSize = BlockSize();
uint64_t blockIndex = fileOffset / blockSize; uint64_t blockIndex = fileOffset / blockSize;
size_t blockOffset = fileOffset % blockSize; size_t blockOffset = fileOffset % blockSize;
unique_ptr<char[]> blockBuffer; std::unique_ptr<char[]> blockBuffer;
std::string scratch; std::string scratch;
AllocateScratch(scratch); AllocateScratch(scratch);
@ -706,7 +706,7 @@ Status BlockAccessCipherStream::Encrypt(uint64_t fileOffset, char *data, size_t
// Copy data to blockBuffer // Copy data to blockBuffer
if (!blockBuffer.get()) { if (!blockBuffer.get()) {
// Allocate buffer // Allocate buffer
blockBuffer = unique_ptr<char[]>(new char[blockSize]); blockBuffer = std::unique_ptr<char[]>(new char[blockSize]);
} }
block = blockBuffer.get(); block = blockBuffer.get();
// Copy plain data to block buffer // Copy plain data to block buffer
@ -737,7 +737,7 @@ Status BlockAccessCipherStream::Decrypt(uint64_t fileOffset, char *data, size_t
auto blockSize = BlockSize(); auto blockSize = BlockSize();
uint64_t blockIndex = fileOffset / blockSize; uint64_t blockIndex = fileOffset / blockSize;
size_t blockOffset = fileOffset % blockSize; size_t blockOffset = fileOffset % blockSize;
unique_ptr<char[]> blockBuffer; std::unique_ptr<char[]> blockBuffer;
std::string scratch; std::string scratch;
AllocateScratch(scratch); AllocateScratch(scratch);
@ -751,7 +751,7 @@ Status BlockAccessCipherStream::Decrypt(uint64_t fileOffset, char *data, size_t
// Copy data to blockBuffer // Copy data to blockBuffer
if (!blockBuffer.get()) { if (!blockBuffer.get()) {
// Allocate buffer // Allocate buffer
blockBuffer = unique_ptr<char[]>(new char[blockSize]); blockBuffer = std::unique_ptr<char[]>(new char[blockSize]);
} }
block = blockBuffer.get(); block = blockBuffer.get();
// Copy encrypted data to block buffer // Copy encrypted data to block buffer
@ -882,7 +882,9 @@ size_t CTREncryptionProvider::PopulateSecretPrefixPart(char* /*prefix*/,
return 0; return 0;
} }
Status CTREncryptionProvider::CreateCipherStream(const std::string& fname, const EnvOptions& options, Slice &prefix, unique_ptr<BlockAccessCipherStream>* result) { Status CTREncryptionProvider::CreateCipherStream(
const std::string& fname, const EnvOptions& options, Slice& prefix,
std::unique_ptr<BlockAccessCipherStream>* result) {
// Read plain text part of prefix. // Read plain text part of prefix.
auto blockSize = cipher_.BlockSize(); auto blockSize = cipher_.BlockSize();
uint64_t initialCounter; uint64_t initialCounter;
@ -905,8 +907,9 @@ Status CTREncryptionProvider::CreateCipherStream(const std::string& fname, const
Status CTREncryptionProvider::CreateCipherStreamFromPrefix( Status CTREncryptionProvider::CreateCipherStreamFromPrefix(
const std::string& /*fname*/, const EnvOptions& /*options*/, const std::string& /*fname*/, const EnvOptions& /*options*/,
uint64_t initialCounter, const Slice& iv, const Slice& /*prefix*/, uint64_t initialCounter, const Slice& iv, const Slice& /*prefix*/,
unique_ptr<BlockAccessCipherStream>* result) { std::unique_ptr<BlockAccessCipherStream>* result) {
(*result) = unique_ptr<BlockAccessCipherStream>(new CTRCipherStream(cipher_, iv.data(), initialCounter)); (*result) = std::unique_ptr<BlockAccessCipherStream>(
new CTRCipherStream(cipher_, iv.data(), initialCounter));
return Status::OK(); return Status::OK();
} }

14
env/env_hdfs.cc vendored
View File

@ -381,7 +381,7 @@ const std::string HdfsEnv::pathsep = "/";
// open a file for sequential reading // open a file for sequential reading
Status HdfsEnv::NewSequentialFile(const std::string& fname, Status HdfsEnv::NewSequentialFile(const std::string& fname,
unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) { const EnvOptions& options) {
result->reset(); result->reset();
HdfsReadableFile* f = new HdfsReadableFile(fileSys_, fname); HdfsReadableFile* f = new HdfsReadableFile(fileSys_, fname);
@ -396,7 +396,7 @@ Status HdfsEnv::NewSequentialFile(const std::string& fname,
// open a file for random reading // open a file for random reading
Status HdfsEnv::NewRandomAccessFile(const std::string& fname, Status HdfsEnv::NewRandomAccessFile(const std::string& fname,
unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) { const EnvOptions& options) {
result->reset(); result->reset();
HdfsReadableFile* f = new HdfsReadableFile(fileSys_, fname); HdfsReadableFile* f = new HdfsReadableFile(fileSys_, fname);
@ -411,7 +411,7 @@ Status HdfsEnv::NewRandomAccessFile(const std::string& fname,
// create a new file for writing // create a new file for writing
Status HdfsEnv::NewWritableFile(const std::string& fname, Status HdfsEnv::NewWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) { const EnvOptions& options) {
result->reset(); result->reset();
Status s; Status s;
@ -437,7 +437,7 @@ class HdfsDirectory : public Directory {
}; };
Status HdfsEnv::NewDirectory(const std::string& name, Status HdfsEnv::NewDirectory(const std::string& name,
unique_ptr<Directory>* result) { std::unique_ptr<Directory>* result) {
int value = hdfsExists(fileSys_, name.c_str()); int value = hdfsExists(fileSys_, name.c_str());
switch (value) { switch (value) {
case HDFS_EXISTS: case HDFS_EXISTS:
@ -581,7 +581,7 @@ Status HdfsEnv::UnlockFile(FileLock* lock) {
} }
Status HdfsEnv::NewLogger(const std::string& fname, Status HdfsEnv::NewLogger(const std::string& fname,
shared_ptr<Logger>* result) { std::shared_ptr<Logger>* result) {
HdfsWritableFile* f = new HdfsWritableFile(fileSys_, fname); HdfsWritableFile* f = new HdfsWritableFile(fileSys_, fname);
if (f == nullptr || !f->isValid()) { if (f == nullptr || !f->isValid()) {
delete f; delete f;
@ -610,10 +610,10 @@ Status NewHdfsEnv(Env** hdfs_env, const std::string& fsname) {
// dummy placeholders used when HDFS is not available // dummy placeholders used when HDFS is not available
namespace rocksdb { namespace rocksdb {
Status HdfsEnv::NewSequentialFile(const std::string& /*fname*/, Status HdfsEnv::NewSequentialFile(const std::string& /*fname*/,
unique_ptr<SequentialFile>* /*result*/, std::unique_ptr<SequentialFile>* /*result*/,
const EnvOptions& /*options*/) { const EnvOptions& /*options*/) {
return Status::NotSupported("Not compiled with hdfs support"); return Status::NotSupported("Not compiled with hdfs support");
} }
Status NewHdfsEnv(Env** /*hdfs_env*/, const std::string& /*fsname*/) { Status NewHdfsEnv(Env** /*hdfs_env*/, const std::string& /*fsname*/) {
return Status::NotSupported("Not compiled with hdfs support"); return Status::NotSupported("Not compiled with hdfs support");

20
env/env_posix.cc vendored
View File

@ -142,7 +142,7 @@ class PosixEnv : public Env {
} }
virtual Status NewSequentialFile(const std::string& fname, virtual Status NewSequentialFile(const std::string& fname,
unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
int fd = -1; int fd = -1;
@ -192,7 +192,7 @@ class PosixEnv : public Env {
} }
virtual Status NewRandomAccessFile(const std::string& fname, virtual Status NewRandomAccessFile(const std::string& fname,
unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
Status s; Status s;
@ -249,7 +249,7 @@ class PosixEnv : public Env {
} }
virtual Status OpenWritableFile(const std::string& fname, virtual Status OpenWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options, const EnvOptions& options,
bool reopen = false) { bool reopen = false) {
result->reset(); result->reset();
@ -333,20 +333,20 @@ class PosixEnv : public Env {
} }
virtual Status NewWritableFile(const std::string& fname, virtual Status NewWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
return OpenWritableFile(fname, result, options, false); return OpenWritableFile(fname, result, options, false);
} }
virtual Status ReopenWritableFile(const std::string& fname, virtual Status ReopenWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
return OpenWritableFile(fname, result, options, true); return OpenWritableFile(fname, result, options, true);
} }
virtual Status ReuseWritableFile(const std::string& fname, virtual Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
result->reset(); result->reset();
Status s; Status s;
@ -430,7 +430,7 @@ class PosixEnv : public Env {
} }
virtual Status NewRandomRWFile(const std::string& fname, virtual Status NewRandomRWFile(const std::string& fname,
unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
int fd = -1; int fd = -1;
int flags = cloexec_flags(O_RDWR, &options); int flags = cloexec_flags(O_RDWR, &options);
@ -455,7 +455,7 @@ class PosixEnv : public Env {
virtual Status NewMemoryMappedFileBuffer( virtual Status NewMemoryMappedFileBuffer(
const std::string& fname, const std::string& fname,
unique_ptr<MemoryMappedFileBuffer>* result) override { std::unique_ptr<MemoryMappedFileBuffer>* result) override {
int fd = -1; int fd = -1;
Status status; Status status;
int flags = cloexec_flags(O_RDWR, nullptr); int flags = cloexec_flags(O_RDWR, nullptr);
@ -497,7 +497,7 @@ class PosixEnv : public Env {
} }
virtual Status NewDirectory(const std::string& name, virtual Status NewDirectory(const std::string& name,
unique_ptr<Directory>* result) override { std::unique_ptr<Directory>* result) override {
result->reset(); result->reset();
int fd; int fd;
int flags = cloexec_flags(0, nullptr); int flags = cloexec_flags(0, nullptr);
@ -791,7 +791,7 @@ class PosixEnv : public Env {
} }
virtual Status NewLogger(const std::string& fname, virtual Status NewLogger(const std::string& fname,
shared_ptr<Logger>* result) override { std::shared_ptr<Logger>* result) override {
FILE* f; FILE* f;
{ {
IOSTATS_TIMER_GUARD(open_nanos); IOSTATS_TIMER_GUARD(open_nanos);

42
env/env_test.cc vendored
View File

@ -181,11 +181,11 @@ TEST_F(EnvPosixTest, DISABLED_FilePermission) {
std::vector<std::string> fileNames{ std::vector<std::string> fileNames{
test::PerThreadDBPath(env_, "testfile"), test::PerThreadDBPath(env_, "testfile"),
test::PerThreadDBPath(env_, "testfile1")}; test::PerThreadDBPath(env_, "testfile1")};
unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
ASSERT_OK(env_->NewWritableFile(fileNames[0], &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fileNames[0], &wfile, soptions));
ASSERT_OK(env_->NewWritableFile(fileNames[1], &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fileNames[1], &wfile, soptions));
wfile.reset(); wfile.reset();
unique_ptr<RandomRWFile> rwfile; std::unique_ptr<RandomRWFile> rwfile;
ASSERT_OK(env_->NewRandomRWFile(fileNames[1], &rwfile, soptions)); ASSERT_OK(env_->NewRandomRWFile(fileNames[1], &rwfile, soptions));
struct stat sb; struct stat sb;
@ -217,7 +217,7 @@ TEST_F(EnvPosixTest, MemoryMappedFileBuffer) {
std::string expected_data; std::string expected_data;
std::string fname = test::PerThreadDBPath(env_, "testfile"); std::string fname = test::PerThreadDBPath(env_, "testfile");
{ {
unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
const EnvOptions soptions; const EnvOptions soptions;
ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions));
@ -812,7 +812,7 @@ class IoctlFriendlyTmpdir {
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
TEST_F(EnvPosixTest, PositionedAppend) { TEST_F(EnvPosixTest, PositionedAppend) {
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
EnvOptions options; EnvOptions options;
options.use_direct_writes = true; options.use_direct_writes = true;
options.use_mmap_writes = false; options.use_mmap_writes = false;
@ -832,7 +832,7 @@ TEST_F(EnvPosixTest, PositionedAppend) {
// The file now has 1 sector worth of a followed by a page worth of b // The file now has 1 sector worth of a followed by a page worth of b
// Verify the above // Verify the above
unique_ptr<SequentialFile> seq_file; std::unique_ptr<SequentialFile> seq_file;
ASSERT_OK(env_->NewSequentialFile(ift.name() + "/f", &seq_file, options)); ASSERT_OK(env_->NewSequentialFile(ift.name() + "/f", &seq_file, options));
char scratch[kPageSize * 2]; char scratch[kPageSize * 2];
Slice result; Slice result;
@ -851,10 +851,10 @@ TEST_P(EnvPosixTestWithParam, RandomAccessUniqueID) {
soptions.use_direct_reads = soptions.use_direct_writes = direct_io_; soptions.use_direct_reads = soptions.use_direct_writes = direct_io_;
IoctlFriendlyTmpdir ift; IoctlFriendlyTmpdir ift;
std::string fname = ift.name() + "/testfile"; std::string fname = ift.name() + "/testfile";
unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions));
unique_ptr<RandomAccessFile> file; std::unique_ptr<RandomAccessFile> file;
// Get Unique ID // Get Unique ID
ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions)); ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions));
@ -921,7 +921,7 @@ TEST_P(EnvPosixTestWithParam, AllocateTest) {
EnvOptions soptions; EnvOptions soptions;
soptions.use_mmap_writes = false; soptions.use_mmap_writes = false;
soptions.use_direct_reads = soptions.use_direct_writes = direct_io_; soptions.use_direct_reads = soptions.use_direct_writes = direct_io_;
unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions));
// allocate 100 MB // allocate 100 MB
@ -990,14 +990,14 @@ TEST_P(EnvPosixTestWithParam, RandomAccessUniqueIDConcurrent) {
fnames.push_back(ift.name() + "/" + "testfile" + ToString(i)); fnames.push_back(ift.name() + "/" + "testfile" + ToString(i));
// Create file. // Create file.
unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
ASSERT_OK(env_->NewWritableFile(fnames[i], &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fnames[i], &wfile, soptions));
} }
// Collect and check whether the IDs are unique. // Collect and check whether the IDs are unique.
std::unordered_set<std::string> ids; std::unordered_set<std::string> ids;
for (const std::string fname : fnames) { for (const std::string fname : fnames) {
unique_ptr<RandomAccessFile> file; std::unique_ptr<RandomAccessFile> file;
std::string unique_id; std::string unique_id;
ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions)); ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions));
size_t id_size = file->GetUniqueId(temp_id, MAX_ID_SIZE); size_t id_size = file->GetUniqueId(temp_id, MAX_ID_SIZE);
@ -1033,14 +1033,14 @@ TEST_P(EnvPosixTestWithParam, RandomAccessUniqueIDDeletes) {
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
// Create file. // Create file.
{ {
unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions));
} }
// Get Unique ID // Get Unique ID
std::string unique_id; std::string unique_id;
{ {
unique_ptr<RandomAccessFile> file; std::unique_ptr<RandomAccessFile> file;
ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions)); ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions));
size_t id_size = file->GetUniqueId(temp_id, MAX_ID_SIZE); size_t id_size = file->GetUniqueId(temp_id, MAX_ID_SIZE);
ASSERT_TRUE(id_size > 0); ASSERT_TRUE(id_size > 0);
@ -1076,7 +1076,7 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
// Create file. // Create file.
{ {
unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX)
if (soptions.use_direct_writes) { if (soptions.use_direct_writes) {
soptions.use_direct_writes = false; soptions.use_direct_writes = false;
@ -1090,7 +1090,7 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
// Random Read // Random Read
{ {
unique_ptr<RandomAccessFile> file; std::unique_ptr<RandomAccessFile> file;
auto scratch = NewAligned(kSectorSize, 0); auto scratch = NewAligned(kSectorSize, 0);
Slice result; Slice result;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX)
@ -1107,7 +1107,7 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
// Sequential Read // Sequential Read
{ {
unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
auto scratch = NewAligned(kSectorSize, 0); auto scratch = NewAligned(kSectorSize, 0);
Slice result; Slice result;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX)
@ -1252,7 +1252,7 @@ TEST_P(EnvPosixTestWithParam, LogBufferMaxSizeTest) {
TEST_P(EnvPosixTestWithParam, Preallocation) { TEST_P(EnvPosixTestWithParam, Preallocation) {
rocksdb::SyncPoint::GetInstance()->EnableProcessing(); rocksdb::SyncPoint::GetInstance()->EnableProcessing();
const std::string src = test::PerThreadDBPath(env_, "testfile"); const std::string src = test::PerThreadDBPath(env_, "testfile");
unique_ptr<WritableFile> srcfile; std::unique_ptr<WritableFile> srcfile;
EnvOptions soptions; EnvOptions soptions;
soptions.use_direct_reads = soptions.use_direct_writes = direct_io_; soptions.use_direct_reads = soptions.use_direct_writes = direct_io_;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD) #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD)
@ -1315,7 +1315,7 @@ TEST_P(EnvPosixTestWithParam, ConsistentChildrenAttributes) {
for (int i = 0; i < kNumChildren; ++i) { for (int i = 0; i < kNumChildren; ++i) {
const std::string path = const std::string path =
test::TmpDir(env_) + "/" + "testfile_" + std::to_string(i); test::TmpDir(env_) + "/" + "testfile_" + std::to_string(i);
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD) #if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD)
if (soptions.use_direct_writes) { if (soptions.use_direct_writes) {
rocksdb::SyncPoint::GetInstance()->SetCallBack( rocksdb::SyncPoint::GetInstance()->SetCallBack(
@ -1638,7 +1638,7 @@ TEST_P(EnvPosixTestWithParam, PosixRandomRWFileRandomized) {
const std::string path = test::PerThreadDBPath(env_, "random_rw_file_rand"); const std::string path = test::PerThreadDBPath(env_, "random_rw_file_rand");
env_->DeleteFile(path); env_->DeleteFile(path);
unique_ptr<RandomRWFile> file; std::unique_ptr<RandomRWFile> file;
#ifdef OS_LINUX #ifdef OS_LINUX
// Cannot open non-existing file. // Cannot open non-existing file.
@ -1712,7 +1712,7 @@ class TestEnv : public EnvWrapper {
int GetCloseCount() { return close_count; } int GetCloseCount() { return close_count; }
virtual Status NewLogger(const std::string& /*fname*/, virtual Status NewLogger(const std::string& /*fname*/,
shared_ptr<Logger>* result) { std::shared_ptr<Logger>* result) {
result->reset(new TestLogger(this)); result->reset(new TestLogger(this));
return Status::OK(); return Status::OK();
} }
@ -1756,8 +1756,8 @@ INSTANTIATE_TEST_CASE_P(DefaultEnvWithDirectIO, EnvPosixTestWithParam,
#endif // !defined(ROCKSDB_LITE) #endif // !defined(ROCKSDB_LITE)
#if !defined(ROCKSDB_LITE) && !defined(OS_WIN) #if !defined(ROCKSDB_LITE) && !defined(OS_WIN)
static unique_ptr<Env> chroot_env(NewChrootEnv(Env::Default(), static std::unique_ptr<Env> chroot_env(
test::TmpDir(Env::Default()))); NewChrootEnv(Env::Default(), test::TmpDir(Env::Default())));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
ChrootEnvWithoutDirectIO, EnvPosixTestWithParam, ChrootEnvWithoutDirectIO, EnvPosixTestWithParam,
::testing::Values(std::pair<Env*, bool>(chroot_env.get(), false))); ::testing::Values(std::pair<Env*, bool>(chroot_env.get(), false)));

14
env/mock_env.cc vendored
View File

@ -424,7 +424,7 @@ MockEnv::~MockEnv() {
// Partial implementation of the Env interface. // Partial implementation of the Env interface.
Status MockEnv::NewSequentialFile(const std::string& fname, Status MockEnv::NewSequentialFile(const std::string& fname,
unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& /*soptions*/) { const EnvOptions& /*soptions*/) {
auto fn = NormalizePath(fname); auto fn = NormalizePath(fname);
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
@ -441,7 +441,7 @@ Status MockEnv::NewSequentialFile(const std::string& fname,
} }
Status MockEnv::NewRandomAccessFile(const std::string& fname, Status MockEnv::NewRandomAccessFile(const std::string& fname,
unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& /*soptions*/) { const EnvOptions& /*soptions*/) {
auto fn = NormalizePath(fname); auto fn = NormalizePath(fname);
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
@ -458,7 +458,7 @@ Status MockEnv::NewRandomAccessFile(const std::string& fname,
} }
Status MockEnv::NewRandomRWFile(const std::string& fname, Status MockEnv::NewRandomRWFile(const std::string& fname,
unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& /*soptions*/) { const EnvOptions& /*soptions*/) {
auto fn = NormalizePath(fname); auto fn = NormalizePath(fname);
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
@ -476,7 +476,7 @@ Status MockEnv::NewRandomRWFile(const std::string& fname,
Status MockEnv::ReuseWritableFile(const std::string& fname, Status MockEnv::ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) { const EnvOptions& options) {
auto s = RenameFile(old_fname, fname); auto s = RenameFile(old_fname, fname);
if (!s.ok()) { if (!s.ok()) {
@ -487,7 +487,7 @@ Status MockEnv::ReuseWritableFile(const std::string& fname,
} }
Status MockEnv::NewWritableFile(const std::string& fname, Status MockEnv::NewWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& env_options) { const EnvOptions& env_options) {
auto fn = NormalizePath(fname); auto fn = NormalizePath(fname);
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
@ -503,7 +503,7 @@ Status MockEnv::NewWritableFile(const std::string& fname,
} }
Status MockEnv::NewDirectory(const std::string& /*name*/, Status MockEnv::NewDirectory(const std::string& /*name*/,
unique_ptr<Directory>* result) { std::unique_ptr<Directory>* result) {
result->reset(new MockEnvDirectory()); result->reset(new MockEnvDirectory());
return Status::OK(); return Status::OK();
} }
@ -660,7 +660,7 @@ Status MockEnv::LinkFile(const std::string& src, const std::string& dest) {
} }
Status MockEnv::NewLogger(const std::string& fname, Status MockEnv::NewLogger(const std::string& fname,
shared_ptr<Logger>* result) { std::shared_ptr<Logger>* result) {
auto fn = NormalizePath(fname); auto fn = NormalizePath(fname);
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
auto iter = file_map_.find(fn); auto iter = file_map_.find(fn);

14
env/mock_env.h vendored
View File

@ -28,28 +28,28 @@ class MockEnv : public EnvWrapper {
// Partial implementation of the Env interface. // Partial implementation of the Env interface.
virtual Status NewSequentialFile(const std::string& fname, virtual Status NewSequentialFile(const std::string& fname,
unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& soptions) override; const EnvOptions& soptions) override;
virtual Status NewRandomAccessFile(const std::string& fname, virtual Status NewRandomAccessFile(const std::string& fname,
unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& soptions) override; const EnvOptions& soptions) override;
virtual Status NewRandomRWFile(const std::string& fname, virtual Status NewRandomRWFile(const std::string& fname,
unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override; const EnvOptions& options) override;
virtual Status ReuseWritableFile(const std::string& fname, virtual Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override; const EnvOptions& options) override;
virtual Status NewWritableFile(const std::string& fname, virtual Status NewWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& env_options) override; const EnvOptions& env_options) override;
virtual Status NewDirectory(const std::string& name, virtual Status NewDirectory(const std::string& name,
unique_ptr<Directory>* result) override; std::unique_ptr<Directory>* result) override;
virtual Status FileExists(const std::string& fname) override; virtual Status FileExists(const std::string& fname) override;
@ -81,7 +81,7 @@ class MockEnv : public EnvWrapper {
const std::string& target) override; const std::string& target) override;
virtual Status NewLogger(const std::string& fname, virtual Status NewLogger(const std::string& fname,
shared_ptr<Logger>* result) override; std::shared_ptr<Logger>* result) override;
virtual Status LockFile(const std::string& fname, FileLock** flock) override; virtual Status LockFile(const std::string& fname, FileLock** flock) override;

View File

@ -29,7 +29,7 @@ TEST_F(MockEnvTest, Corrupt) {
const std::string kGood = "this is a good string, synced to disk"; const std::string kGood = "this is a good string, synced to disk";
const std::string kCorrupted = "this part may be corrupted"; const std::string kCorrupted = "this part may be corrupted";
const std::string kFileName = "/dir/f"; const std::string kFileName = "/dir/f";
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
ASSERT_OK(env_->NewWritableFile(kFileName, &writable_file, soptions_)); ASSERT_OK(env_->NewWritableFile(kFileName, &writable_file, soptions_));
ASSERT_OK(writable_file->Append(kGood)); ASSERT_OK(writable_file->Append(kGood));
ASSERT_TRUE(writable_file->GetFileSize() == kGood.size()); ASSERT_TRUE(writable_file->GetFileSize() == kGood.size());
@ -37,7 +37,7 @@ TEST_F(MockEnvTest, Corrupt) {
std::string scratch; std::string scratch;
scratch.resize(kGood.size() + kCorrupted.size() + 16); scratch.resize(kGood.size() + kCorrupted.size() + 16);
Slice result; Slice result;
unique_ptr<RandomAccessFile> rand_file; std::unique_ptr<RandomAccessFile> rand_file;
ASSERT_OK(env_->NewRandomAccessFile(kFileName, &rand_file, soptions_)); ASSERT_OK(env_->NewRandomAccessFile(kFileName, &rand_file, soptions_));
ASSERT_OK(rand_file->Read(0, kGood.size(), &result, &(scratch[0]))); ASSERT_OK(rand_file->Read(0, kGood.size(), &result, &(scratch[0])));
ASSERT_EQ(result.compare(kGood), 0); ASSERT_EQ(result.compare(kGood), 0);

View File

@ -255,23 +255,24 @@ class HdfsEnv : public Env {
} }
virtual Status NewSequentialFile(const std::string& fname, virtual Status NewSequentialFile(const std::string& fname,
unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) override; const EnvOptions& options) override;
virtual Status NewRandomAccessFile(const std::string& /*fname*/, virtual Status NewRandomAccessFile(
unique_ptr<RandomAccessFile>* /*result*/, const std::string& /*fname*/,
std::unique_ptr<RandomAccessFile>* /*result*/,
const EnvOptions& /*options*/) override { const EnvOptions& /*options*/) override {
return notsup; return notsup;
} }
virtual Status NewWritableFile(const std::string& /*fname*/, virtual Status NewWritableFile(const std::string& /*fname*/,
unique_ptr<WritableFile>* /*result*/, std::unique_ptr<WritableFile>* /*result*/,
const EnvOptions& /*options*/) override { const EnvOptions& /*options*/) override {
return notsup; return notsup;
} }
virtual Status NewDirectory(const std::string& /*name*/, virtual Status NewDirectory(const std::string& /*name*/,
unique_ptr<Directory>* /*result*/) override { std::unique_ptr<Directory>* /*result*/) override {
return notsup; return notsup;
} }
@ -328,7 +329,7 @@ class HdfsEnv : public Env {
virtual Status UnlockFile(FileLock* /*lock*/) override { return notsup; } virtual Status UnlockFile(FileLock* /*lock*/) override { return notsup; }
virtual Status NewLogger(const std::string& /*fname*/, virtual Status NewLogger(const std::string& /*fname*/,
shared_ptr<Logger>* /*result*/) override { std::shared_ptr<Logger>* /*result*/) override {
return notsup; return notsup;
} }

View File

@ -996,9 +996,9 @@ class DB {
// cleared aggressively and the iterator might keep getting invalid before // cleared aggressively and the iterator might keep getting invalid before
// an update is read. // an update is read.
virtual Status GetUpdatesSince( virtual Status GetUpdatesSince(
SequenceNumber seq_number, unique_ptr<TransactionLogIterator>* iter, SequenceNumber seq_number, std::unique_ptr<TransactionLogIterator>* iter,
const TransactionLogIterator::ReadOptions& const TransactionLogIterator::ReadOptions& read_options =
read_options = TransactionLogIterator::ReadOptions()) = 0; TransactionLogIterator::ReadOptions()) = 0;
// Windows API macro interference // Windows API macro interference
#undef DeleteFile #undef DeleteFile

View File

@ -137,9 +137,8 @@ class Env {
// //
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status NewSequentialFile(const std::string& fname, virtual Status NewSequentialFile(const std::string& fname,
unique_ptr<SequentialFile>* result, std::unique_ptr<SequentialFile>* result,
const EnvOptions& options) const EnvOptions& options) = 0;
= 0;
// Create a brand new random access read-only file with the // Create a brand new random access read-only file with the
// specified name. On success, stores a pointer to the new file in // specified name. On success, stores a pointer to the new file in
@ -149,9 +148,8 @@ class Env {
// //
// The returned file may be concurrently accessed by multiple threads. // The returned file may be concurrently accessed by multiple threads.
virtual Status NewRandomAccessFile(const std::string& fname, virtual Status NewRandomAccessFile(const std::string& fname,
unique_ptr<RandomAccessFile>* result, std::unique_ptr<RandomAccessFile>* result,
const EnvOptions& options) const EnvOptions& options) = 0;
= 0;
// These values match Linux definition // These values match Linux definition
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/fcntl.h#n56 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/fcntl.h#n56
enum WriteLifeTimeHint { enum WriteLifeTimeHint {
@ -171,7 +169,7 @@ class Env {
// //
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status NewWritableFile(const std::string& fname, virtual Status NewWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) = 0; const EnvOptions& options) = 0;
// Create an object that writes to a new file with the specified // Create an object that writes to a new file with the specified
@ -182,7 +180,7 @@ class Env {
// //
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status ReopenWritableFile(const std::string& /*fname*/, virtual Status ReopenWritableFile(const std::string& /*fname*/,
unique_ptr<WritableFile>* /*result*/, std::unique_ptr<WritableFile>* /*result*/,
const EnvOptions& /*options*/) { const EnvOptions& /*options*/) {
return Status::NotSupported(); return Status::NotSupported();
} }
@ -190,7 +188,7 @@ class Env {
// Reuse an existing file by renaming it and opening it as writable. // Reuse an existing file by renaming it and opening it as writable.
virtual Status ReuseWritableFile(const std::string& fname, virtual Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options); const EnvOptions& options);
// Open `fname` for random read and write, if file doesn't exist the file // Open `fname` for random read and write, if file doesn't exist the file
@ -199,7 +197,7 @@ class Env {
// //
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status NewRandomRWFile(const std::string& /*fname*/, virtual Status NewRandomRWFile(const std::string& /*fname*/,
unique_ptr<RandomRWFile>* /*result*/, std::unique_ptr<RandomRWFile>* /*result*/,
const EnvOptions& /*options*/) { const EnvOptions& /*options*/) {
return Status::NotSupported("RandomRWFile is not implemented in this Env"); return Status::NotSupported("RandomRWFile is not implemented in this Env");
} }
@ -209,7 +207,7 @@ class Env {
// file in `*result`. The file must exist prior to this call. // file in `*result`. The file must exist prior to this call.
virtual Status NewMemoryMappedFileBuffer( virtual Status NewMemoryMappedFileBuffer(
const std::string& /*fname*/, const std::string& /*fname*/,
unique_ptr<MemoryMappedFileBuffer>* /*result*/) { std::unique_ptr<MemoryMappedFileBuffer>* /*result*/) {
return Status::NotSupported( return Status::NotSupported(
"MemoryMappedFileBuffer is not implemented in this Env"); "MemoryMappedFileBuffer is not implemented in this Env");
} }
@ -222,7 +220,7 @@ class Env {
// *result and returns OK. On failure stores nullptr in *result and // *result and returns OK. On failure stores nullptr in *result and
// returns non-OK. // returns non-OK.
virtual Status NewDirectory(const std::string& name, virtual Status NewDirectory(const std::string& name,
unique_ptr<Directory>* result) = 0; std::unique_ptr<Directory>* result) = 0;
// Returns OK if the named file exists. // Returns OK if the named file exists.
// NotFound if the named file does not exist, // NotFound if the named file does not exist,
@ -370,7 +368,7 @@ class Env {
// Create and return a log file for storing informational messages. // Create and return a log file for storing informational messages.
virtual Status NewLogger(const std::string& fname, virtual Status NewLogger(const std::string& fname,
shared_ptr<Logger>* result) = 0; std::shared_ptr<Logger>* result) = 0;
// Returns the number of micro-seconds since some fixed point in time. // Returns the number of micro-seconds since some fixed point in time.
// It is often used as system time such as in GenericRateLimiter // It is often used as system time such as in GenericRateLimiter
@ -942,24 +940,32 @@ class FileLock {
void operator=(const FileLock&); void operator=(const FileLock&);
}; };
extern void LogFlush(const shared_ptr<Logger>& info_log); extern void LogFlush(const std::shared_ptr<Logger>& info_log);
extern void Log(const InfoLogLevel log_level, extern void Log(const InfoLogLevel log_level,
const shared_ptr<Logger>& info_log, const char* format, ...); const std::shared_ptr<Logger>& info_log, const char* format,
...);
// a set of log functions with different log levels. // a set of log functions with different log levels.
extern void Header(const shared_ptr<Logger>& info_log, const char* format, ...); extern void Header(const std::shared_ptr<Logger>& info_log, const char* format,
extern void Debug(const shared_ptr<Logger>& info_log, const char* format, ...); ...);
extern void Info(const shared_ptr<Logger>& info_log, const char* format, ...); extern void Debug(const std::shared_ptr<Logger>& info_log, const char* format,
extern void Warn(const shared_ptr<Logger>& info_log, const char* format, ...); ...);
extern void Error(const shared_ptr<Logger>& info_log, const char* format, ...); extern void Info(const std::shared_ptr<Logger>& info_log, const char* format,
extern void Fatal(const shared_ptr<Logger>& info_log, const char* format, ...); ...);
extern void Warn(const std::shared_ptr<Logger>& info_log, const char* format,
...);
extern void Error(const std::shared_ptr<Logger>& info_log, const char* format,
...);
extern void Fatal(const std::shared_ptr<Logger>& info_log, const char* format,
...);
// Log the specified data to *info_log if info_log is non-nullptr. // Log the specified data to *info_log if info_log is non-nullptr.
// The default info log level is InfoLogLevel::INFO_LEVEL. // The default info log level is InfoLogLevel::INFO_LEVEL.
extern void Log(const shared_ptr<Logger>& info_log, const char* format, ...) extern void Log(const std::shared_ptr<Logger>& info_log, const char* format,
...)
# if defined(__GNUC__) || defined(__clang__) # if defined(__GNUC__) || defined(__clang__)
__attribute__((__format__ (__printf__, 2, 3))) __attribute__((__format__(__printf__, 2, 3)))
# endif # endif
; ;
@ -1005,37 +1011,38 @@ class EnvWrapper : public Env {
Env* target() const { return target_; } Env* target() const { return target_; }
// The following text is boilerplate that forwards all methods to target() // The following text is boilerplate that forwards all methods to target()
Status NewSequentialFile(const std::string& f, unique_ptr<SequentialFile>* r, Status NewSequentialFile(const std::string& f,
std::unique_ptr<SequentialFile>* r,
const EnvOptions& options) override { const EnvOptions& options) override {
return target_->NewSequentialFile(f, r, options); return target_->NewSequentialFile(f, r, options);
} }
Status NewRandomAccessFile(const std::string& f, Status NewRandomAccessFile(const std::string& f,
unique_ptr<RandomAccessFile>* r, std::unique_ptr<RandomAccessFile>* r,
const EnvOptions& options) override { const EnvOptions& options) override {
return target_->NewRandomAccessFile(f, r, options); return target_->NewRandomAccessFile(f, r, options);
} }
Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r, Status NewWritableFile(const std::string& f, std::unique_ptr<WritableFile>* r,
const EnvOptions& options) override { const EnvOptions& options) override {
return target_->NewWritableFile(f, r, options); return target_->NewWritableFile(f, r, options);
} }
Status ReopenWritableFile(const std::string& fname, Status ReopenWritableFile(const std::string& fname,
unique_ptr<WritableFile>* result, std::unique_ptr<WritableFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
return target_->ReopenWritableFile(fname, result, options); return target_->ReopenWritableFile(fname, result, options);
} }
Status ReuseWritableFile(const std::string& fname, Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* r, std::unique_ptr<WritableFile>* r,
const EnvOptions& options) override { const EnvOptions& options) override {
return target_->ReuseWritableFile(fname, old_fname, r, options); return target_->ReuseWritableFile(fname, old_fname, r, options);
} }
Status NewRandomRWFile(const std::string& fname, Status NewRandomRWFile(const std::string& fname,
unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options) override { const EnvOptions& options) override {
return target_->NewRandomRWFile(fname, result, options); return target_->NewRandomRWFile(fname, result, options);
} }
Status NewDirectory(const std::string& name, Status NewDirectory(const std::string& name,
unique_ptr<Directory>* result) override { std::unique_ptr<Directory>* result) override {
return target_->NewDirectory(name, result); return target_->NewDirectory(name, result);
} }
Status FileExists(const std::string& f) override { Status FileExists(const std::string& f) override {
@ -1113,7 +1120,7 @@ class EnvWrapper : public Env {
return target_->GetTestDirectory(path); return target_->GetTestDirectory(path);
} }
Status NewLogger(const std::string& fname, Status NewLogger(const std::string& fname,
shared_ptr<Logger>* result) override { std::shared_ptr<Logger>* result) override {
return target_->NewLogger(fname, result); return target_->NewLogger(fname, result);
} }
uint64_t NowMicros() override { return target_->NowMicros(); } uint64_t NowMicros() override { return target_->NowMicros(); }

View File

@ -142,8 +142,9 @@ class EncryptionProvider {
// CreateCipherStream creates a block access cipher stream for a file given // CreateCipherStream creates a block access cipher stream for a file given
// given name and options. // given name and options.
virtual Status CreateCipherStream(const std::string& fname, const EnvOptions& options, virtual Status CreateCipherStream(
Slice& prefix, unique_ptr<BlockAccessCipherStream>* result) = 0; const std::string& fname, const EnvOptions& options, Slice& prefix,
std::unique_ptr<BlockAccessCipherStream>* result) = 0;
}; };
// This encryption provider uses a CTR cipher stream, with a given block cipher // This encryption provider uses a CTR cipher stream, with a given block cipher
@ -174,8 +175,9 @@ class CTREncryptionProvider : public EncryptionProvider {
// CreateCipherStream creates a block access cipher stream for a file given // CreateCipherStream creates a block access cipher stream for a file given
// given name and options. // given name and options.
virtual Status CreateCipherStream(const std::string& fname, const EnvOptions& options, virtual Status CreateCipherStream(
Slice& prefix, unique_ptr<BlockAccessCipherStream>* result) override; const std::string& fname, const EnvOptions& options, Slice& prefix,
std::unique_ptr<BlockAccessCipherStream>* result) override;
protected: protected:
// PopulateSecretPrefixPart initializes the data into a new prefix block // PopulateSecretPrefixPart initializes the data into a new prefix block
@ -187,8 +189,10 @@ class CTREncryptionProvider : public EncryptionProvider {
// CreateCipherStreamFromPrefix creates a block access cipher stream for a file given // CreateCipherStreamFromPrefix creates a block access cipher stream for a file given
// given name and options. The given prefix is already decrypted. // given name and options. The given prefix is already decrypted.
virtual Status CreateCipherStreamFromPrefix(const std::string& fname, const EnvOptions& options, virtual Status CreateCipherStreamFromPrefix(
uint64_t initialCounter, const Slice& iv, const Slice& prefix, unique_ptr<BlockAccessCipherStream>* result); const std::string& fname, const EnvOptions& options,
uint64_t initialCounter, const Slice& iv, const Slice& prefix,
std::unique_ptr<BlockAccessCipherStream>* result);
}; };
} // namespace rocksdb } // namespace rocksdb

View File

@ -462,8 +462,8 @@ class TableFactory {
// table_reader is the output table reader. // table_reader is the output table reader.
virtual Status NewTableReader( virtual Status NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table_reader, std::unique_ptr<TableReader>* table_reader,
bool prefetch_index_and_filter_in_cache = true) const = 0; bool prefetch_index_and_filter_in_cache = true) const = 0;
// Return a table builder to write to a file for this table type. // Return a table builder to write to a file for this table type.

View File

@ -60,7 +60,7 @@ struct BatchResult {
// Add empty __ctor and __dtor for the rule of five // Add empty __ctor and __dtor for the rule of five
// However, preserve the original semantics and prohibit copying // However, preserve the original semantics and prohibit copying
// as the unique_ptr member does not copy. // as the std::unique_ptr member does not copy.
BatchResult() {} BatchResult() {}
~BatchResult() {} ~BatchResult() {}

View File

@ -48,20 +48,21 @@ class EnvMirror : public EnvWrapper {
delete b_; delete b_;
} }
Status NewSequentialFile(const std::string& f, unique_ptr<SequentialFile>* r, Status NewSequentialFile(const std::string& f,
std::unique_ptr<SequentialFile>* r,
const EnvOptions& options) override; const EnvOptions& options) override;
Status NewRandomAccessFile(const std::string& f, Status NewRandomAccessFile(const std::string& f,
unique_ptr<RandomAccessFile>* r, std::unique_ptr<RandomAccessFile>* r,
const EnvOptions& options) override; const EnvOptions& options) override;
Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r, Status NewWritableFile(const std::string& f, std::unique_ptr<WritableFile>* r,
const EnvOptions& options) override; const EnvOptions& options) override;
Status ReuseWritableFile(const std::string& fname, Status ReuseWritableFile(const std::string& fname,
const std::string& old_fname, const std::string& old_fname,
unique_ptr<WritableFile>* r, std::unique_ptr<WritableFile>* r,
const EnvOptions& options) override; const EnvOptions& options) override;
virtual Status NewDirectory(const std::string& name, virtual Status NewDirectory(const std::string& name,
unique_ptr<Directory>* result) override { std::unique_ptr<Directory>* result) override {
unique_ptr<Directory> br; std::unique_ptr<Directory> br;
Status as = a_->NewDirectory(name, result); Status as = a_->NewDirectory(name, result);
Status bs = b_->NewDirectory(name, &br); Status bs = b_->NewDirectory(name, &br);
assert(as == bs); assert(as == bs);

View File

@ -27,8 +27,8 @@ namespace rocksdb {
template <typename T> template <typename T>
T* NewCustomObject(const std::string& target, std::unique_ptr<T>* res_guard); T* NewCustomObject(const std::string& target, std::unique_ptr<T>* res_guard);
// Returns a new T when called with a string. Populates the unique_ptr argument // Returns a new T when called with a string. Populates the std::unique_ptr
// if granting ownership to caller. // argument if granting ownership to caller.
template <typename T> template <typename T>
using FactoryFunc = std::function<T*(const std::string&, std::unique_ptr<T>*)>; using FactoryFunc = std::function<T*(const std::string&, std::unique_ptr<T>*)>;

View File

@ -369,7 +369,7 @@ class StackableDB : public DB {
} }
virtual Status GetUpdatesSince( virtual Status GetUpdatesSince(
SequenceNumber seq_number, unique_ptr<TransactionLogIterator>* iter, SequenceNumber seq_number, std::unique_ptr<TransactionLogIterator>* iter,
const TransactionLogIterator::ReadOptions& read_options) override { const TransactionLogIterator::ReadOptions& read_options) override {
return db_->GetUpdatesSince(seq_number, iter, read_options); return db_->GetUpdatesSince(seq_number, iter, read_options);
} }

View File

@ -1970,8 +1970,8 @@ jbyte Java_org_rocksdb_Options_compressionType(JNIEnv* /*env*/,
* @param jcompression_levels A reference to a java byte array * @param jcompression_levels A reference to a java byte array
* where each byte indicates a compression level * where each byte indicates a compression level
* *
* @return A unique_ptr to the vector, or unique_ptr(nullptr) if a JNI exception * @return A std::unique_ptr to the vector, or std::unique_ptr(nullptr) if a JNI
* occurs * exception occurs
*/ */
std::unique_ptr<std::vector<rocksdb::CompressionType>> std::unique_ptr<std::vector<rocksdb::CompressionType>>
rocksdb_compression_vector_helper(JNIEnv* env, jbyteArray jcompression_levels) { rocksdb_compression_vector_helper(JNIEnv* env, jbyteArray jcompression_levels) {

View File

@ -168,7 +168,7 @@ class HashSkipListRep : public MemTableRep {
Bucket* list_; Bucket* list_;
Bucket::Iterator iter_; Bucket::Iterator iter_;
// here we track if we own list_. If we own it, we are also // here we track if we own list_. If we own it, we are also
// responsible for it's cleaning. This is a poor man's shared_ptr // responsible for it's cleaning. This is a poor man's std::shared_ptr
bool own_list_; bool own_list_;
std::unique_ptr<Arena> arena_; std::unique_ptr<Arena> arena_;
std::string tmp_; // For passing to EncodeKey std::string tmp_; // For passing to EncodeKey

View File

@ -18,7 +18,7 @@ namespace rocksdb {
// ImmutableCFOptions is a data struct used by RocksDB internal. It contains a // ImmutableCFOptions is a data struct used by RocksDB internal. It contains a
// subset of Options that should not be changed during the entire lifetime // subset of Options that should not be changed during the entire lifetime
// of DB. Raw pointers defined in this struct do not have ownership to the data // of DB. Raw pointers defined in this struct do not have ownership to the data
// they point to. Options contains shared_ptr to these data. // they point to. Options contains std::shared_ptr to these data.
struct ImmutableCFOptions { struct ImmutableCFOptions {
ImmutableCFOptions(); ImmutableCFOptions();
explicit ImmutableCFOptions(const Options& options); explicit ImmutableCFOptions(const Options& options);

View File

@ -48,7 +48,7 @@ Status PersistRocksDBOptions(const DBOptions& db_opt,
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
unique_ptr<WritableFileWriter> writable; std::unique_ptr<WritableFileWriter> writable;
writable.reset(new WritableFileWriter(std::move(wf), file_name, EnvOptions(), writable.reset(new WritableFileWriter(std::move(wf), file_name, EnvOptions(),
nullptr /* statistics */)); nullptr /* statistics */));

View File

@ -109,7 +109,7 @@ public:
// The returned file will only be accessed by one thread at a time. // The returned file will only be accessed by one thread at a time.
virtual Status NewRandomRWFile(const std::string& fname, virtual Status NewRandomRWFile(const std::string& fname,
unique_ptr<RandomRWFile>* result, std::unique_ptr<RandomRWFile>* result,
const EnvOptions& options); const EnvOptions& options);
virtual Status NewMemoryMappedFileBuffer( virtual Status NewMemoryMappedFileBuffer(

View File

@ -40,7 +40,7 @@ struct WindowsThread::Data {
void WindowsThread::Init(std::function<void()>&& func) { void WindowsThread::Init(std::function<void()>&& func) {
data_ = std::make_shared<Data>(std::move(func)); data_ = std::make_shared<Data>(std::move(func));
// We create another instance of shared_ptr to get an additional ref // We create another instance of std::shared_ptr to get an additional ref
// since we may detach and destroy this instance before the threadproc // since we may detach and destroy this instance before the threadproc
// may start to run. We choose to allocate this additional ref on the heap // may start to run. We choose to allocate this additional ref on the heap
// so we do not need to synchronize and allow this thread to proceed // so we do not need to synchronize and allow this thread to proceed

View File

@ -42,8 +42,8 @@ extern const uint64_t kCuckooTableMagicNumber;
Status AdaptiveTableFactory::NewTableReader( Status AdaptiveTableFactory::NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table, std::unique_ptr<TableReader>* table,
bool /*prefetch_index_and_filter_in_cache*/) const { bool /*prefetch_index_and_filter_in_cache*/) const {
Footer footer; Footer footer;
auto s = ReadFooterFromFile(file.get(), nullptr /* prefetch_buffer */, auto s = ReadFooterFromFile(file.get(), nullptr /* prefetch_buffer */,

View File

@ -35,8 +35,8 @@ class AdaptiveTableFactory : public TableFactory {
Status NewTableReader( Status NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table, std::unique_ptr<TableReader>* table,
bool prefetch_index_and_filter_in_cache = true) const override; bool prefetch_index_and_filter_in_cache = true) const override;
TableBuilder* NewTableBuilder( TableBuilder* NewTableBuilder(

View File

@ -194,8 +194,8 @@ BlockBasedTableFactory::BlockBasedTableFactory(
Status BlockBasedTableFactory::NewTableReader( Status BlockBasedTableFactory::NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table_reader, std::unique_ptr<TableReader>* table_reader,
bool prefetch_index_and_filter_in_cache) const { bool prefetch_index_and_filter_in_cache) const {
return BlockBasedTable::Open( return BlockBasedTable::Open(
table_reader_options.ioptions, table_reader_options.env_options, table_reader_options.ioptions, table_reader_options.env_options,

View File

@ -53,8 +53,8 @@ class BlockBasedTableFactory : public TableFactory {
Status NewTableReader( Status NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table_reader, std::unique_ptr<TableReader>* table_reader,
bool prefetch_index_and_filter_in_cache = true) const override; bool prefetch_index_and_filter_in_cache = true) const override;
TableBuilder* NewTableBuilder( TableBuilder* NewTableBuilder(

View File

@ -745,9 +745,9 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
const EnvOptions& env_options, const EnvOptions& env_options,
const BlockBasedTableOptions& table_options, const BlockBasedTableOptions& table_options,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
unique_ptr<RandomAccessFileReader>&& file, std::unique_ptr<RandomAccessFileReader>&& file,
uint64_t file_size, uint64_t file_size,
unique_ptr<TableReader>* table_reader, std::unique_ptr<TableReader>* table_reader,
const SliceTransform* prefix_extractor, const SliceTransform* prefix_extractor,
const bool prefetch_index_and_filter_in_cache, const bool prefetch_index_and_filter_in_cache,
const bool skip_filters, const int level, const bool skip_filters, const int level,
@ -826,7 +826,7 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
rep->internal_prefix_transform.reset( rep->internal_prefix_transform.reset(
new InternalKeySliceTransform(prefix_extractor)); new InternalKeySliceTransform(prefix_extractor));
SetupCacheKeyPrefix(rep, file_size); SetupCacheKeyPrefix(rep, file_size);
unique_ptr<BlockBasedTable> new_table(new BlockBasedTable(rep)); std::unique_ptr<BlockBasedTable> new_table(new BlockBasedTable(rep));
// page cache options // page cache options
rep->persistent_cache_options = rep->persistent_cache_options =
@ -1029,7 +1029,7 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
bool disable_prefix_seek = bool disable_prefix_seek =
rep->index_type == BlockBasedTableOptions::kHashSearch && rep->index_type == BlockBasedTableOptions::kHashSearch &&
need_upper_bound_check; need_upper_bound_check;
unique_ptr<InternalIteratorBase<BlockHandle>> iter( std::unique_ptr<InternalIteratorBase<BlockHandle>> iter(
new_table->NewIndexIterator(ReadOptions(), disable_prefix_seek, new_table->NewIndexIterator(ReadOptions(), disable_prefix_seek,
nullptr, &index_entry)); nullptr, &index_entry));
s = iter->status(); s = iter->status();
@ -1948,7 +1948,7 @@ bool BlockBasedTable::PrefixMayMatch(
// Then, try find it within each block // Then, try find it within each block
// we already know prefix_extractor and prefix_extractor_name must match // we already know prefix_extractor and prefix_extractor_name must match
// because `CheckPrefixMayMatch` first checks `check_filter_ == true` // because `CheckPrefixMayMatch` first checks `check_filter_ == true`
unique_ptr<InternalIteratorBase<BlockHandle>> iiter( std::unique_ptr<InternalIteratorBase<BlockHandle>> iiter(
NewIndexIterator(no_io_read_options, NewIndexIterator(no_io_read_options,
/* need_upper_bound_check */ false)); /* need_upper_bound_check */ false));
iiter->Seek(internal_prefix); iiter->Seek(internal_prefix);
@ -2730,7 +2730,7 @@ Status BlockBasedTable::CreateIndexReader(
} }
uint64_t BlockBasedTable::ApproximateOffsetOf(const Slice& key) { uint64_t BlockBasedTable::ApproximateOffsetOf(const Slice& key) {
unique_ptr<InternalIteratorBase<BlockHandle>> index_iter( std::unique_ptr<InternalIteratorBase<BlockHandle>> index_iter(
NewIndexIterator(ReadOptions())); NewIndexIterator(ReadOptions()));
index_iter->Seek(key); index_iter->Seek(key);

View File

@ -89,8 +89,9 @@ class BlockBasedTable : public TableReader {
const EnvOptions& env_options, const EnvOptions& env_options,
const BlockBasedTableOptions& table_options, const BlockBasedTableOptions& table_options,
const InternalKeyComparator& internal_key_comparator, const InternalKeyComparator& internal_key_comparator,
unique_ptr<RandomAccessFileReader>&& file, std::unique_ptr<RandomAccessFileReader>&& file,
uint64_t file_size, unique_ptr<TableReader>* table_reader, uint64_t file_size,
std::unique_ptr<TableReader>* table_reader,
const SliceTransform* prefix_extractor = nullptr, const SliceTransform* prefix_extractor = nullptr,
bool prefetch_index_and_filter_in_cache = true, bool prefetch_index_and_filter_in_cache = true,
bool skip_filters = false, int level = -1, bool skip_filters = false, int level = -1,
@ -458,7 +459,7 @@ struct BlockBasedTable::Rep {
const FilterPolicy* const filter_policy; const FilterPolicy* const filter_policy;
const InternalKeyComparator& internal_comparator; const InternalKeyComparator& internal_comparator;
Status status; Status status;
unique_ptr<RandomAccessFileReader> file; std::unique_ptr<RandomAccessFileReader> file;
char cache_key_prefix[kMaxCacheKeyPrefixSize]; char cache_key_prefix[kMaxCacheKeyPrefixSize];
size_t cache_key_prefix_size = 0; size_t cache_key_prefix_size = 0;
char persistent_cache_key_prefix[kMaxCacheKeyPrefixSize]; char persistent_cache_key_prefix[kMaxCacheKeyPrefixSize];
@ -474,8 +475,8 @@ struct BlockBasedTable::Rep {
// index_reader and filter will be populated and used only when // index_reader and filter will be populated and used only when
// options.block_cache is nullptr; otherwise we will get the index block via // options.block_cache is nullptr; otherwise we will get the index block via
// the block cache. // the block cache.
unique_ptr<IndexReader> index_reader; std::unique_ptr<IndexReader> index_reader;
unique_ptr<FilterBlockReader> filter; std::unique_ptr<FilterBlockReader> filter;
enum class FilterType { enum class FilterType {
kNoFilter, kNoFilter,
@ -500,7 +501,7 @@ struct BlockBasedTable::Rep {
// module should not be relying on db module. However to make things easier // module should not be relying on db module. However to make things easier
// and compatible with existing code, we introduce a wrapper that allows // and compatible with existing code, we introduce a wrapper that allows
// block to extract prefix without knowing if a key is internal or not. // block to extract prefix without knowing if a key is internal or not.
unique_ptr<SliceTransform> internal_prefix_transform; std::unique_ptr<SliceTransform> internal_prefix_transform;
std::shared_ptr<const SliceTransform> table_prefix_extractor; std::shared_ptr<const SliceTransform> table_prefix_extractor;
// only used in level 0 files when pin_l0_filter_and_index_blocks_in_cache is // only used in level 0 files when pin_l0_filter_and_index_blocks_in_cache is

View File

@ -51,7 +51,7 @@ class CuckooBuilderTest : public testing::Test {
} }
} }
// Read file // Read file
unique_ptr<RandomAccessFile> read_file; std::unique_ptr<RandomAccessFile> read_file;
ASSERT_OK(env_->NewRandomAccessFile(fname, &read_file, env_options_)); ASSERT_OK(env_->NewRandomAccessFile(fname, &read_file, env_options_));
uint64_t read_file_size; uint64_t read_file_size;
ASSERT_OK(env_->GetFileSize(fname, &read_file_size)); ASSERT_OK(env_->GetFileSize(fname, &read_file_size));
@ -63,7 +63,7 @@ class CuckooBuilderTest : public testing::Test {
// Assert Table Properties. // Assert Table Properties.
TableProperties* props = nullptr; TableProperties* props = nullptr;
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
new RandomAccessFileReader(std::move(read_file), fname)); new RandomAccessFileReader(std::move(read_file), fname));
ASSERT_OK(ReadTableProperties(file_reader.get(), read_file_size, ASSERT_OK(ReadTableProperties(file_reader.get(), read_file_size,
kCuckooTableMagicNumber, ioptions, kCuckooTableMagicNumber, ioptions,
@ -161,10 +161,10 @@ class CuckooBuilderTest : public testing::Test {
}; };
TEST_F(CuckooBuilderTest, SuccessWithEmptyFile) { TEST_F(CuckooBuilderTest, SuccessWithEmptyFile) {
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("EmptyFile"); fname = test::PerThreadDBPath("EmptyFile");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, 4, 100, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, 4, 100,
BytewiseComparator(), 1, false, false, BytewiseComparator(), 1, false, false,
@ -203,10 +203,10 @@ TEST_F(CuckooBuilderTest, WriteSuccessNoCollisionFullKey) {
} }
uint64_t expected_table_size = GetExpectedTableSize(keys.size()); uint64_t expected_table_size = GetExpectedTableSize(keys.size());
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("NoCollisionFullKey"); fname = test::PerThreadDBPath("NoCollisionFullKey");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
100, BytewiseComparator(), 1, false, false, 100, BytewiseComparator(), 1, false, false,
@ -252,10 +252,10 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionFullKey) {
} }
uint64_t expected_table_size = GetExpectedTableSize(keys.size()); uint64_t expected_table_size = GetExpectedTableSize(keys.size());
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("WithCollisionFullKey"); fname = test::PerThreadDBPath("WithCollisionFullKey");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
100, BytewiseComparator(), 1, false, false, 100, BytewiseComparator(), 1, false, false,
@ -300,11 +300,11 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionAndCuckooBlock) {
} }
uint64_t expected_table_size = GetExpectedTableSize(keys.size()); uint64_t expected_table_size = GetExpectedTableSize(keys.size());
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
uint32_t cuckoo_block_size = 2; uint32_t cuckoo_block_size = 2;
fname = test::PerThreadDBPath("WithCollisionFullKey2"); fname = test::PerThreadDBPath("WithCollisionFullKey2");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder( CuckooTableBuilder builder(
file_writer.get(), kHashTableRatio, num_hash_fun, 100, file_writer.get(), kHashTableRatio, num_hash_fun, 100,
@ -354,10 +354,10 @@ TEST_F(CuckooBuilderTest, WithCollisionPathFullKey) {
} }
uint64_t expected_table_size = GetExpectedTableSize(keys.size()); uint64_t expected_table_size = GetExpectedTableSize(keys.size());
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("WithCollisionPathFullKey"); fname = test::PerThreadDBPath("WithCollisionPathFullKey");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
100, BytewiseComparator(), 1, false, false, 100, BytewiseComparator(), 1, false, false,
@ -404,10 +404,10 @@ TEST_F(CuckooBuilderTest, WithCollisionPathFullKeyAndCuckooBlock) {
} }
uint64_t expected_table_size = GetExpectedTableSize(keys.size()); uint64_t expected_table_size = GetExpectedTableSize(keys.size());
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("WithCollisionPathFullKeyAndCuckooBlock"); fname = test::PerThreadDBPath("WithCollisionPathFullKeyAndCuckooBlock");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
100, BytewiseComparator(), 2, false, false, 100, BytewiseComparator(), 2, false, false,
@ -447,10 +447,10 @@ TEST_F(CuckooBuilderTest, WriteSuccessNoCollisionUserKey) {
std::vector<uint64_t> expected_locations = {0, 1, 2, 3}; std::vector<uint64_t> expected_locations = {0, 1, 2, 3};
uint64_t expected_table_size = GetExpectedTableSize(user_keys.size()); uint64_t expected_table_size = GetExpectedTableSize(user_keys.size());
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("NoCollisionUserKey"); fname = test::PerThreadDBPath("NoCollisionUserKey");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
100, BytewiseComparator(), 1, false, false, 100, BytewiseComparator(), 1, false, false,
@ -491,10 +491,10 @@ TEST_F(CuckooBuilderTest, WriteSuccessWithCollisionUserKey) {
std::vector<uint64_t> expected_locations = {0, 1, 2, 3}; std::vector<uint64_t> expected_locations = {0, 1, 2, 3};
uint64_t expected_table_size = GetExpectedTableSize(user_keys.size()); uint64_t expected_table_size = GetExpectedTableSize(user_keys.size());
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("WithCollisionUserKey"); fname = test::PerThreadDBPath("WithCollisionUserKey");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
100, BytewiseComparator(), 1, false, false, 100, BytewiseComparator(), 1, false, false,
@ -537,10 +537,10 @@ TEST_F(CuckooBuilderTest, WithCollisionPathUserKey) {
std::vector<uint64_t> expected_locations = {0, 1, 3, 4, 2}; std::vector<uint64_t> expected_locations = {0, 1, 3, 4, 2};
uint64_t expected_table_size = GetExpectedTableSize(user_keys.size()); uint64_t expected_table_size = GetExpectedTableSize(user_keys.size());
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("WithCollisionPathUserKey"); fname = test::PerThreadDBPath("WithCollisionPathUserKey");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
2, BytewiseComparator(), 1, false, false, 2, BytewiseComparator(), 1, false, false,
@ -582,10 +582,10 @@ TEST_F(CuckooBuilderTest, FailWhenCollisionPathTooLong) {
}; };
hash_map = std::move(hm); hash_map = std::move(hm);
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("WithCollisionPathUserKey"); fname = test::PerThreadDBPath("WithCollisionPathUserKey");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
2, BytewiseComparator(), 1, false, false, 2, BytewiseComparator(), 1, false, false,
@ -610,10 +610,10 @@ TEST_F(CuckooBuilderTest, FailWhenSameKeyInserted) {
uint32_t num_hash_fun = 4; uint32_t num_hash_fun = 4;
std::string user_key = "repeatedkey"; std::string user_key = "repeatedkey";
unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
fname = test::PerThreadDBPath("FailWhenSameKeyInserted"); fname = test::PerThreadDBPath("FailWhenSameKeyInserted");
ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_)); ASSERT_OK(env_->NewWritableFile(fname, &writable_file, env_options_));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, EnvOptions())); new WritableFileWriter(std::move(writable_file), fname, EnvOptions()));
CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun, CuckooTableBuilder builder(file_writer.get(), kHashTableRatio, num_hash_fun,
100, BytewiseComparator(), 1, false, false, 100, BytewiseComparator(), 1, false, false,

View File

@ -14,7 +14,7 @@ namespace rocksdb {
Status CuckooTableFactory::NewTableReader( Status CuckooTableFactory::NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
std::unique_ptr<TableReader>* table, std::unique_ptr<TableReader>* table,
bool /*prefetch_index_and_filter_in_cache*/) const { bool /*prefetch_index_and_filter_in_cache*/) const {
std::unique_ptr<CuckooTableReader> new_reader(new CuckooTableReader( std::unique_ptr<CuckooTableReader> new_reader(new CuckooTableReader(

View File

@ -60,8 +60,8 @@ class CuckooTableFactory : public TableFactory {
Status NewTableReader( Status NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table, std::unique_ptr<TableReader>* table,
bool prefetch_index_and_filter_in_cache = true) const override; bool prefetch_index_and_filter_in_cache = true) const override;
TableBuilder* NewTableBuilder( TableBuilder* NewTableBuilder(

View File

@ -95,7 +95,7 @@ class CuckooReaderTest : public testing::Test {
const Comparator* ucomp = BytewiseComparator()) { const Comparator* ucomp = BytewiseComparator()) {
std::unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
ASSERT_OK(env->NewWritableFile(fname, &writable_file, env_options)); ASSERT_OK(env->NewWritableFile(fname, &writable_file, env_options));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, env_options)); new WritableFileWriter(std::move(writable_file), fname, env_options));
CuckooTableBuilder builder( CuckooTableBuilder builder(
@ -115,7 +115,7 @@ class CuckooReaderTest : public testing::Test {
// Check reader now. // Check reader now.
std::unique_ptr<RandomAccessFile> read_file; std::unique_ptr<RandomAccessFile> read_file;
ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options)); ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options));
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
new RandomAccessFileReader(std::move(read_file), fname)); new RandomAccessFileReader(std::move(read_file), fname));
const ImmutableCFOptions ioptions(options); const ImmutableCFOptions ioptions(options);
CuckooTableReader reader(ioptions, std::move(file_reader), file_size, ucomp, CuckooTableReader reader(ioptions, std::move(file_reader), file_size, ucomp,
@ -144,7 +144,7 @@ class CuckooReaderTest : public testing::Test {
void CheckIterator(const Comparator* ucomp = BytewiseComparator()) { void CheckIterator(const Comparator* ucomp = BytewiseComparator()) {
std::unique_ptr<RandomAccessFile> read_file; std::unique_ptr<RandomAccessFile> read_file;
ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options)); ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options));
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
new RandomAccessFileReader(std::move(read_file), fname)); new RandomAccessFileReader(std::move(read_file), fname));
const ImmutableCFOptions ioptions(options); const ImmutableCFOptions ioptions(options);
CuckooTableReader reader(ioptions, std::move(file_reader), file_size, ucomp, CuckooTableReader reader(ioptions, std::move(file_reader), file_size, ucomp,
@ -323,7 +323,7 @@ TEST_F(CuckooReaderTest, WhenKeyNotFound) {
CreateCuckooFileAndCheckReader(); CreateCuckooFileAndCheckReader();
std::unique_ptr<RandomAccessFile> read_file; std::unique_ptr<RandomAccessFile> read_file;
ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options)); ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options));
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
new RandomAccessFileReader(std::move(read_file), fname)); new RandomAccessFileReader(std::move(read_file), fname));
const ImmutableCFOptions ioptions(options); const ImmutableCFOptions ioptions(options);
CuckooTableReader reader(ioptions, std::move(file_reader), file_size, ucmp, CuckooTableReader reader(ioptions, std::move(file_reader), file_size, ucmp,
@ -411,7 +411,7 @@ void WriteFile(const std::vector<std::string>& keys,
std::unique_ptr<WritableFile> writable_file; std::unique_ptr<WritableFile> writable_file;
ASSERT_OK(env->NewWritableFile(fname, &writable_file, env_options)); ASSERT_OK(env->NewWritableFile(fname, &writable_file, env_options));
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
new WritableFileWriter(std::move(writable_file), fname, env_options)); new WritableFileWriter(std::move(writable_file), fname, env_options));
CuckooTableBuilder builder( CuckooTableBuilder builder(
file_writer.get(), hash_ratio, 64, 1000, test::Uint64Comparator(), 5, file_writer.get(), hash_ratio, 64, 1000, test::Uint64Comparator(), 5,
@ -432,7 +432,7 @@ void WriteFile(const std::vector<std::string>& keys,
env->GetFileSize(fname, &file_size); env->GetFileSize(fname, &file_size);
std::unique_ptr<RandomAccessFile> read_file; std::unique_ptr<RandomAccessFile> read_file;
ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options)); ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options));
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
new RandomAccessFileReader(std::move(read_file), fname)); new RandomAccessFileReader(std::move(read_file), fname));
const ImmutableCFOptions ioptions(options); const ImmutableCFOptions ioptions(options);
@ -464,7 +464,7 @@ void ReadKeys(uint64_t num, uint32_t batch_size) {
env->GetFileSize(fname, &file_size); env->GetFileSize(fname, &file_size);
std::unique_ptr<RandomAccessFile> read_file; std::unique_ptr<RandomAccessFile> read_file;
ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options)); ASSERT_OK(env->NewRandomAccessFile(fname, &read_file, env_options));
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
new RandomAccessFileReader(std::move(read_file), fname)); new RandomAccessFileReader(std::move(read_file), fname));
const ImmutableCFOptions ioptions(options); const ImmutableCFOptions ioptions(options);

View File

@ -542,9 +542,9 @@ TEST(DataBlockHashIndex, BlockTestLarge) {
void TestBoundary(InternalKey& ik1, std::string& v1, InternalKey& ik2, void TestBoundary(InternalKey& ik1, std::string& v1, InternalKey& ik2,
std::string& v2, InternalKey& seek_ikey, std::string& v2, InternalKey& seek_ikey,
GetContext& get_context, Options& options) { GetContext& get_context, Options& options) {
unique_ptr<WritableFileWriter> file_writer; std::unique_ptr<WritableFileWriter> file_writer;
unique_ptr<RandomAccessFileReader> file_reader; std::unique_ptr<RandomAccessFileReader> file_reader;
unique_ptr<TableReader> table_reader; std::unique_ptr<TableReader> table_reader;
int level_ = -1; int level_ = -1;
std::vector<std::string> keys; std::vector<std::string> keys;
@ -557,7 +557,7 @@ void TestBoundary(InternalKey& ik1, std::string& v1, InternalKey& ik2,
soptions.use_mmap_reads = ioptions.allow_mmap_reads; soptions.use_mmap_reads = ioptions.allow_mmap_reads;
file_writer.reset( file_writer.reset(
test::GetWritableFileWriter(new test::StringSink(), "" /* don't care */)); test::GetWritableFileWriter(new test::StringSink(), "" /* don't care */));
unique_ptr<TableBuilder> builder; std::unique_ptr<TableBuilder> builder;
std::vector<std::unique_ptr<IntTblPropCollectorFactory>> std::vector<std::unique_ptr<IntTblPropCollectorFactory>>
int_tbl_prop_collector_factories; int_tbl_prop_collector_factories;
std::string column_family_name; std::string column_family_name;

View File

@ -60,8 +60,8 @@ MockTableFactory::MockTableFactory() : next_id_(1) {}
Status MockTableFactory::NewTableReader( Status MockTableFactory::NewTableReader(
const TableReaderOptions& /*table_reader_options*/, const TableReaderOptions& /*table_reader_options*/,
unique_ptr<RandomAccessFileReader>&& file, uint64_t /*file_size*/, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t /*file_size*/,
unique_ptr<TableReader>* table_reader, std::unique_ptr<TableReader>* table_reader,
bool /*prefetch_index_and_filter_in_cache*/) const { bool /*prefetch_index_and_filter_in_cache*/) const {
uint32_t id = GetIDFromFile(file.get()); uint32_t id = GetIDFromFile(file.get());

View File

@ -157,8 +157,8 @@ class MockTableFactory : public TableFactory {
const char* Name() const override { return "MockTable"; } const char* Name() const override { return "MockTable"; }
Status NewTableReader( Status NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table_reader, std::unique_ptr<TableReader>* table_reader,
bool prefetch_index_and_filter_in_cache = true) const override; bool prefetch_index_and_filter_in_cache = true) const override;
TableBuilder* NewTableBuilder( TableBuilder* NewTableBuilder(
const TableBuilderOptions& table_builder_options, const TableBuilderOptions& table_builder_options,

View File

@ -19,8 +19,8 @@ namespace rocksdb {
Status PlainTableFactory::NewTableReader( Status PlainTableFactory::NewTableReader(
const TableReaderOptions& table_reader_options, const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table, std::unique_ptr<TableReader>* table,
bool /*prefetch_index_and_filter_in_cache*/) const { bool /*prefetch_index_and_filter_in_cache*/) const {
return PlainTableReader::Open( return PlainTableReader::Open(
table_reader_options.ioptions, table_reader_options.env_options, table_reader_options.ioptions, table_reader_options.env_options,

View File

@ -149,8 +149,8 @@ class PlainTableFactory : public TableFactory {
const char* Name() const override { return "PlainTable"; } const char* Name() const override { return "PlainTable"; }
Status NewTableReader(const TableReaderOptions& table_reader_options, Status NewTableReader(const TableReaderOptions& table_reader_options,
unique_ptr<RandomAccessFileReader>&& file, std::unique_ptr<RandomAccessFileReader>&& file,
uint64_t file_size, unique_ptr<TableReader>* table, uint64_t file_size, std::unique_ptr<TableReader>* table,
bool prefetch_index_and_filter_in_cache) const override; bool prefetch_index_and_filter_in_cache) const override;
TableBuilder* NewTableBuilder( TableBuilder* NewTableBuilder(

View File

@ -114,7 +114,7 @@ class PlainTableFileReader {
}; };
// Keep buffers for two recent reads. // Keep buffers for two recent reads.
std::array<unique_ptr<Buffer>, 2> buffers_; std::array<std::unique_ptr<Buffer>, 2> buffers_;
uint32_t num_buf_; uint32_t num_buf_;
Status status_; Status status_;

View File

@ -91,12 +91,11 @@ class PlainTableIterator : public InternalIterator {
}; };
extern const uint64_t kPlainTableMagicNumber; extern const uint64_t kPlainTableMagicNumber;
PlainTableReader::PlainTableReader(const ImmutableCFOptions& ioptions, PlainTableReader::PlainTableReader(
unique_ptr<RandomAccessFileReader>&& file, const ImmutableCFOptions& ioptions,
const EnvOptions& storage_options, std::unique_ptr<RandomAccessFileReader>&& file,
const InternalKeyComparator& icomparator, const EnvOptions& storage_options, const InternalKeyComparator& icomparator,
EncodingType encoding_type, EncodingType encoding_type, uint64_t file_size,
uint64_t file_size,
const TableProperties* table_properties, const TableProperties* table_properties,
const SliceTransform* prefix_extractor) const SliceTransform* prefix_extractor)
: internal_comparator_(icomparator), : internal_comparator_(icomparator),
@ -118,8 +117,8 @@ PlainTableReader::~PlainTableReader() {
Status PlainTableReader::Open( Status PlainTableReader::Open(
const ImmutableCFOptions& ioptions, const EnvOptions& env_options, const ImmutableCFOptions& ioptions, const EnvOptions& env_options,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size,
unique_ptr<TableReader>* table_reader, const int bloom_bits_per_key, std::unique_ptr<TableReader>* table_reader, const int bloom_bits_per_key,
double hash_table_ratio, size_t index_sparseness, size_t huge_page_tlb_size, double hash_table_ratio, size_t index_sparseness, size_t huge_page_tlb_size,
bool full_scan_mode, const SliceTransform* prefix_extractor) { bool full_scan_mode, const SliceTransform* prefix_extractor) {
if (file_size > PlainTableIndex::kMaxFileSize) { if (file_size > PlainTableIndex::kMaxFileSize) {

View File

@ -48,7 +48,7 @@ struct PlainTableReaderFileInfo {
bool is_mmap_mode; bool is_mmap_mode;
Slice file_data; Slice file_data;
uint32_t data_end_offset; uint32_t data_end_offset;
unique_ptr<RandomAccessFileReader> file; std::unique_ptr<RandomAccessFileReader> file;
PlainTableReaderFileInfo(unique_ptr<RandomAccessFileReader>&& _file, PlainTableReaderFileInfo(unique_ptr<RandomAccessFileReader>&& _file,
const EnvOptions& storage_options, const EnvOptions& storage_options,
@ -71,8 +71,8 @@ class PlainTableReader: public TableReader {
static Status Open(const ImmutableCFOptions& ioptions, static Status Open(const ImmutableCFOptions& ioptions,
const EnvOptions& env_options, const EnvOptions& env_options,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
unique_ptr<RandomAccessFileReader>&& file, std::unique_ptr<RandomAccessFileReader>&& file,
uint64_t file_size, unique_ptr<TableReader>* table, uint64_t file_size, std::unique_ptr<TableReader>* table,
const int bloom_bits_per_key, double hash_table_ratio, const int bloom_bits_per_key, double hash_table_ratio,
size_t index_sparseness, size_t huge_page_tlb_size, size_t index_sparseness, size_t huge_page_tlb_size,
bool full_scan_mode, bool full_scan_mode,
@ -104,7 +104,7 @@ class PlainTableReader: public TableReader {
} }
PlainTableReader(const ImmutableCFOptions& ioptions, PlainTableReader(const ImmutableCFOptions& ioptions,
unique_ptr<RandomAccessFileReader>&& file, std::unique_ptr<RandomAccessFileReader>&& file,
const EnvOptions& env_options, const EnvOptions& env_options,
const InternalKeyComparator& internal_comparator, const InternalKeyComparator& internal_comparator,
EncodingType encoding_type, uint64_t file_size, EncodingType encoding_type, uint64_t file_size,

View File

@ -86,9 +86,9 @@ void TableReaderBenchmark(Options& opts, EnvOptions& env_options,
const ImmutableCFOptions ioptions(opts); const ImmutableCFOptions ioptions(opts);
const ColumnFamilyOptions cfo(opts); const ColumnFamilyOptions cfo(opts);
const MutableCFOptions moptions(cfo); const MutableCFOptions moptions(cfo);
unique_ptr<WritableFileWriter> file_writer; std::unique_ptr<WritableFileWriter> file_writer;
if (!through_db) { if (!through_db) {
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
env->NewWritableFile(file_name, &file, env_options); env->NewWritableFile(file_name, &file, env_options);
std::vector<std::unique_ptr<IntTblPropCollectorFactory> > std::vector<std::unique_ptr<IntTblPropCollectorFactory> >
@ -127,9 +127,9 @@ void TableReaderBenchmark(Options& opts, EnvOptions& env_options,
db->Flush(FlushOptions()); db->Flush(FlushOptions());
} }
unique_ptr<TableReader> table_reader; std::unique_ptr<TableReader> table_reader;
if (!through_db) { if (!through_db) {
unique_ptr<RandomAccessFile> raf; std::unique_ptr<RandomAccessFile> raf;
s = env->NewRandomAccessFile(file_name, &raf, env_options); s = env->NewRandomAccessFile(file_name, &raf, env_options);
if (!s.ok()) { if (!s.ok()) {
fprintf(stderr, "Create File Error: %s\n", s.ToString().c_str()); fprintf(stderr, "Create File Error: %s\n", s.ToString().c_str());
@ -137,7 +137,7 @@ void TableReaderBenchmark(Options& opts, EnvOptions& env_options,
} }
uint64_t file_size; uint64_t file_size;
env->GetFileSize(file_name, &file_size); env->GetFileSize(file_name, &file_size);
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
new RandomAccessFileReader(std::move(raf), file_name)); new RandomAccessFileReader(std::move(raf), file_name));
s = opts.table_factory->NewTableReader( s = opts.table_factory->NewTableReader(
TableReaderOptions(ioptions, moptions.prefix_extractor.get(), TableReaderOptions(ioptions, moptions.prefix_extractor.get(),

View File

@ -325,7 +325,7 @@ class TableConstructor: public Constructor {
soptions.use_mmap_reads = ioptions.allow_mmap_reads; soptions.use_mmap_reads = ioptions.allow_mmap_reads;
file_writer_.reset(test::GetWritableFileWriter(new test::StringSink(), file_writer_.reset(test::GetWritableFileWriter(new test::StringSink(),
"" /* don't care */)); "" /* don't care */));
unique_ptr<TableBuilder> builder; std::unique_ptr<TableBuilder> builder;
std::vector<std::unique_ptr<IntTblPropCollectorFactory>> std::vector<std::unique_ptr<IntTblPropCollectorFactory>>
int_tbl_prop_collector_factories; int_tbl_prop_collector_factories;
std::string column_family_name; std::string column_family_name;
@ -423,9 +423,9 @@ class TableConstructor: public Constructor {
} }
uint64_t uniq_id_; uint64_t uniq_id_;
unique_ptr<WritableFileWriter> file_writer_; std::unique_ptr<WritableFileWriter> file_writer_;
unique_ptr<RandomAccessFileReader> file_reader_; std::unique_ptr<RandomAccessFileReader> file_reader_;
unique_ptr<TableReader> table_reader_; std::unique_ptr<TableReader> table_reader_;
bool convert_to_internal_key_; bool convert_to_internal_key_;
int level_; int level_;
@ -508,7 +508,7 @@ class InternalIteratorFromIterator : public InternalIterator {
virtual Status status() const override { return it_->status(); } virtual Status status() const override { return it_->status(); }
private: private:
unique_ptr<Iterator> it_; std::unique_ptr<Iterator> it_;
}; };
class DBConstructor: public Constructor { class DBConstructor: public Constructor {
@ -1024,7 +1024,7 @@ class HarnessTest : public testing::Test {
WriteBufferManager write_buffer_; WriteBufferManager write_buffer_;
bool support_prev_; bool support_prev_;
bool only_support_prefix_seek_; bool only_support_prefix_seek_;
shared_ptr<InternalKeyComparator> internal_comparator_; std::shared_ptr<InternalKeyComparator> internal_comparator_;
}; };
static bool Between(uint64_t val, uint64_t low, uint64_t high) { static bool Between(uint64_t val, uint64_t low, uint64_t high) {
@ -1393,8 +1393,8 @@ void PrefetchRange(TableConstructor* c, Options* opt,
// prefetch // prefetch
auto* table_reader = dynamic_cast<BlockBasedTable*>(c->GetTableReader()); auto* table_reader = dynamic_cast<BlockBasedTable*>(c->GetTableReader());
Status s; Status s;
unique_ptr<Slice> begin, end; std::unique_ptr<Slice> begin, end;
unique_ptr<InternalKey> i_begin, i_end; std::unique_ptr<InternalKey> i_begin, i_end;
if (key_begin != nullptr) { if (key_begin != nullptr) {
if (c->ConvertToInternalKey()) { if (c->ConvertToInternalKey()) {
i_begin.reset(new InternalKey(key_begin, kMaxSequenceNumber, kTypeValue)); i_begin.reset(new InternalKey(key_begin, kMaxSequenceNumber, kTypeValue));
@ -1425,7 +1425,7 @@ TEST_P(BlockBasedTableTest, PrefetchTest) {
// The purpose of this test is to test the prefetching operation built into // The purpose of this test is to test the prefetching operation built into
// BlockBasedTable. // BlockBasedTable.
Options opt; Options opt;
unique_ptr<InternalKeyComparator> ikc; std::unique_ptr<InternalKeyComparator> ikc;
ikc.reset(new test::PlainInternalKeyComparator(opt.comparator)); ikc.reset(new test::PlainInternalKeyComparator(opt.comparator));
opt.compression = kNoCompression; opt.compression = kNoCompression;
BlockBasedTableOptions table_options = GetBlockBasedTableOptions(); BlockBasedTableOptions table_options = GetBlockBasedTableOptions();
@ -2017,7 +2017,7 @@ TEST_P(BlockBasedTableTest, FilterBlockInBlockCache) {
// -- PART 1: Open with regular block cache. // -- PART 1: Open with regular block cache.
// Since block_cache is disabled, no cache activities will be involved. // Since block_cache is disabled, no cache activities will be involved.
unique_ptr<InternalIterator> iter; std::unique_ptr<InternalIterator> iter;
int64_t last_cache_bytes_read = 0; int64_t last_cache_bytes_read = 0;
// At first, no block will be accessed. // At first, no block will be accessed.
@ -2351,7 +2351,7 @@ TEST_P(BlockBasedTableTest, NoObjectInCacheAfterTableClose) {
} }
// Create a table // Create a table
Options opt; Options opt;
unique_ptr<InternalKeyComparator> ikc; std::unique_ptr<InternalKeyComparator> ikc;
ikc.reset(new test::PlainInternalKeyComparator(opt.comparator)); ikc.reset(new test::PlainInternalKeyComparator(opt.comparator));
opt.compression = kNoCompression; opt.compression = kNoCompression;
BlockBasedTableOptions table_options = BlockBasedTableOptions table_options =
@ -2427,7 +2427,7 @@ TEST_P(BlockBasedTableTest, BlockCacheLeak) {
// unique ID from the file. // unique ID from the file.
Options opt; Options opt;
unique_ptr<InternalKeyComparator> ikc; std::unique_ptr<InternalKeyComparator> ikc;
ikc.reset(new test::PlainInternalKeyComparator(opt.comparator)); ikc.reset(new test::PlainInternalKeyComparator(opt.comparator));
opt.compression = kNoCompression; opt.compression = kNoCompression;
BlockBasedTableOptions table_options = GetBlockBasedTableOptions(); BlockBasedTableOptions table_options = GetBlockBasedTableOptions();
@ -2450,7 +2450,7 @@ TEST_P(BlockBasedTableTest, BlockCacheLeak) {
const MutableCFOptions moptions(opt); const MutableCFOptions moptions(opt);
c.Finish(opt, ioptions, moptions, table_options, *ikc, &keys, &kvmap); c.Finish(opt, ioptions, moptions, table_options, *ikc, &keys, &kvmap);
unique_ptr<InternalIterator> iter( std::unique_ptr<InternalIterator> iter(
c.NewIterator(moptions.prefix_extractor.get())); c.NewIterator(moptions.prefix_extractor.get()));
iter->SeekToFirst(); iter->SeekToFirst();
while (iter->Valid()) { while (iter->Valid()) {
@ -2511,7 +2511,7 @@ TEST_P(BlockBasedTableTest, MemoryAllocator) {
auto custom_memory_allocator = std::make_shared<CustomMemoryAllocator>(); auto custom_memory_allocator = std::make_shared<CustomMemoryAllocator>();
{ {
Options opt; Options opt;
unique_ptr<InternalKeyComparator> ikc; std::unique_ptr<InternalKeyComparator> ikc;
ikc.reset(new test::PlainInternalKeyComparator(opt.comparator)); ikc.reset(new test::PlainInternalKeyComparator(opt.comparator));
opt.compression = kNoCompression; opt.compression = kNoCompression;
BlockBasedTableOptions table_options; BlockBasedTableOptions table_options;
@ -2538,7 +2538,7 @@ TEST_P(BlockBasedTableTest, MemoryAllocator) {
const MutableCFOptions moptions(opt); const MutableCFOptions moptions(opt);
c.Finish(opt, ioptions, moptions, table_options, *ikc, &keys, &kvmap); c.Finish(opt, ioptions, moptions, table_options, *ikc, &keys, &kvmap);
unique_ptr<InternalIterator> iter( std::unique_ptr<InternalIterator> iter(
c.NewIterator(moptions.prefix_extractor.get())); c.NewIterator(moptions.prefix_extractor.get()));
iter->SeekToFirst(); iter->SeekToFirst();
while (iter->Valid()) { while (iter->Valid()) {
@ -2630,7 +2630,7 @@ TEST_F(PlainTableTest, BasicPlainTableProperties) {
PlainTableFactory factory(plain_table_options); PlainTableFactory factory(plain_table_options);
test::StringSink sink; test::StringSink sink;
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
test::GetWritableFileWriter(new test::StringSink(), "" /* don't care */)); test::GetWritableFileWriter(new test::StringSink(), "" /* don't care */));
Options options; Options options;
const ImmutableCFOptions ioptions(options); const ImmutableCFOptions ioptions(options);
@ -2659,7 +2659,7 @@ TEST_F(PlainTableTest, BasicPlainTableProperties) {
test::StringSink* ss = test::StringSink* ss =
static_cast<test::StringSink*>(file_writer->writable_file()); static_cast<test::StringSink*>(file_writer->writable_file());
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
test::GetRandomAccessFileReader( test::GetRandomAccessFileReader(
new test::StringSource(ss->contents(), 72242, true))); new test::StringSource(ss->contents(), 72242, true)));
@ -3253,7 +3253,7 @@ TEST_F(PrefixTest, PrefixAndWholeKeyTest) {
TEST_P(BlockBasedTableTest, DISABLED_TableWithGlobalSeqno) { TEST_P(BlockBasedTableTest, DISABLED_TableWithGlobalSeqno) {
BlockBasedTableOptions bbto = GetBlockBasedTableOptions(); BlockBasedTableOptions bbto = GetBlockBasedTableOptions();
test::StringSink* sink = new test::StringSink(); test::StringSink* sink = new test::StringSink();
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
test::GetWritableFileWriter(sink, "" /* don't care */)); test::GetWritableFileWriter(sink, "" /* don't care */));
Options options; Options options;
options.table_factory.reset(NewBlockBasedTableFactory(bbto)); options.table_factory.reset(NewBlockBasedTableFactory(bbto));
@ -3291,7 +3291,7 @@ TEST_P(BlockBasedTableTest, DISABLED_TableWithGlobalSeqno) {
// Helper function to get version, global_seqno, global_seqno_offset // Helper function to get version, global_seqno, global_seqno_offset
std::function<void()> GetVersionAndGlobalSeqno = [&]() { std::function<void()> GetVersionAndGlobalSeqno = [&]() {
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
test::GetRandomAccessFileReader( test::GetRandomAccessFileReader(
new test::StringSource(ss_rw.contents(), 73342, true))); new test::StringSource(ss_rw.contents(), 73342, true)));
@ -3320,9 +3320,9 @@ TEST_P(BlockBasedTableTest, DISABLED_TableWithGlobalSeqno) {
}; };
// Helper function to get the contents of the table InternalIterator // Helper function to get the contents of the table InternalIterator
unique_ptr<TableReader> table_reader; std::unique_ptr<TableReader> table_reader;
std::function<InternalIterator*()> GetTableInternalIter = [&]() { std::function<InternalIterator*()> GetTableInternalIter = [&]() {
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
test::GetRandomAccessFileReader( test::GetRandomAccessFileReader(
new test::StringSource(ss_rw.contents(), 73342, true))); new test::StringSource(ss_rw.contents(), 73342, true)));
@ -3435,7 +3435,7 @@ TEST_P(BlockBasedTableTest, BlockAlignTest) {
BlockBasedTableOptions bbto = GetBlockBasedTableOptions(); BlockBasedTableOptions bbto = GetBlockBasedTableOptions();
bbto.block_align = true; bbto.block_align = true;
test::StringSink* sink = new test::StringSink(); test::StringSink* sink = new test::StringSink();
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
test::GetWritableFileWriter(sink, "" /* don't care */)); test::GetWritableFileWriter(sink, "" /* don't care */));
Options options; Options options;
options.compression = kNoCompression; options.compression = kNoCompression;
@ -3467,7 +3467,7 @@ TEST_P(BlockBasedTableTest, BlockAlignTest) {
file_writer->Flush(); file_writer->Flush();
test::RandomRWStringSink ss_rw(sink); test::RandomRWStringSink ss_rw(sink);
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
test::GetRandomAccessFileReader( test::GetRandomAccessFileReader(
new test::StringSource(ss_rw.contents(), 73342, true))); new test::StringSource(ss_rw.contents(), 73342, true)));
@ -3525,7 +3525,7 @@ TEST_P(BlockBasedTableTest, PropertiesBlockRestartPointTest) {
BlockBasedTableOptions bbto = GetBlockBasedTableOptions(); BlockBasedTableOptions bbto = GetBlockBasedTableOptions();
bbto.block_align = true; bbto.block_align = true;
test::StringSink* sink = new test::StringSink(); test::StringSink* sink = new test::StringSink();
unique_ptr<WritableFileWriter> file_writer( std::unique_ptr<WritableFileWriter> file_writer(
test::GetWritableFileWriter(sink, "" /* don't care */)); test::GetWritableFileWriter(sink, "" /* don't care */));
Options options; Options options;
@ -3560,7 +3560,7 @@ TEST_P(BlockBasedTableTest, PropertiesBlockRestartPointTest) {
file_writer->Flush(); file_writer->Flush();
test::RandomRWStringSink ss_rw(sink); test::RandomRWStringSink ss_rw(sink);
unique_ptr<RandomAccessFileReader> file_reader( std::unique_ptr<RandomAccessFileReader> file_reader(
test::GetRandomAccessFileReader( test::GetRandomAccessFileReader(
new test::StringSource(ss_rw.contents(), 73342, true))); new test::StringSource(ss_rw.contents(), 73342, true)));

View File

@ -1143,11 +1143,12 @@ class ReportFileOpEnv : public EnvWrapper {
counters_.bytes_written_ = 0; counters_.bytes_written_ = 0;
} }
Status NewSequentialFile(const std::string& f, unique_ptr<SequentialFile>* r, Status NewSequentialFile(const std::string& f,
std::unique_ptr<SequentialFile>* r,
const EnvOptions& soptions) override { const EnvOptions& soptions) override {
class CountingFile : public SequentialFile { class CountingFile : public SequentialFile {
private: private:
unique_ptr<SequentialFile> target_; std::unique_ptr<SequentialFile> target_;
ReportFileOpCounters* counters_; ReportFileOpCounters* counters_;
public: public:
@ -1175,11 +1176,11 @@ class ReportFileOpEnv : public EnvWrapper {
} }
Status NewRandomAccessFile(const std::string& f, Status NewRandomAccessFile(const std::string& f,
unique_ptr<RandomAccessFile>* r, std::unique_ptr<RandomAccessFile>* r,
const EnvOptions& soptions) override { const EnvOptions& soptions) override {
class CountingFile : public RandomAccessFile { class CountingFile : public RandomAccessFile {
private: private:
unique_ptr<RandomAccessFile> target_; std::unique_ptr<RandomAccessFile> target_;
ReportFileOpCounters* counters_; ReportFileOpCounters* counters_;
public: public:
@ -1204,11 +1205,11 @@ class ReportFileOpEnv : public EnvWrapper {
return s; return s;
} }
Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r, Status NewWritableFile(const std::string& f, std::unique_ptr<WritableFile>* r,
const EnvOptions& soptions) override { const EnvOptions& soptions) override {
class CountingFile : public WritableFile { class CountingFile : public WritableFile {
private: private:
unique_ptr<WritableFile> target_; std::unique_ptr<WritableFile> target_;
ReportFileOpCounters* counters_; ReportFileOpCounters* counters_;
public: public:
@ -5680,7 +5681,7 @@ void VerifyDBFromDB(std::string& truth_db_name) {
void Replay(ThreadState* /*thread*/, DBWithColumnFamilies* db_with_cfh) { void Replay(ThreadState* /*thread*/, DBWithColumnFamilies* db_with_cfh) {
Status s; Status s;
unique_ptr<TraceReader> trace_reader; std::unique_ptr<TraceReader> trace_reader;
s = NewFileTraceReader(FLAGS_env, EnvOptions(), FLAGS_trace_file, s = NewFileTraceReader(FLAGS_env, EnvOptions(), FLAGS_trace_file,
&trace_reader); &trace_reader);
if (!s.ok()) { if (!s.ok()) {

View File

@ -279,7 +279,7 @@ const std::string options_file_content = R"OPTIONS_FILE(
TEST_F(DBBenchTest, OptionsFileFromFile) { TEST_F(DBBenchTest, OptionsFileFromFile) {
const std::string kOptionsFileName = test_path_ + "/OPTIONS_flash"; const std::string kOptionsFileName = test_path_ + "/OPTIONS_flash";
unique_ptr<WritableFile> writable; std::unique_ptr<WritableFile> writable;
ASSERT_OK(Env::Default()->NewWritableFile(kOptionsFileName, &writable, ASSERT_OK(Env::Default()->NewWritableFile(kOptionsFileName, &writable,
EnvOptions())); EnvOptions()));
ASSERT_OK(writable->Append(options_file_content)); ASSERT_OK(writable->Append(options_file_content));

View File

@ -67,7 +67,7 @@ struct ReplicationThread {
static void ReplicationThreadBody(void* arg) { static void ReplicationThreadBody(void* arg) {
ReplicationThread* t = reinterpret_cast<ReplicationThread*>(arg); ReplicationThread* t = reinterpret_cast<ReplicationThread*>(arg);
DB* db = t->db; DB* db = t->db;
unique_ptr<TransactionLogIterator> iter; std::unique_ptr<TransactionLogIterator> iter;
SequenceNumber currentSeqNum = 1; SequenceNumber currentSeqNum = 1;
while (!t->stop.load(std::memory_order_acquire)) { while (!t->stop.load(std::memory_order_acquire)) {
iter.reset(); iter.reset();

View File

@ -940,7 +940,7 @@ class SharedState {
if (status.ok()) { if (status.ok()) {
status = FLAGS_env->GetFileSize(FLAGS_expected_values_path, &size); status = FLAGS_env->GetFileSize(FLAGS_expected_values_path, &size);
} }
unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
if (status.ok() && size == 0) { if (status.ok() && size == 0) {
const EnvOptions soptions; const EnvOptions soptions;
status = FLAGS_env->NewWritableFile(FLAGS_expected_values_path, &wfile, status = FLAGS_env->NewWritableFile(FLAGS_expected_values_path, &wfile,
@ -2689,7 +2689,7 @@ class NonBatchedOpsStressTest : public StressTest {
} }
if (!thread->rand.OneIn(2)) { if (!thread->rand.OneIn(2)) {
// Use iterator to verify this range // Use iterator to verify this range
unique_ptr<Iterator> iter( std::unique_ptr<Iterator> iter(
db_->NewIterator(options, column_families_[cf])); db_->NewIterator(options, column_families_[cf]));
iter->Seek(Key(start)); iter->Seek(Key(start));
for (auto i = start; i < end; i++) { for (auto i = start; i < end; i++) {
@ -3591,7 +3591,7 @@ class AtomicFlushStressTest : public StressTest {
options.total_order_seek = true; options.total_order_seek = true;
assert(thread != nullptr); assert(thread != nullptr);
auto shared = thread->shared; auto shared = thread->shared;
std::vector<unique_ptr<Iterator> > iters(column_families_.size()); std::vector<std::unique_ptr<Iterator> > iters(column_families_.size());
for (size_t i = 0; i != column_families_.size(); ++i) { for (size_t i = 0; i != column_families_.size(); ++i) {
iters[i].reset(db_->NewIterator(options, column_families_[i])); iters[i].reset(db_->NewIterator(options, column_families_[i]));
} }

View File

@ -1964,11 +1964,11 @@ void DumpWalFile(std::string wal_file, bool print_header, bool print_values,
bool is_write_committed, LDBCommandExecuteResult* exec_state) { bool is_write_committed, LDBCommandExecuteResult* exec_state) {
Env* env_ = Env::Default(); Env* env_ = Env::Default();
EnvOptions soptions; EnvOptions soptions;
unique_ptr<SequentialFileReader> wal_file_reader; std::unique_ptr<SequentialFileReader> wal_file_reader;
Status status; Status status;
{ {
unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
status = env_->NewSequentialFile(wal_file, &file, soptions); status = env_->NewSequentialFile(wal_file, &file, soptions);
if (status.ok()) { if (status.ok()) {
wal_file_reader.reset( wal_file_reader.reset(

View File

@ -43,7 +43,7 @@ void createSST(const std::string& file_name,
std::shared_ptr<rocksdb::TableFactory> tf; std::shared_ptr<rocksdb::TableFactory> tf;
tf.reset(new rocksdb::BlockBasedTableFactory(table_options)); tf.reset(new rocksdb::BlockBasedTableFactory(table_options));
unique_ptr<WritableFile> file; std::unique_ptr<WritableFile> file;
Env* env = Env::Default(); Env* env = Env::Default();
EnvOptions env_options; EnvOptions env_options;
ReadOptions read_options; ReadOptions read_options;
@ -51,7 +51,7 @@ void createSST(const std::string& file_name,
const ImmutableCFOptions imoptions(opts); const ImmutableCFOptions imoptions(opts);
const MutableCFOptions moptions(opts); const MutableCFOptions moptions(opts);
rocksdb::InternalKeyComparator ikc(opts.comparator); rocksdb::InternalKeyComparator ikc(opts.comparator);
unique_ptr<TableBuilder> tb; std::unique_ptr<TableBuilder> tb;
ASSERT_OK(env->NewWritableFile(file_name, &file, env_options)); ASSERT_OK(env->NewWritableFile(file_name, &file, env_options));

View File

@ -83,7 +83,7 @@ Status SstFileReader::GetTableReader(const std::string& file_path) {
// read table magic number // read table magic number
Footer footer; Footer footer;
unique_ptr<RandomAccessFile> file; std::unique_ptr<RandomAccessFile> file;
uint64_t file_size = 0; uint64_t file_size = 0;
Status s = options_.env->NewRandomAccessFile(file_path, &file, soptions_); Status s = options_.env->NewRandomAccessFile(file_path, &file, soptions_);
if (s.ok()) { if (s.ok()) {
@ -126,7 +126,7 @@ Status SstFileReader::GetTableReader(const std::string& file_path) {
Status SstFileReader::NewTableReader( Status SstFileReader::NewTableReader(
const ImmutableCFOptions& /*ioptions*/, const EnvOptions& /*soptions*/, const ImmutableCFOptions& /*ioptions*/, const EnvOptions& /*soptions*/,
const InternalKeyComparator& /*internal_comparator*/, uint64_t file_size, const InternalKeyComparator& /*internal_comparator*/, uint64_t file_size,
unique_ptr<TableReader>* /*table_reader*/) { std::unique_ptr<TableReader>* /*table_reader*/) {
// We need to turn off pre-fetching of index and filter nodes for // We need to turn off pre-fetching of index and filter nodes for
// BlockBasedTable // BlockBasedTable
if (BlockBasedTableFactory::kName == options_.table_factory->Name()) { if (BlockBasedTableFactory::kName == options_.table_factory->Name()) {
@ -148,7 +148,7 @@ Status SstFileReader::VerifyChecksum() {
} }
Status SstFileReader::DumpTable(const std::string& out_filename) { Status SstFileReader::DumpTable(const std::string& out_filename) {
unique_ptr<WritableFile> out_file; std::unique_ptr<WritableFile> out_file;
Env* env = Env::Default(); Env* env = Env::Default();
env->NewWritableFile(out_filename, &out_file, soptions_); env->NewWritableFile(out_filename, &out_file, soptions_);
Status s = table_reader_->DumpTable(out_file.get(), Status s = table_reader_->DumpTable(out_file.get(),
@ -159,21 +159,21 @@ Status SstFileReader::DumpTable(const std::string& out_filename) {
uint64_t SstFileReader::CalculateCompressedTableSize( uint64_t SstFileReader::CalculateCompressedTableSize(
const TableBuilderOptions& tb_options, size_t block_size) { const TableBuilderOptions& tb_options, size_t block_size) {
unique_ptr<WritableFile> out_file; std::unique_ptr<WritableFile> out_file;
unique_ptr<Env> env(NewMemEnv(Env::Default())); std::unique_ptr<Env> env(NewMemEnv(Env::Default()));
env->NewWritableFile(testFileName, &out_file, soptions_); env->NewWritableFile(testFileName, &out_file, soptions_);
unique_ptr<WritableFileWriter> dest_writer; std::unique_ptr<WritableFileWriter> dest_writer;
dest_writer.reset( dest_writer.reset(
new WritableFileWriter(std::move(out_file), testFileName, soptions_)); new WritableFileWriter(std::move(out_file), testFileName, soptions_));
BlockBasedTableOptions table_options; BlockBasedTableOptions table_options;
table_options.block_size = block_size; table_options.block_size = block_size;
BlockBasedTableFactory block_based_tf(table_options); BlockBasedTableFactory block_based_tf(table_options);
unique_ptr<TableBuilder> table_builder; std::unique_ptr<TableBuilder> table_builder;
table_builder.reset(block_based_tf.NewTableBuilder( table_builder.reset(block_based_tf.NewTableBuilder(
tb_options, tb_options,
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily, TablePropertiesCollectorFactory::Context::kUnknownColumnFamily,
dest_writer.get())); dest_writer.get()));
unique_ptr<InternalIterator> iter(table_reader_->NewIterator( std::unique_ptr<InternalIterator> iter(table_reader_->NewIterator(
ReadOptions(), moptions_.prefix_extractor.get())); ReadOptions(), moptions_.prefix_extractor.get()));
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) { for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
if (!iter->status().ok()) { if (!iter->status().ok()) {

Some files were not shown because too many files have changed in this diff Show More