From: Igor Fedotov Date: Thu, 25 Jul 2019 10:06:50 +0000 (+0300) Subject: location hint X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fheads%2Fwip-ifed-loc-hint;p=rocksdb.git location hint --- diff --git a/db/builder.cc b/db/builder.cc index 8e944983..561b1faa 100644 --- a/db/builder.cc +++ b/db/builder.cc @@ -118,6 +118,10 @@ Status BuildTable( return s; } file->SetIOPriority(io_priority); + file->SetWriteLocationHint( + level < 0 ? + Env::LOCATION_UNSORTED : + Env::WriteLocationHint(Env::LOCATION_L0 + level)); file->SetWriteLifeTimeHint(write_hint); file_writer.reset(new WritableFileWriter(std::move(file), env_options, diff --git a/db/compaction_job.cc b/db/compaction_job.cc index 8bafabd5..493a4f31 100644 --- a/db/compaction_job.cc +++ b/db/compaction_job.cc @@ -1359,6 +1359,10 @@ Status CompactionJob::OpenCompactionOutputFile( sub_compact->outputs.push_back(out); writable_file->SetIOPriority(Env::IO_LOW); + writable_file->SetWriteLocationHint( + Env::WriteLocationHint( + Env::LOCATION_L0 + sub_compact->compaction->output_level())); + writable_file->SetWriteLifeTimeHint(write_hint_); writable_file->SetPreallocationBlockSize(static_cast( sub_compact->compaction->OutputFilePreallocationSize())); diff --git a/db/db_impl_open.cc b/db/db_impl_open.cc index 2ab34789..dc023340 100644 --- a/db/db_impl_open.cc +++ b/db/db_impl_open.cc @@ -230,6 +230,7 @@ Status DBImpl::NewDB() { } file->SetPreallocationBlockSize( immutable_db_options_.manifest_preallocation_size); + file->SetWriteLocationHint(Env::LOCATION_UNSORTED); unique_ptr file_writer( new WritableFileWriter(std::move(file), env_options)); log::Writer log(std::move(file_writer), 0, false); @@ -950,7 +951,7 @@ Status DBImpl::WriteLevel0TableForRecovery(int job_id, ColumnFamilyData* cfd, cfd->ioptions()->compression_opts, paranoid_file_checks, cfd->internal_stats(), TableFileCreationReason::kRecovery, &event_logger_, job_id, Env::IO_HIGH, nullptr /* table_properties */, - -1 /* level */, current_time, write_hint); + 0 /* level */, current_time, write_hint); LogFlush(immutable_db_options_.info_log); ROCKS_LOG_DEBUG(immutable_db_options_.info_log, "[%s] [WriteLevel0TableForRecovery]" @@ -1079,6 +1080,7 @@ Status DBImpl::Open(const DBOptions& db_options, const std::string& dbname, &lfile, opt_env_options); if (s.ok()) { lfile->SetWriteLifeTimeHint(write_hint); + lfile->SetWriteLocationHint(Env::LOCATION_WAL); lfile->SetPreallocationBlockSize( impl->GetWalPreallocateBlockSize(max_write_buffer_size)); { diff --git a/db/db_impl_write.cc b/db/db_impl_write.cc index fce910c7..b5340b27 100644 --- a/db/db_impl_write.cc +++ b/db/db_impl_write.cc @@ -1346,6 +1346,7 @@ Status DBImpl::SwitchMemtable(ColumnFamilyData* cfd, WriteContext* context, // use preallocate_block_size instead // of calling GetWalPreallocateBlockSize() lfile->SetPreallocationBlockSize(preallocate_block_size); + lfile->SetWriteLocationHint(Env::LOCATION_WAL); lfile->SetWriteLifeTimeHint(write_hint); unique_ptr file_writer( new WritableFileWriter(std::move(lfile), opt_env_opt)); diff --git a/db/version_set.cc b/db/version_set.cc index b14bea89..71f81215 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -2861,6 +2861,7 @@ Status VersionSet::LogAndApply(ColumnFamilyData* column_family_data, env_, DescriptorFileName(dbname_, pending_manifest_file_number_), &descriptor_file, opt_env_opts); if (s.ok()) { + descriptor_file->SetWriteLocationHint(Env::LOCATION_UNSORTED); descriptor_file->SetPreallocationBlockSize( db_options_->manifest_preallocation_size); diff --git a/include/rocksdb/env.h b/include/rocksdb/env.h index 79ff3f38..a7da1577 100644 --- a/include/rocksdb/env.h +++ b/include/rocksdb/env.h @@ -164,6 +164,12 @@ class Env { WLTH_EXTREME, // Data written has an extremely long life time }; + enum WriteLocationHint { + LOCATION_WAL = 1, + LOCATION_UNSORTED = 2, + LOCATION_L0 = 3, + }; + // Create an object that writes to a new file with the specified // name. Deletes any existing file with the same name and creates a // new file. On success, stores a pointer to the new file in @@ -685,6 +691,10 @@ class WritableFile { virtual Env::IOPriority GetIOPriority() { return io_priority_; } + virtual void SetWriteLocationHint(Env::WriteLocationHint) { + // do nothing + } + virtual void SetWriteLifeTimeHint(Env::WriteLifeTimeHint hint) { write_hint_ = hint; }