@@ -174,6 +174,15 @@ func (k compactionKind) String() string {
174174 return "?"
175175}
176176
177+ // compactingOrFlushing returns "flushing" if the compaction kind is a flush,
178+ // otherwise it returns "compacting".
179+ func (k compactionKind ) compactingOrFlushing () string {
180+ if k == compactionKindFlush {
181+ return "flushing"
182+ }
183+ return "compacting"
184+ }
185+
177186// compaction is a table compaction from one level to the next, starting from a
178187// given version.
179188type compaction struct {
@@ -3143,7 +3152,7 @@ func (d *DB) compactAndWrite(
31433152 }
31443153 // Create a new table.
31453154 writerOpts := d .opts .MakeWriterOptions (c .outputLevel .level , tableFormat )
3146- objMeta , tw , err := d .newCompactionOutput (jobID , c , writerOpts )
3155+ objMeta , tw , err := d .newCompactionOutputTable (jobID , c , writerOpts )
31473156 if err != nil {
31483157 return runner .Finish ().WithError (err )
31493158 }
@@ -3271,43 +3280,56 @@ func (c *compaction) makeVersionEdit(result compact.Result) (*versionEdit, error
32713280 return ve , nil
32723281}
32733282
3274- // newCompactionOutput creates an object for a new table produced by a
3283+ // newCompactionOutputTable creates an object for a new table produced by a
32753284// compaction or flush.
3276- func (d * DB ) newCompactionOutput (
3285+ func (d * DB ) newCompactionOutputTable (
32773286 jobID JobID , c * compaction , writerOpts sstable.WriterOptions ,
32783287) (objstorage.ObjectMetadata , sstable.RawWriter , error ) {
3279- writable , objMeta , err := d .newCompactionOutputObj (jobID , c , base .FileTypeTable )
3288+ writable , objMeta , err := d .newCompactionOutputObj (c , base .FileTypeTable )
32803289 if err != nil {
32813290 return objstorage.ObjectMetadata {}, nil , err
32823291 }
3283-
3284- var reason string
3285- if c .kind == compactionKindFlush {
3286- reason = "flushing"
3287- } else {
3288- reason = "compacting"
3289- }
32903292 d .opts .EventListener .TableCreated (TableCreateInfo {
32913293 JobID : int (jobID ),
3292- Reason : reason ,
3294+ Reason : c . kind . compactingOrFlushing () ,
32933295 Path : d .objProvider .Path (objMeta ),
32943296 FileNum : objMeta .DiskFileNum ,
32953297 })
3296-
32973298 writerOpts .SetInternal (sstableinternal.WriterOptions {
32983299 CacheOpts : sstableinternal.CacheOptions {
32993300 CacheHandle : d .cacheHandle ,
33003301 FileNum : objMeta .DiskFileNum ,
33013302 },
33023303 })
3303-
33043304 tw := sstable .NewRawWriterWithCPUMeasurer (writable , writerOpts , c .grantHandle )
33053305 return objMeta , tw , nil
33063306}
33073307
3308+ // Allow the newCompactionOutputBlob method to be unused for now.
3309+ // TODO(jackson): Hook this up.
3310+ var _ = (* DB ).newCompactionOutputBlob
3311+
3312+ // newCompactionOutputBlob creates an object for a new blob produced by a
3313+ // compaction or flush.
3314+ func (d * DB ) newCompactionOutputBlob (
3315+ jobID JobID , c * compaction ,
3316+ ) (objstorage.Writable , objstorage.ObjectMetadata , error ) {
3317+ writable , objMeta , err := d .newCompactionOutputObj (c , base .FileTypeBlob )
3318+ if err != nil {
3319+ return nil , objstorage.ObjectMetadata {}, err
3320+ }
3321+ d .opts .EventListener .BlobFileCreated (BlobFileCreateInfo {
3322+ JobID : int (jobID ),
3323+ Reason : c .kind .compactingOrFlushing (),
3324+ Path : d .objProvider .Path (objMeta ),
3325+ FileNum : objMeta .DiskFileNum ,
3326+ })
3327+ return writable , objMeta , nil
3328+ }
3329+
33083330// newCompactionOutputObj creates an object produced by a compaction or flush.
33093331func (d * DB ) newCompactionOutputObj (
3310- jobID JobID , c * compaction , typ base.FileType ,
3332+ c * compaction , typ base.FileType ,
33113333) (objstorage.Writable , objstorage.ObjectMetadata , error ) {
33123334 diskFileNum := d .mu .versions .getNextDiskFileNum ()
33133335
0 commit comments