Skip to content

Commit fdd04af

Browse files
committed
db: extract determineExcisedTableSize from exciseTable
1 parent 781add9 commit fdd04af

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

excise.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,9 @@ func (d *DB) exciseTable(
117117
}
118118

119119
if leftTable.HasRangeKeys || leftTable.HasPointKeys {
120-
var err error
121-
leftTable.Size, err = d.fileCache.estimateSize(m, leftTable.Smallest.UserKey, leftTable.Largest.UserKey)
122-
if err != nil {
120+
if err := determineExcisedTableSize(d.fileCache, m, leftTable); err != nil {
123121
return nil, nil, err
124122
}
125-
if leftTable.Size == 0 {
126-
// On occasion, estimateSize gives us a low estimate, i.e. a 0 file size,
127-
// such as if the excised file only has range keys/dels and no point
128-
// keys. This can cause panics in places where we divide by file sizes.
129-
// Correct for it here.
130-
leftTable.Size = 1
131-
}
132123
if err := leftTable.Validate(d.cmp, d.opts.Comparer.FormatKey); err != nil {
133124
return nil, nil, err
134125
}
@@ -158,18 +149,9 @@ func (d *DB) exciseTable(
158149
return nil, nil, err
159150
}
160151
if rightTable.HasRangeKeys || rightTable.HasPointKeys {
161-
var err error
162-
rightTable.Size, err = d.fileCache.estimateSize(m, rightTable.Smallest.UserKey, rightTable.Largest.UserKey)
163-
if err != nil {
152+
if err := determineExcisedTableSize(d.fileCache, m, rightTable); err != nil {
164153
return nil, nil, err
165154
}
166-
if rightTable.Size == 0 {
167-
// On occasion, estimateSize gives us a low estimate, i.e. a 0 file size,
168-
// such as if the excised file only has range keys/dels and no point keys.
169-
// This can cause panics in places where we divide by file sizes. Correct
170-
// for it here.
171-
rightTable.Size = 1
172-
}
173155
if err := rightTable.Validate(d.cmp, d.opts.Comparer.FormatKey); err != nil {
174156
return nil, nil, err
175157
}
@@ -338,6 +320,24 @@ func determineRightTableBounds(
338320
return nil
339321
}
340322

323+
func determineExcisedTableSize(
324+
fc *fileCacheHandle, originalTable, excisedTable *tableMetadata,
325+
) error {
326+
size, err := fc.estimateSize(originalTable, excisedTable.Smallest.UserKey, excisedTable.Largest.UserKey)
327+
if err != nil {
328+
return err
329+
}
330+
excisedTable.Size = size
331+
if size == 0 {
332+
// On occasion, estimateSize gives us a low estimate, i.e. a 0 file size,
333+
// such as if the excised file only has range keys/dels and no point
334+
// keys. This can cause panics in places where we divide by file sizes.
335+
// Correct for it here.
336+
excisedTable.Size = 1
337+
}
338+
return nil
339+
}
340+
341341
// applyExciseToVersionEdit updates ve with a table deletion for the original
342342
// table and table additions for the left and/or right table.
343343
//

0 commit comments

Comments
 (0)