in scctl/pkg/plugin/diagnose/compare_holder.go [70:131]
func (h *abstractCompareHolder) Compare() *CompareResult {
result := &CompareResult{
Results: make(map[int][]string),
}
leftCh := make(chan map[string]*dump.KV, 2)
rightCh := make(chan map[string]*dump.KV, 2)
var (
add []string
update []string
del []string
)
gopool.New(gopool.Configure().Workers(5)).
Do(func(_ context.Context) {
left := h.toMap(h.Cache)
leftCh <- left
leftCh <- left
}).
Do(func(_ context.Context) {
right := h.toMap(h.DataStore)
rightCh <- right
rightCh <- right
}).
Do(func(_ context.Context) {
left := <-leftCh
right := <-rightCh
// add or update
for lk, lkv := range left {
rkv, ok := right[lk]
if !ok {
add = append(add, h.MismatchFunc(lkv))
continue
}
if rkv.Rev != lkv.Rev {
update = append(update, h.MismatchFunc(lkv))
}
}
}).
Do(func(_ context.Context) {
left := <-leftCh
right := <-rightCh
// delete
for rk, rkv := range right {
if _, ok := left[rk]; !ok {
del = append(del, h.MismatchFunc(rkv))
}
}
}).
Done()
if len(add) > 0 {
result.Results[greater] = add
}
if len(update) > 0 {
result.Results[mismatch] = update
}
if len(del) > 0 {
result.Results[less] = del
}
return result
}