-
Notifications
You must be signed in to change notification settings - Fork 6.2k
ddl: enhance checkpoint management with chunk tracking #64607
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,10 +199,12 @@ type CheckpointManager struct { | |
|
|
||
| // taskCheckpoint is the checkpoint for a single task. | ||
| type taskCheckpoint struct { | ||
| totalKeys int | ||
| writtenKeys int | ||
| endKey kv.Key | ||
| lastBatchRead bool | ||
| totalKeys int | ||
| writtenKeys int | ||
| endKey kv.Key | ||
| lastBatchRead bool | ||
| chunksTotal int | ||
| chunksFinished int | ||
| } | ||
|
|
||
| // newCheckpointManagerWithStorage is the common constructor | ||
|
|
@@ -348,14 +350,24 @@ func (s *CheckpointManager) UpdateChunk(taskID int, delta int, last bool) { | |
| cp := s.checkpoints[taskID] | ||
| cp.totalKeys += delta | ||
| cp.lastBatchRead = last | ||
| cp.chunksTotal++ | ||
| } | ||
|
|
||
| // FinishChunk updates the written keys of the task. | ||
| // This is called by the writer after writing the local engine to update the current number of rows written. | ||
| func (s *CheckpointManager) FinishChunk(taskID int, delta int) { | ||
| s.mu.Lock() | ||
| cp := s.checkpoints[taskID] | ||
| cp, ok := s.checkpoints[taskID] | ||
| if !ok { | ||
| s.mu.Unlock() | ||
| s.logger.Warn("finish chunk for unknown task", zap.Int("taskID", taskID)) | ||
| return | ||
| } | ||
| cp.writtenKeys += delta | ||
| cp.chunksFinished++ | ||
| if cp.chunksFinished == cp.chunksTotal { | ||
| s.logger.Info("finish a index ingest task", zap.Int("id", taskID), zap.Int("totalKeys", cp.totalKeys), zap.Int("writtenKeys", cp.writtenKeys)) | ||
| } | ||
| s.mu.Unlock() | ||
| } | ||
|
|
||
|
|
@@ -396,7 +408,7 @@ func (s *CheckpointManager) afterFlush() { | |
| defer s.mu.Unlock() | ||
| for { | ||
| cp := s.checkpoints[s.minTaskIDFinished] | ||
| if cp == nil || !cp.lastBatchRead || cp.writtenKeys < cp.totalKeys { | ||
| if cp == nil || !cp.lastBatchRead || cp.writtenKeys < cp.totalKeys || cp.chunksFinished < cp.chunksTotal { | ||
|
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. IF !(cp.writtenKeys < cp.totalKeys), then chunksFinished must equal to chunksTotal?
Collaborator
Author
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. this case handle the situation when cp.writtenKeys = cp.totalKeys, but cp.chunksFinished < cp.chunksTotal, which will be fixed in #64655 |
||
| break | ||
| } | ||
| delete(s.checkpoints, s.minTaskIDFinished) | ||
|
|
||
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.
It may not be correct after we support OnDuplicateKeyRemove
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.
OnDuplicateKeyRemove should not affect chunk count, so this is not a problem