Skip to content

Commit 9dfc42a

Browse files
committed
blob: apply defaults to FileWriterOptions
If unspecified, apply reasonable defaults to each field of FileWriterOptions.
1 parent 51b1e1b commit 9dfc42a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sstable/blob/blob.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ type FileWriterOptions struct {
5353
FlushGovernor block.FlushGovernor
5454
}
5555

56+
func (o *FileWriterOptions) ensureDefaults() {
57+
if o.Compression <= block.DefaultCompression || o.Compression >= block.NCompression {
58+
o.Compression = block.SnappyCompression
59+
}
60+
if o.ChecksumType == block.ChecksumTypeNone {
61+
o.ChecksumType = block.ChecksumTypeCRC32c
62+
}
63+
if o.FlushGovernor == (block.FlushGovernor{}) {
64+
o.FlushGovernor = block.MakeFlushGovernor(
65+
base.DefaultBlockSize,
66+
base.DefaultBlockSizeThreshold,
67+
base.SizeClassAwareBlockSizeThreshold,
68+
nil)
69+
}
70+
}
71+
5672
// FileWriterStats aggregates statistics about a blob file written by a
5773
// FileWriter.
5874
type FileWriterStats struct {
@@ -107,6 +123,7 @@ type compressedBlock struct {
107123

108124
// NewFileWriter creates a new FileWriter.
109125
func NewFileWriter(fn base.DiskFileNum, w objstorage.Writable, opts FileWriterOptions) *FileWriter {
126+
opts.ensureDefaults()
110127
fw := writerPool.Get().(*FileWriter)
111128
fw.fileNum = fn
112129
fw.w = w
@@ -200,6 +217,9 @@ func (w *FileWriter) Close() (FileWriterStats, error) {
200217
panic(errors.AssertionFailedf("block count mismatch: %d vs %d",
201218
stats.BlockCount, len(w.blockOffsets)))
202219
}
220+
if stats.BlockCount == 0 {
221+
panic(errors.AssertionFailedf("no blocks written"))
222+
}
203223

204224
// Write the index block.
205225
vbih := valblk.IndexHandle{

0 commit comments

Comments
 (0)