From 68b46a2e3699180609b65c2529b86b067bd1829d Mon Sep 17 00:00:00 2001 From: haoyuhuang Date: Sun, 30 Jun 2019 19:54:28 -0700 Subject: [PATCH] Block cache tracer: StartTrace return busy if trace is already started. (#5519) Summary: This PR is needed for integration into MyRocks. A second call on StartTrace returns Busy so that MyRocks may return an error to the user. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5519 Test Plan: make clean && USE_CLANG=1 make check -j32 Differential Revision: D16055476 Pulled By: HaoyuHuang fbshipit-source-id: a51772fb0965c873922757eb470a332b1e02a91d --- trace_replay/block_cache_tracer.cc | 2 +- trace_replay/block_cache_tracer_test.cc | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/trace_replay/block_cache_tracer.cc b/trace_replay/block_cache_tracer.cc index 4c5ad0116..b163216d8 100644 --- a/trace_replay/block_cache_tracer.cc +++ b/trace_replay/block_cache_tracer.cc @@ -233,7 +233,7 @@ Status BlockCacheTracer::StartTrace( std::unique_ptr&& trace_writer) { InstrumentedMutexLock lock_guard(&trace_writer_mutex_); if (writer_.load()) { - return Status::OK(); + return Status::Busy(); } trace_options_ = trace_options; writer_.store( diff --git a/trace_replay/block_cache_tracer_test.cc b/trace_replay/block_cache_tracer_test.cc index 44cba7bfb..e7a588104 100644 --- a/trace_replay/block_cache_tracer_test.cc +++ b/trace_replay/block_cache_tracer_test.cc @@ -195,6 +195,17 @@ TEST_F(BlockCacheTracerTest, AtomicWrite) { } } +TEST_F(BlockCacheTracerTest, ConsecutiveStartTrace) { + TraceOptions trace_opt; + std::unique_ptr trace_writer; + ASSERT_OK( + NewFileTraceWriter(env_, env_options_, trace_file_path_, &trace_writer)); + BlockCacheTracer writer; + ASSERT_OK(writer.StartTrace(env_, trace_opt, std::move(trace_writer))); + ASSERT_NOK(writer.StartTrace(env_, trace_opt, std::move(trace_writer))); + ASSERT_OK(env_->FileExists(trace_file_path_)); +} + TEST_F(BlockCacheTracerTest, AtomicNoWriteAfterEndTrace) { BlockCacheTraceRecord record = GenerateAccessRecord(); {