Skip to content

Commit

Permalink
This is an automated cherry-pick of tikv#7537
Browse files Browse the repository at this point in the history
close tikv#7535

Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
lhy1024 authored and ti-chi-bot committed Feb 20, 2024
1 parent b092996 commit d94b5d4
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions server/core/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,22 +562,44 @@ func DistinctScore(labels []string, stores []*StoreInfo, other *StoreInfo) float
return score
}

<<<<<<< HEAD:server/core/store.go

Check failure on line 565 in server/core/store.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: non-declaration statement outside function body
// MergeLabels merges the passed in labels with origins, overriding duplicated
// ones.
func (s *StoreInfo) MergeLabels(labels []*metapb.StoreLabel) []*metapb.StoreLabel {
storeLabels := s.GetLabels()
L:

Check failure on line 570 in server/core/store.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: missing statement after label
=======

Check failure on line 571 in server/core/store.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected ==, expecting }
// MergeLabels merges the passed in labels with origins, overriding duplicated ones.
// Note: To prevent potential data races, it is advisable to refrain from directly modifying the 'origin' variable.
func MergeLabels(origin []*metapb.StoreLabel, labels []*metapb.StoreLabel) []*metapb.StoreLabel {
results := make([]*metapb.StoreLabel, 0, len(origin))
for _, label := range origin {
results = append(results, &metapb.StoreLabel{
Key: label.Key,
Value: label.Value,
})
}

>>>>>>> 1772ad02e (core: fix datarace in MergeLabels (#7537)):pkg/core/store.go

Check failure on line 583 in server/core/store.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected >>, expecting }

Check failure on line 583 in server/core/store.go

View workflow job for this annotation

GitHub Actions / statics

invalid character U+0023 '#'
for _, newLabel := range labels {
for _, label := range storeLabels {
found := false
for _, label := range results {
if strings.EqualFold(label.Key, newLabel.Key) {
// Update the value for an existing key.
label.Value = newLabel.Value
continue L
found = true
break
}
}
storeLabels = append(storeLabels, newLabel)
// Add a new label if the key doesn't exist in the original slice.
if !found {
results = append(results, newLabel)
}
}
res := storeLabels[:0]
for _, l := range storeLabels {

// Filter out labels with an empty value.
res := results[:0]
for _, l := range results {
if l.Value != "" {
res = append(res, l)
}
Expand Down

0 comments on commit d94b5d4

Please sign in to comment.