diff --git a/db/db_impl.cc b/db/db_impl.cc index eeb1670de..4eb7091cb 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -3655,8 +3655,13 @@ Status DBImpl::StartTrace(const TraceOptions& trace_options, Status DBImpl::EndTrace() { InstrumentedMutexLock lock(&trace_mutex_); - Status s = tracer_->Close(); - tracer_.reset(); + Status s; + if (tracer_ != nullptr) { + s = tracer_->Close(); + tracer_.reset(); + } else { + return Status::IOError("No trace file to close"); + } return s; } diff --git a/db/db_test2.cc b/db/db_test2.cc index 9a351dac0..dabb34fa9 100644 --- a/db/db_test2.cc +++ b/db/db_test2.cc @@ -2875,6 +2875,8 @@ TEST_F(DBTest2, TraceAndReplay) { Random rnd(301); Iterator* single_iter = nullptr; + ASSERT_TRUE(db_->EndTrace().IsIOError()); + std::string trace_filename = dbname_ + "/rocksdb.trace"; std::unique_ptr trace_writer; ASSERT_OK(NewFileTraceWriter(env_, env_opts, trace_filename, &trace_writer));