startCompactionMonitors starts background goroutines for compaction and snapshots.
()
| 2859 | |
| 2860 | // startCompactionMonitors starts background goroutines for compaction and snapshots. |
| 2861 | func (f *VFSFile) startCompactionMonitors() { |
| 2862 | f.compactionCtx, f.compactionCancel = context.WithCancel(f.ctx) |
| 2863 | |
| 2864 | // Use configured levels or defaults |
| 2865 | levels := f.vfs.CompactionLevels |
| 2866 | if levels == nil { |
| 2867 | levels = DefaultCompactionLevels |
| 2868 | } |
| 2869 | |
| 2870 | // Start compaction monitors for each level |
| 2871 | for _, lvl := range levels { |
| 2872 | if lvl.Level == 0 { |
| 2873 | continue // L0 doesn't need compaction (source level) |
| 2874 | } |
| 2875 | f.compactionWg.Add(1) |
| 2876 | go func(level *CompactionLevel) { |
| 2877 | defer f.compactionWg.Done() |
| 2878 | f.monitorCompaction(f.compactionCtx, level) |
| 2879 | }(lvl) |
| 2880 | } |
| 2881 | |
| 2882 | // Start snapshot monitor if configured |
| 2883 | if f.vfs.SnapshotInterval > 0 { |
| 2884 | f.compactionWg.Add(1) |
| 2885 | go func() { |
| 2886 | defer f.compactionWg.Done() |
| 2887 | f.monitorSnapshots(f.compactionCtx) |
| 2888 | }() |
| 2889 | } |
| 2890 | |
| 2891 | // Start L0 retention monitor if configured |
| 2892 | if f.vfs.L0Retention > 0 { |
| 2893 | f.compactionWg.Add(1) |
| 2894 | go func() { |
| 2895 | defer f.compactionWg.Done() |
| 2896 | f.monitorL0Retention(f.compactionCtx) |
| 2897 | }() |
| 2898 | } |
| 2899 | |
| 2900 | f.logger.Info("compaction monitors started", |
| 2901 | "levels", len(levels), |
| 2902 | "snapshotInterval", f.vfs.SnapshotInterval, |
| 2903 | "l0Retention", f.vfs.L0Retention) |
| 2904 | } |
| 2905 | |
| 2906 | // Compact compacts source level files into the destination level. |
| 2907 | // Returns ErrNoCompaction if there are no files to compact. |
no test coverage detected