@@ -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
0 commit comments