@@ -1149,45 +1149,29 @@ func (b *BulkVersionEdit) Accumulate(ve *VersionEdit) error {
11491149//
11501150// curr may be nil, which is equivalent to a pointer to a zero version.
11511151func (b * BulkVersionEdit ) Apply (
1152- curr * Version , comparer * base. Comparer , flushSplitBytes int64 , readCompactionRate int64 ,
1152+ curr * Version , flushSplitBytes int64 , readCompactionRate int64 ,
11531153) (* Version , error ) {
1154+ comparer := curr .cmp
11541155 v := & Version {
11551156 cmp : comparer ,
11561157 }
11571158
11581159 // Adjust the count of files marked for compaction.
1159- if curr != nil {
1160- v .Stats .MarkedForCompaction = curr .Stats .MarkedForCompaction
1161- }
1160+ v .Stats .MarkedForCompaction = curr .Stats .MarkedForCompaction
11621161 v .Stats .MarkedForCompaction += b .MarkedForCompactionCountDiff
11631162 if v .Stats .MarkedForCompaction < 0 {
11641163 return nil , base .CorruptionErrorf ("pebble: version marked for compaction count negative" )
11651164 }
11661165
11671166 for level := range v .Levels {
1168- if curr == nil || curr .Levels [level ].tree .root == nil {
1169- v .Levels [level ] = MakeLevelMetadata (comparer .Compare , level , nil /* files */ )
1170- } else {
1171- v .Levels [level ] = curr .Levels [level ].clone ()
1172- }
1173- if curr == nil || curr .RangeKeyLevels [level ].tree .root == nil {
1174- v .RangeKeyLevels [level ] = MakeLevelMetadata (comparer .Compare , level , nil /* files */ )
1175- } else {
1176- v .RangeKeyLevels [level ] = curr .RangeKeyLevels [level ].clone ()
1177- }
1167+ v .Levels [level ] = curr .Levels [level ].clone ()
1168+ v .RangeKeyLevels [level ] = curr .RangeKeyLevels [level ].clone ()
11781169
11791170 if len (b .AddedTables [level ]) == 0 && len (b .DeletedTables [level ]) == 0 {
11801171 // There are no edits on this level.
11811172 if level == 0 {
1182- // Initialize L0Sublevels.
1183- if curr == nil || curr .L0Sublevels == nil {
1184- if err := v .InitL0Sublevels (flushSplitBytes ); err != nil {
1185- return nil , errors .Wrap (err , "pebble: internal error" )
1186- }
1187- } else {
1188- v .L0Sublevels = curr .L0Sublevels
1189- v .L0SublevelFiles = v .L0Sublevels .Levels
1190- }
1173+ v .L0Sublevels = curr .L0Sublevels
1174+ v .L0SublevelFiles = curr .L0SublevelFiles
11911175 }
11921176 continue
11931177 }
@@ -1266,6 +1250,7 @@ func (b *BulkVersionEdit) Apply(
12661250 // Track the keys with the smallest and largest keys, so that we can
12671251 // check consistency of the modified span.
12681252 if sm == nil || base .InternalCompare (comparer .Compare , sm .Smallest , f .Smallest ) > 0 {
1253+
12691254 sm = f
12701255 }
12711256 if la == nil || base .InternalCompare (comparer .Compare , la .Largest , f .Largest ) < 0 {
@@ -1285,7 +1270,7 @@ func (b *BulkVersionEdit) Apply(
12851270 }
12861271
12871272 if level == 0 {
1288- if curr != nil && curr . L0Sublevels != nil && len (deletedTablesMap ) == 0 {
1273+ if len (deletedTablesMap ) == 0 {
12891274 // Flushes and ingestions that do not delete any L0 files do not require
12901275 // a regeneration of L0Sublevels from scratch. We can instead generate
12911276 // it incrementally.
0 commit comments