monitorCompaction runs periodic compaction for a level.
(ctx context.Context, lvl *CompactionLevel)
| 2988 | |
| 2989 | // monitorCompaction runs periodic compaction for a level. |
| 2990 | func (f *VFSFile) monitorCompaction(ctx context.Context, lvl *CompactionLevel) { |
| 2991 | f.logger.Info("starting VFS compaction monitor", "level", lvl.Level, "interval", lvl.Interval) |
| 2992 | |
| 2993 | ticker := time.NewTicker(lvl.Interval) |
| 2994 | defer ticker.Stop() |
| 2995 | |
| 2996 | for { |
| 2997 | select { |
| 2998 | case <-ctx.Done(): |
| 2999 | return |
| 3000 | case <-ticker.C: |
| 3001 | info, err := f.Compact(ctx, lvl.Level) |
| 3002 | if err != nil { |
| 3003 | if !errors.Is(err, ErrNoCompaction) && |
| 3004 | !errors.Is(err, context.Canceled) && |
| 3005 | !errors.Is(err, context.DeadlineExceeded) { |
| 3006 | f.logger.Error("compaction failed", "level", lvl.Level, "error", err) |
| 3007 | } |
| 3008 | } else { |
| 3009 | f.logger.Debug("compaction completed", |
| 3010 | "level", lvl.Level, |
| 3011 | "minTXID", info.MinTXID, |
| 3012 | "maxTXID", info.MaxTXID, |
| 3013 | "size", info.Size) |
| 3014 | } |
| 3015 | } |
| 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | // monitorSnapshots runs periodic snapshot creation. |
| 3020 | func (f *VFSFile) monitorSnapshots(ctx context.Context) { |
no test coverage detected