Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c11f98d

Browse files
committedJan 16, 2025·
Address comments
1 parent b695598 commit c11f98d

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed
 

‎db/db_impl/db_impl.cc

+17-26
Original file line numberDiff line numberDiff line change
@@ -5853,35 +5853,24 @@ Status DBImpl::IngestExternalFiles(
58535853
InstrumentedMutexLock l(&mutex_);
58545854
TEST_SYNC_POINT("DBImpl::AddFile:MutexLock");
58555855

5856-
// Stop writes to the DB by entering both write threads.
5857-
// Even with allow_write = true, writes to the DB must be temporarily
5858-
// stopped to wait for pending writes. This is because allow_write = true
5859-
// only requires users to ensure no concurrent writes overlap with the
5860-
// ingestion data and does not require ensuring no overlapping
5861-
// unordered_write before ingestion.
5862-
WriteThread::Writer w;
5863-
write_thread_.EnterUnbatched(&w, &mutex_);
5864-
WriteThread::Writer nonmem_w;
5865-
if (two_write_queues_) {
5866-
nonmem_write_thread_.EnterUnbatched(&nonmem_w, &mutex_);
5867-
}
5868-
5869-
// When unordered_write is enabled, the keys are writing to memtable in an
5870-
// unordered way. If the ingestion job checks memtable key range before the
5871-
// key landing in memtable, the ingestion job may skip the necessary
5872-
// memtable flush.
5873-
// So wait here to ensure there is no pending write to memtable.
5874-
WaitForPendingWrites();
5875-
5876-
if (allow_write) {
5877-
// If allow_write is true, writes to the DB are resumed here,
5878-
// allowing users to write normally during the subsequent ingest process.
5856+
if (!allow_write) {
5857+
// Stop writes to the DB by entering both write threads.
5858+
WriteThread::Writer w;
5859+
write_thread_.EnterUnbatched(&w, &mutex_);
5860+
WriteThread::Writer nonmem_w;
58795861
if (two_write_queues_) {
5880-
nonmem_write_thread_.ExitUnbatched(&nonmem_w);
5862+
nonmem_write_thread_.EnterUnbatched(&nonmem_w, &mutex_);
58815863
}
5882-
write_thread_.ExitUnbatched(&w);
5864+
5865+
// When unordered_write is enabled, the keys are writing to memtable in an
5866+
// unordered way. If the ingestion job checks memtable key range before
5867+
// the key landing in memtable, the ingestion job may skip the necessary
5868+
// memtable flush.
5869+
// So wait here to ensure there is no pending write to memtable.
5870+
WaitForPendingWrites();
58835871
}
5884-
TEST_SYNC_POINT_CALLBACK("DBImpl::IngestExternalFile:AfterPendingWrites",
5872+
5873+
TEST_SYNC_POINT_CALLBACK("DBImpl::IngestExternalFile:AfterAllowWriteCheck",
58855874
nullptr);
58865875

58875876
num_running_ingest_file_ += static_cast<int>(num_cfs);
@@ -6036,9 +6025,11 @@ Status DBImpl::IngestExternalFiles(
60366025
}
60376026

60386027
if (!allow_write) {
6028+
WriteThread::Writer nonmem_w;
60396029
if (two_write_queues_) {
60406030
nonmem_write_thread_.ExitUnbatched(&nonmem_w);
60416031
}
6032+
WriteThread::Writer w;
60426033
write_thread_.ExitUnbatched(&w);
60436034
}
60446035

‎db/external_sst_file_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ TEST_P(ExternalSSTFileTest, WriteDuringIngest) {
23962396

23972397
// Set callback to simulate concurrent write during ingestion
23982398
SyncPoint::GetInstance()->SetCallBack(
2399-
"DBImpl::IngestExternalFile:AfterPendingWrites", [&](void*) {
2399+
"DBImpl::IngestExternalFile:AfterAllowWriteCheck", [&](void*) {
24002400
// Write a non-overlapping key
24012401
ASSERT_OK(Put("foo", "v1"));
24022402
});

0 commit comments

Comments
 (0)
Please sign in to comment.