@@ -139,6 +139,66 @@ func (i BlobFileDeleteInfo) SafeFormat(w redact.SafePrinter, _ rune) {
139
139
w .Printf ("[JOB %d] blob file deleted %s" , redact .Safe (i .JobID ), i .FileNum )
140
140
}
141
141
142
+ // BlobFileRewriteInfo contains the info for a blob file rewrite event.
143
+ type BlobFileRewriteInfo struct {
144
+ // JobID is the ID of the job.
145
+ JobID int
146
+ // Input contains the input tables for the compaction organized by level.
147
+ Input BlobFileInfo
148
+ // Output contains the output tables generated by the compaction. The output
149
+ // info is empty for the compaction begin event.
150
+ Output BlobFileInfo
151
+ // Duration is the time spent compacting, including reading and writing
152
+ // files.
153
+ Duration time.Duration
154
+ // TotalDuration is the total wall-time duration of the compaction,
155
+ // including applying the compaction to the database. TotalDuration is
156
+ // always ≥ Duration.
157
+ TotalDuration time.Duration
158
+ Done bool
159
+ // Err is set only if Done is true. If non-nil, indicates that the compaction
160
+ // failed. Note that err can be ErrCancelledCompaction, which can happen
161
+ // during normal operation.
162
+ Err error
163
+ }
164
+
165
+ func (i BlobFileRewriteInfo ) String () string {
166
+ return redact .StringWithoutMarkers (i )
167
+ }
168
+
169
+ // SafeFormat implements redact.SafeFormatter.
170
+ func (i BlobFileRewriteInfo ) SafeFormat (w redact.SafePrinter , _ rune ) {
171
+ if i .Err != nil {
172
+ w .Printf ("[JOB %d] blob file (%s, %s) rewrite error: %s" ,
173
+ redact .Safe (i .JobID ), i .Input .BlobFileID , i .Input .DiskFileNum , i .Err )
174
+ return
175
+ }
176
+
177
+ if ! i .Done {
178
+ w .Printf ("[JOB %d] rewriting blob file %s (physical file %s)" ,
179
+ redact .Safe (i .JobID ), i .Input .BlobFileID , i .Input .DiskFileNum )
180
+ return
181
+ }
182
+ w .Printf ("[JOB %d] rewrote blob file (%s, %s) -> (%s, %s), in %.1fs (%.1fs total)" ,
183
+ redact .Safe (i .JobID ), i .Input .BlobFileID , i .Input .DiskFileNum ,
184
+ i .Output .BlobFileID , i .Output .DiskFileNum ,
185
+ redact .Safe (i .Duration .Seconds ()),
186
+ redact .Safe (i .TotalDuration .Seconds ()))
187
+ }
188
+
189
+ // BlobFileInfo describes a blob file.
190
+ type BlobFileInfo struct {
191
+ // BlobFileID is the logical ID of the blob file.
192
+ BlobFileID base.BlobFileID
193
+ // DiskFileNum is the file number of the blob file on disk.
194
+ DiskFileNum base.DiskFileNum
195
+ // Size is the physical size of the file in bytes.
196
+ Size uint64
197
+ // ValueSize is the pre-compressed size of the values in the blob file in
198
+ // bytes.
199
+ ValueSize uint64
200
+ }
201
+
142
202
// CompactionInfo contains the info for a compaction event.
143
203
type CompactionInfo struct {
144
204
// JobID is the ID of the compaction job.
@@ -802,6 +862,12 @@ type EventListener struct {
802
862
// BlobFileDeleted is invoked after a blob file has been deleted.
803
863
BlobFileDeleted func (BlobFileDeleteInfo )
804
864
865
+ // BlobFileRewriteBegin is invoked when a blob file rewrite compaction begins.
866
+ BlobFileRewriteBegin func (BlobFileRewriteInfo )
867
+
868
+ // BlobFileRewriteEnd is invoked when a blob file rewrite compaction ends.
869
+ BlobFileRewriteEnd func (BlobFileRewriteInfo )
870
+
805
871
// DataCorruption is invoked when an on-disk corruption is detected. It should
806
872
// not block, as it is called synchronously in read paths.
807
873
DataCorruption func (DataCorruptionInfo )
@@ -907,6 +973,12 @@ func (l *EventListener) EnsureDefaults(logger Logger) {
907
973
if l .BlobFileDeleted == nil {
908
974
l .BlobFileDeleted = func (info BlobFileDeleteInfo ) {}
909
975
}
976
+ if l .BlobFileRewriteBegin == nil {
977
+ l .BlobFileRewriteBegin = func (info BlobFileRewriteInfo ) {}
978
+ }
979
+ if l .BlobFileRewriteEnd == nil {
980
+ l .BlobFileRewriteEnd = func (info BlobFileRewriteInfo ) {}
981
+ }
910
982
if l .DataCorruption == nil {
911
983
if logger != nil {
912
984
l .DataCorruption = func (info DataCorruptionInfo ) {
@@ -998,6 +1070,12 @@ func MakeLoggingEventListener(logger Logger) EventListener {
998
1070
BlobFileDeleted : func (info BlobFileDeleteInfo ) {
999
1071
logger .Infof ("%s" , info )
1000
1072
},
1073
+ BlobFileRewriteBegin : func (info BlobFileRewriteInfo ) {
1074
+ logger .Infof ("%s" , info )
1075
+ },
1076
+ BlobFileRewriteEnd : func (info BlobFileRewriteInfo ) {
1077
+ logger .Infof ("%s" , info )
1078
+ },
1001
1079
DataCorruption : func (info DataCorruptionInfo ) {
1002
1080
logger .Errorf ("%s" , info )
1003
1081
},
@@ -1084,6 +1162,14 @@ func TeeEventListener(a, b EventListener) EventListener {
1084
1162
a .BlobFileDeleted (info )
1085
1163
b .BlobFileDeleted (info )
1086
1164
},
1165
+ BlobFileRewriteBegin : func (info BlobFileRewriteInfo ) {
1166
+ a .BlobFileRewriteBegin (info )
1167
+ b .BlobFileRewriteBegin (info )
1168
+ },
1169
+ BlobFileRewriteEnd : func (info BlobFileRewriteInfo ) {
1170
+ a .BlobFileRewriteEnd (info )
1171
+ b .BlobFileRewriteEnd (info )
1172
+ },
1087
1173
DataCorruption : func (info DataCorruptionInfo ) {
1088
1174
a .DataCorruption (info )
1089
1175
b .DataCorruption (info )
0 commit comments