@@ -6,9 +6,11 @@ package pebble
6
6
7
7
import (
8
8
"bytes"
9
+ stdcmp "cmp"
9
10
"context"
10
11
"fmt"
11
12
"iter"
13
+ "maps"
12
14
"math"
13
15
"runtime/pprof"
14
16
"slices"
@@ -331,6 +333,8 @@ type tableCompaction struct {
331
333
332
334
tableFormat sstable.TableFormat
333
335
objCreateOpts objstorage.CreateOptions
336
+
337
+ annotations []string
334
338
}
335
339
336
340
// Assert that tableCompaction implements the compaction interface.
@@ -2681,6 +2685,7 @@ func (d *DB) compact1(jobID JobID, c *tableCompaction) (err error) {
2681
2685
2682
2686
ve , stats , err := d .runCompaction (jobID , c )
2683
2687
2688
+ info .Annotations = append (info .Annotations , c .annotations ... )
2684
2689
info .Duration = d .timeNow ().Sub (startTime )
2685
2690
if err == nil {
2686
2691
validateVersionEdit (ve , d .opts .Comparer .ValidateKey , d .opts .Comparer .FormatKey , d .opts .Logger )
@@ -3114,6 +3119,13 @@ func (d *DB) runDeleteOnlyCompaction(
3114
3119
}
3115
3120
return false
3116
3121
})
3122
+ sort .Slice (ve .NewTables , func (i , j int ) bool {
3123
+ return ve .NewTables [i ].Meta .TableNum < ve .NewTables [j ].Meta .TableNum
3124
+ })
3125
+ deletedTableEntries := slices .Collect (maps .Keys (ve .DeletedTables ))
3126
+ slices .SortFunc (deletedTableEntries , func (a , b manifest.DeletedTableEntry ) int {
3127
+ return stdcmp .Compare (a .FileNum , b .FileNum )
3128
+ })
3117
3129
// Remove any entries from CreatedBackingTables that are not used in any
3118
3130
// NewFiles.
3119
3131
usedBackingFiles := make (map [base.DiskFileNum ]struct {})
@@ -3126,6 +3138,22 @@ func (d *DB) runDeleteOnlyCompaction(
3126
3138
_ , used := usedBackingFiles [b .DiskFileNum ]
3127
3139
return ! used
3128
3140
})
3141
+
3142
+ // Iterate through the deleted tables and new tables to annotate excised tables.
3143
+ // If a new table is virtual and the base.DiskFileNum is the same as a deleted table, then
3144
+ // our deleted table was excised.
3145
+ for _ , table := range deletedTableEntries {
3146
+ for _ , newEntry := range ve .NewTables {
3147
+ if newEntry .Meta .Virtual &&
3148
+ newEntry .Meta .TableBacking .DiskFileNum == ve .DeletedTables [table ].TableBacking .DiskFileNum {
3149
+ c .annotations = append (c .annotations ,
3150
+ fmt .Sprintf ("(excised: %s)" , ve .DeletedTables [table ].TableNum ))
3151
+ break
3152
+ }
3153
+ }
3154
+
3155
+ }
3156
+
3129
3157
// Refresh the disk available statistic whenever a compaction/flush
3130
3158
// completes, before re-acquiring the mutex.
3131
3159
d .calculateDiskAvailableBytes ()
0 commit comments