|
11 | 11 | #include "port/stack_trace.h"
|
12 | 12 | #include "rocksdb/advanced_options.h"
|
13 | 13 | #include "rocksdb/options.h"
|
| 14 | +#include "rocksdb/perf_context.h" |
14 | 15 | #include "rocksdb/sst_file_writer.h"
|
15 | 16 | #include "test_util/testharness.h"
|
16 | 17 | #include "test_util/testutil.h"
|
@@ -260,14 +261,56 @@ TEST_F(ExternalSSTFileBasicTest, Basic) {
|
260 | 261 | ASSERT_NOK(s) << s.ToString();
|
261 | 262 |
|
262 | 263 | DestroyAndReopen(options);
|
| 264 | + |
| 265 | + SyncPoint::GetInstance()->LoadDependency({ |
| 266 | + {"DBImpl::IngestExternalFile:AfterIncIngestFileCounter", |
| 267 | + "ExternalSSTFileBasicTest.LiveWriteStart"}, |
| 268 | + {"ExternalSSTFileBasicTest.LiveWriteStart", |
| 269 | + "DBImpl::IngestExternalFiles:InstallSVForFirstCF:0"}, |
| 270 | + }); |
| 271 | + SyncPoint::GetInstance()->EnableProcessing(); |
| 272 | + PerfContext* write_thread_perf_context; |
| 273 | + std::thread write_thread([&] { |
| 274 | + TEST_SYNC_POINT("ExternalSSTFileBasicTest.LiveWriteStart"); |
| 275 | + SetPerfLevel(kEnableWait); |
| 276 | + write_thread_perf_context = get_perf_context(); |
| 277 | + write_thread_perf_context->Reset(); |
| 278 | + ASSERT_OK(db_->Put(WriteOptions(), "bar", "v2")); |
| 279 | + ASSERT_GT(write_thread_perf_context->write_thread_wait_nanos, 0); |
| 280 | + // Test sync points were used to make sure this live write enter write |
| 281 | + // thread after the file ingestion entered write thread. So by the time this |
| 282 | + // live write finishes, the latest seqno is 1 means file ingestion used |
| 283 | + // seqno 0. |
| 284 | + ASSERT_EQ(db_->GetLatestSequenceNumber(), 1U); |
| 285 | + }); |
| 286 | + |
263 | 287 | // Add file using file path
|
| 288 | + SetPerfLevel(kEnableTimeExceptForMutex); |
| 289 | + PerfContext* perf_ctx = get_perf_context(); |
| 290 | + perf_ctx->Reset(); |
264 | 291 | s = DeprecatedAddFile({file1});
|
| 292 | + ASSERT_GT(perf_context.file_ingestion_nanos, 0); |
| 293 | + ASSERT_GT(perf_context.file_ingestion_blocking_live_writes_nanos, 0); |
265 | 294 | ASSERT_OK(s) << s.ToString();
|
266 |
| - ASSERT_EQ(db_->GetLatestSequenceNumber(), 0U); |
267 | 295 | for (int k = 0; k < 100; k++) {
|
268 | 296 | ASSERT_EQ(Get(Key(k)), Key(k) + "_val");
|
269 | 297 | }
|
270 | 298 |
|
| 299 | + write_thread.join(); |
| 300 | + ASSERT_GT(perf_context.file_ingestion_blocking_live_writes_nanos, |
| 301 | + write_thread_perf_context->write_thread_wait_nanos); |
| 302 | + SyncPoint::GetInstance()->DisableProcessing(); |
| 303 | + |
| 304 | + // Re-ingest the file just to check the perf context not enabled at and below |
| 305 | + // kEnableWait. |
| 306 | + SetPerfLevel(kEnableWait); |
| 307 | + perf_ctx->Reset(); |
| 308 | + IngestExternalFileOptions opts; |
| 309 | + opts.allow_global_seqno = true; |
| 310 | + opts.allow_blocking_flush = true; |
| 311 | + ASSERT_OK(db_->IngestExternalFile({file1}, opts)); |
| 312 | + ASSERT_EQ(perf_context.file_ingestion_nanos, 0); |
| 313 | + ASSERT_EQ(perf_context.file_ingestion_blocking_live_writes_nanos, 0); |
271 | 314 | DestroyAndRecreateExternalSSTFilesDir();
|
272 | 315 | }
|
273 | 316 |
|
|
0 commit comments