diff --git a/db/external_sst_file_ingestion_job.cc b/db/external_sst_file_ingestion_job.cc index a25e83f6e..21601f617 100644 --- a/db/external_sst_file_ingestion_job.cc +++ b/db/external_sst_file_ingestion_job.cc @@ -791,13 +791,14 @@ Status ExternalSstFileIngestionJob::AssignGlobalSeqnoForIngestedFile( fs_->NewRandomRWFile(file_to_ingest->internal_file_path, env_options_, &rwfile, nullptr); if (status.ok()) { + FSRandomRWFilePtr fsptr(std::move(rwfile), io_tracer_); std::string seqno_val; PutFixed64(&seqno_val, seqno); - status = rwfile->Write(file_to_ingest->global_seqno_offset, seqno_val, - IOOptions(), nullptr); + status = fsptr->Write(file_to_ingest->global_seqno_offset, seqno_val, + IOOptions(), nullptr); if (status.ok()) { TEST_SYNC_POINT("ExternalSstFileIngestionJob::BeforeSyncGlobalSeqno"); - status = SyncIngestedFile(rwfile.get()); + status = SyncIngestedFile(fsptr.get()); TEST_SYNC_POINT("ExternalSstFileIngestionJob::AfterSyncGlobalSeqno"); if (!status.ok()) { ROCKS_LOG_WARN(db_options_.info_log, diff --git a/env/file_system_tracer.h b/env/file_system_tracer.h index e2ade0967..f18d4a1ff 100644 --- a/env/file_system_tracer.h +++ b/env/file_system_tracer.h @@ -337,26 +337,32 @@ class FSRandomRWFileTracingWrapper : public FSRandomRWFileWrapper { // FSRandomRWFileTracingWrapper when tracing is disabled. class FSRandomRWFilePtr { public: - FSRandomRWFilePtr(FSRandomRWFile* fs, std::shared_ptr io_tracer) - : fs_(fs), + FSRandomRWFilePtr(std::unique_ptr&& fs, + std::shared_ptr io_tracer) + : fs_(std::move(fs)), io_tracer_(io_tracer), - fs_tracer_(new FSRandomRWFileTracingWrapper(fs_, io_tracer_)) {} - - explicit FSRandomRWFilePtr(FSRandomRWFile* fs) - : fs_(fs), io_tracer_(nullptr), fs_tracer_(nullptr) {} + fs_tracer_(fs_.get(), io_tracer_) {} FSRandomRWFile* operator->() const { if (io_tracer_ && io_tracer_->is_tracing_enabled()) { - return fs_tracer_; + return const_cast(&fs_tracer_); } else { - return fs_; + return fs_.get(); + } + } + + FSRandomRWFile* get() const { + if (io_tracer_ && io_tracer_->is_tracing_enabled()) { + return const_cast(&fs_tracer_); + } else { + return fs_.get(); } } private: - FSRandomRWFile* fs_; + std::unique_ptr fs_; std::shared_ptr io_tracer_; - FSRandomRWFileTracingWrapper* fs_tracer_; + FSRandomRWFileTracingWrapper fs_tracer_; }; } // namespace ROCKSDB_NAMESPACE