-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
importinto: integrate global sort(without merge-sort) part 1 #46998
Changes from all commits
9810644
33dd4ab
91d3ec4
9a97910
85ed857
c4f5647
5993797
acb1786
4c3d0b2
11b335f
fee3cc5
857fa56
3c8f67f
b66650f
65b43b4
1e5acb4
91f7e98
a148d3d
e25413d
a3e9817
c7202f7
8b59ff8
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 |
---|---|---|
|
@@ -239,3 +239,71 @@ func GetMaxOverlapping(points []Endpoint) int64 { | |
} | ||
return maxWeight | ||
} | ||
|
||
// SortedKVMeta is the meta of sorted kv. | ||
type SortedKVMeta struct { | ||
MinKey []byte `json:"min_key"` | ||
MaxKey []byte `json:"max_key"` | ||
TotalKVSize uint64 `json:"total_kv_size"` | ||
DataFiles []string `json:"data_files"` | ||
StatFiles []string `json:"stat_files"` | ||
} | ||
|
||
// NewSortedKVMeta creates a SortedKVMeta from a WriterSummary. | ||
func NewSortedKVMeta(summary *WriterSummary) *SortedKVMeta { | ||
meta := &SortedKVMeta{ | ||
MinKey: summary.Min.Clone(), | ||
MaxKey: summary.Max.Clone(), | ||
TotalKVSize: summary.TotalSize, | ||
} | ||
for _, f := range summary.MultipleFilesStats { | ||
for _, filename := range f.Filenames { | ||
meta.DataFiles = append(meta.DataFiles, filename[0]) | ||
meta.StatFiles = append(meta.StatFiles, filename[1]) | ||
} | ||
} | ||
return meta | ||
} | ||
|
||
// Merge merges the other SortedKVMeta into this one. | ||
func (m *SortedKVMeta) Merge(other *SortedKVMeta) { | ||
m.MinKey = NotNilMin(m.MinKey, other.MinKey) | ||
m.MaxKey = NotNilMax(m.MaxKey, other.MaxKey) | ||
m.TotalKVSize += other.TotalKVSize | ||
|
||
m.DataFiles = append(m.DataFiles, other.DataFiles...) | ||
m.StatFiles = append(m.StatFiles, other.StatFiles...) | ||
} | ||
|
||
// MergeSummary merges the WriterSummary into this SortedKVMeta. | ||
func (m *SortedKVMeta) MergeSummary(summary *WriterSummary) { | ||
m.Merge(NewSortedKVMeta(summary)) | ||
} | ||
|
||
// NotNilMin returns the smallest of a and b, ignoring nil values. | ||
func NotNilMin(a, b []byte) []byte { | ||
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. moved from ddl/backfilling_dispatcher.go |
||
if len(a) == 0 { | ||
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. what if both a and b nil?it will return b(nil)? 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. that's moved from add-index, didn't change 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. @Benjamin2037 Yes, returning a |
||
return b | ||
} | ||
if len(b) == 0 { | ||
return a | ||
} | ||
if bytes.Compare(a, b) < 0 { | ||
return a | ||
} | ||
return b | ||
} | ||
|
||
// NotNilMax returns the largest of a and b, ignoring nil values. | ||
func NotNilMax(a, b []byte) []byte { | ||
if len(a) == 0 { | ||
return b | ||
} | ||
if len(b) == 0 { | ||
return a | ||
} | ||
if bytes.Compare(a, b) > 0 { | ||
return a | ||
} | ||
return b | ||
} |
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.