Skip to content

Commit 7b5e23d

Browse files
committed
sstable: validate separator keys before writing
Validate separator keys before writing them out to an index block by calling Comparer.ValidateKey.
1 parent 6ff4dbe commit 7b5e23d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sstable/rowblk_writer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type RawRowWriter struct {
5151
compression block.Compression
5252
separator Separator
5353
successor Successor
54+
validateKey base.ValidateKey
5455
tableFormat TableFormat
5556
isStrictObsolete bool
5657
writingToLowestLevel bool
@@ -1220,6 +1221,11 @@ func (w *RawRowWriter) addIndexEntry(
12201221
// In particular, it must have a non-zero length.
12211222
return nil
12221223
}
1224+
if invariants.Enabled {
1225+
if err := w.validateKey.Validate(sep.UserKey); err != nil {
1226+
return err
1227+
}
1228+
}
12231229

12241230
encoded := bhp.EncodeVarints(tmp)
12251231
if flushIndexBuf != nil {
@@ -1538,6 +1544,8 @@ func (w *RawRowWriter) Close() (err error) {
15381544
return err
15391545
}
15401546
prevKey := w.dataBlockBuf.dataBlock.CurKey()
1547+
// NB: prevKey.UserKey may be nil if there are no keys and we're forcing
1548+
// the creation of an empty data block.
15411549
if err := w.addIndexEntrySync(prevKey, InternalKey{}, bhp, w.dataBlockBuf.tmp[:]); err != nil {
15421550
return err
15431551
}
@@ -1719,6 +1727,7 @@ func newRowWriter(writable objstorage.Writable, o WriterOptions) *RawRowWriter {
17191727
compression: o.Compression,
17201728
separator: o.Comparer.Separator,
17211729
successor: o.Comparer.Successor,
1730+
validateKey: o.Comparer.ValidateKey,
17221731
tableFormat: o.TableFormat,
17231732
isStrictObsolete: o.IsStrictObsolete,
17241733
writingToLowestLevel: o.WritingToLowestLevel,

0 commit comments

Comments
 (0)