Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manifest: fix bug when parsing the suffix rewrite tag #3306

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions internal/manifest/version_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const (
tagCreatedBackingTable = 105
tagRemovedBackingTable = 106

// The custom tags sub-format used by tagNewFile4 and above.
// The custom tags sub-format used by tagNewFile4 and above. All tags less
// than customTagNonSafeIgnoreMask are safe to ignore and their format must be
// a single bytes field.
customTagTerminate = 1
customTagNeedsCompaction = 2
customTagCreationTime = 6
Expand Down Expand Up @@ -348,47 +350,23 @@ func (v *VersionEdit) Decode(r io.Reader) error {
}
if customTag == customTagTerminate {
break
} else if customTag == customTagVirtual {
virtualState.virtual = true
n, err := d.readUvarint()
if err != nil {
return err
}
virtualState.backingFileNum = n
continue
} else if customTag == customTagPrefixRewrite {
content, err := d.readBytes()
if err != nil {
return err
}
synthetic, err := d.readBytes()
if err != nil {
return err
}
virtualPrefix = &PrefixReplacement{
ContentPrefix: content,
SyntheticPrefix: synthetic,
}
continue
} else if customTag == customTagSuffixRewrite {
syntheticSuffix, err = d.readBytes()
if err != nil {
return err
}
}

field, err := d.readBytes()
if err != nil {
return err
}
switch customTag {
case customTagNeedsCompaction:
field, err := d.readBytes()
if err != nil {
return err
}
if len(field) != 1 {
return base.CorruptionErrorf("new-file4: need-compaction field wrong size")
}
markedForCompaction = (field[0] == 1)

case customTagCreationTime:
field, err := d.readBytes()
if err != nil {
return err
}
var n int
creationTime, n = binary.Uvarint(field)
if n != len(field) {
Expand All @@ -398,10 +376,38 @@ func (v *VersionEdit) Decode(r io.Reader) error {
case customTagPathID:
return base.CorruptionErrorf("new-file4: path-id field not supported")

case customTagVirtual:
virtualState.virtual = true
if virtualState.backingFileNum, err = d.readUvarint(); err != nil {
return err
}

case customTagPrefixRewrite:
content, err := d.readBytes()
if err != nil {
return err
}
synthetic, err := d.readBytes()
if err != nil {
return err
}
virtualPrefix = &PrefixReplacement{
ContentPrefix: content,
SyntheticPrefix: synthetic,
}

case customTagSuffixRewrite:
if syntheticSuffix, err = d.readBytes(); err != nil {
return err
}

default:
if (customTag & customTagNonSafeIgnoreMask) != 0 {
return base.CorruptionErrorf("new-file4: custom field not supported: %d", customTag)
}
if _, err := d.readBytes(); err != nil {
return err
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions internal/manifest/version_edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func TestVERoundTripAndAccumulate(t *testing.T) {
CreationTime: 809060,
SmallestSeqNum: 9,
LargestSeqNum: 11,
PrefixReplacement: &PrefixReplacement{
ContentPrefix: []byte("before"),
SyntheticPrefix: []byte("after"),
},
SyntheticSuffix: []byte("foo"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while you're here, could you add a synthetic prefix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done. TFTR!

}).ExtendPointKeyBounds(
cmp,
base.MakeInternalKey([]byte("a"), 0, base.InternalKeyKindSet),
Expand Down Expand Up @@ -129,6 +134,7 @@ func TestVersionEditRoundTrip(t *testing.T) {
SmallestSeqNum: 3,
LargestSeqNum: 5,
MarkedForCompaction: true,
SyntheticSuffix: []byte("foo"),
}).ExtendPointKeyBounds(
cmp,
base.DecodeInternalKey([]byte("A\x00\x01\x02\x03\x04\x05\x06\x07")),
Expand Down
Loading