tests: полный вывод сценариев, ключи mc ls, разбивка времени reconciler

This commit is contained in:
2026-11-04 20:42:57 +03:00
parent 3b403cc352
commit 3ffd41cf3c
6 changed files with 51 additions and 17 deletions
+25 -7
View File
@@ -68,6 +68,9 @@ type Report struct {
Skipped map[string]int `json:"skipped"`
Calls map[string]int `json:"calls"`
HeapAllocMB float64 `json:"heap_alloc_mb"`
// WaitMS — сколько merge-цикл простоял в ожидании очередного элемента каждого
// потока: показывает, кто (S3-листинг или запрос к БД) задаёт время обхода.
WaitMS map[string]int64 `json:"wait_ms"`
Errors []string `json:"errors"`
Items []Item `json:"items"`
}
@@ -105,7 +108,7 @@ func Run(ctx context.Context, repo Repo, store storage.Store, opt Options) (*Rep
rep := &Report{
DryRun: !opt.Apply, GraceSeconds: opt.Grace.Seconds(), Cutoff: cutoff,
Found: map[string]int{}, Fixed: map[string]int{}, Skipped: map[string]int{}, Calls: map[string]int{},
Errors: []string{}, Items: []Item{},
Errors: []string{}, Items: []Item{}, WaitMS: map[string]int64{},
}
rc := &reconciler{repo: repo, store: store, opt: opt, rep: rep, items: map[string]int{}}
@@ -139,26 +142,41 @@ func Run(ctx context.Context, repo Repo, store storage.Store, opt Options) (*Rep
})
}()
o, okO := <-objs
a, okA := <-rows
var waitS3, waitDB time.Duration
nextObj := func() (storage.Object, bool) {
t := time.Now()
o, ok := <-objs
waitS3 += time.Since(t)
return o, ok
}
nextRow := func() (*domain.Attachment, bool) {
t := time.Now()
a, ok := <-rows
waitDB += time.Since(t)
return a, ok
}
o, okO := nextObj()
a, okA := nextRow()
for okO || okA {
switch {
case okA && (!okO || a.ObjectKey < o.Key):
rep.RowsScanned++
rc.rowWithoutObject(ctx, a, cutoff)
a, okA = <-rows
a, okA = nextRow()
case okO && (!okA || o.Key < a.ObjectKey):
rep.ObjectsScanned++
rc.objectWithoutRow(ctx, o, cutoff)
o, okO = <-objs
o, okO = nextObj()
default:
rep.RowsScanned++
rep.ObjectsScanned++
rc.both(ctx, a, o, cutoff)
a, okA = <-rows
o, okO = <-objs
a, okA = nextRow()
o, okO = nextObj()
}
}
rep.WaitMS["s3_list"] = waitS3.Milliseconds()
rep.WaitMS["db_stream"] = waitDB.Milliseconds()
if err := <-objErr; err != nil {
return rep, fmt.Errorf("list objects: %w", err)
}