forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 105
Publish external SST ingestion sequence reservations through the multi-batch commit queue #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gengliqi
wants to merge
14
commits into
tikv:8.10.tikv
Choose a base branch
from
gengliqi:fix-ingest-allow-write
base: 8.10.tikv
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e3426d3
fix ingest allow write
gengliqi 394c101
add more comments
gengliqi 02a4f9a
add a regression unit test
gengliqi 3d9a6b9
update comment
gengliqi 391be8a
format
gengliqi 3235185
add more comments
gengliqi 30f72f1
update test
gengliqi 7528f73
address comments
gengliqi 89d09be
add a unit test
gengliqi 42ebac3
fix multi-batch pending_memtable_writes bug
gengliqi 517307e
Merge remote-tracking branch 'upstream/8.10.tikv' into fix-ingest-all…
gengliqi 6aa04af
u
gengliqi 7ab5ed6
update
gengliqi c6ead81
remove mutex for sequence number reservation in ingestion
gengliqi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5928,16 +5928,9 @@ Status DBImpl::IngestExternalFiles( | |
| } | ||
| // Run ingestion jobs. | ||
| if (status.ok()) { | ||
| if (allow_write) { | ||
| // Briefly stop writes while reserving sequence numbers for ingestion. | ||
| write_thread_.EnterUnbatched(&w, &mutex_); | ||
| if (two_write_queues_) { | ||
| nonmem_write_thread_.EnterUnbatched(&nonmem_w, &mutex_); | ||
| } | ||
| WaitForPendingWrites(); | ||
| } | ||
|
|
||
| SequenceNumber last_seqno = versions_->LastSequence(); | ||
| const bool publish_seqno_through_commit_queue = | ||
| allow_write && immutable_db_options_.enable_multi_batch_write; | ||
| CommitRequest seqno_reservation(&w); | ||
| SequenceNumber reserved_seqno_count = 0; | ||
| if (allow_write) { | ||
| // Each file consumes at most one sequence number. Jobs for different | ||
|
|
@@ -5950,17 +5943,62 @@ Status DBImpl::IngestExternalFiles( | |
| ingestion_jobs[i].files_to_ingest().size())); | ||
| } | ||
| assert(reserved_seqno_count > 0); | ||
|
|
||
| // Become the write queue leader before reserving sequence numbers. | ||
| if (publish_seqno_through_commit_queue) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's difficult to read, how about just writing the logic twice in both |
||
| // Sequence reservation only needs write queue serialization. Keep | ||
| // the DB mutex unlocked so it cannot extend the write barrier. | ||
| mutex_.Unlock(); | ||
| write_thread_.EnterUnbatched(&w); | ||
| } else { | ||
| write_thread_.EnterUnbatched(&w, &mutex_); | ||
| } | ||
| if (two_write_queues_) { | ||
| if (publish_seqno_through_commit_queue) { | ||
| nonmem_write_thread_.EnterUnbatched(&nonmem_w); | ||
| } else { | ||
| nonmem_write_thread_.EnterUnbatched(&nonmem_w, &mutex_); | ||
| } | ||
| } | ||
| if (!publish_seqno_through_commit_queue) { | ||
| WaitForPendingWrites(); | ||
| } | ||
| } | ||
|
|
||
| SequenceNumber last_seqno = | ||
| publish_seqno_through_commit_queue | ||
| ? write_thread_.UpdateLastSequence(versions_->LastSequence()) | ||
| : versions_->LastSequence(); | ||
| if (allow_write) { | ||
| const SequenceNumber reserved_last_seqno = | ||
| last_seqno + reserved_seqno_count; | ||
| versions_->SetLastAllocatedSequence(reserved_last_seqno); | ||
| versions_->SetLastPublishedSequence(reserved_last_seqno); | ||
| versions_->SetLastSequence(reserved_last_seqno); | ||
| if (publish_seqno_through_commit_queue) { | ||
| // Publish the reservation after preceding multi-batch writers, but | ||
| // release the write queue immediately so later writers can proceed. | ||
| write_thread_.UpdateLastSequence(reserved_last_seqno); | ||
| seqno_reservation.commit_lsn = reserved_last_seqno; | ||
| write_thread_.EnterCommitQueue(&seqno_reservation); | ||
| // Keep global barriers from passing until the reservation is | ||
| // published. | ||
| ++pending_memtable_writes_; | ||
| } else { | ||
| versions_->SetLastPublishedSequence(reserved_last_seqno); | ||
| versions_->SetLastSequence(reserved_last_seqno); | ||
| } | ||
| // Resume writes | ||
| if (two_write_queues_) { | ||
| nonmem_write_thread_.ExitUnbatched(&nonmem_w); | ||
| } | ||
| write_thread_.ExitUnbatched(&w); | ||
|
|
||
| if (publish_seqno_through_commit_queue) { | ||
| TEST_SYNC_POINT( | ||
| "DBImpl::IngestExternalFiles:BeforeWaitForSeqnoReservation"); | ||
| MultiBatchWriteCommit(&seqno_reservation); | ||
| mutex_.Lock(); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // The reservation cannot be rolled back if ingestion fails because a | ||
| // foreground write may have already consumed a later sequence number. | ||
| TEST_SYNC_POINT("DBImpl::IngestExternalFiles:AfterReserveSeqno"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment here