Skip to content

Commit

Permalink
manifest: rename PrefixReplacement methods
Browse files Browse the repository at this point in the history
The `ReplaceArg / ReplaceResult` methods are not too descriptive, I
always have to look at the code to remember which does what. Renaming
to `Apply` and `Invert`.
  • Loading branch information
RaduBerinde committed Feb 22, 2024
1 parent b2494c5 commit c10f722
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions sstable/reader_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ type PrefixReplacement struct {
SyntheticPrefix []byte
}

// ReplaceArg replaces the new prefix in the argument with the original prefix.
func (p *PrefixReplacement) ReplaceArg(src []byte) []byte {
return p.replace(src, p.SyntheticPrefix, p.ContentPrefix)
// Apply replaces the content prefix in the key with the synthetic prefix.
func (p *PrefixReplacement) Apply(key []byte) []byte {
return p.replace(key, p.ContentPrefix, p.SyntheticPrefix)
}

// ReplaceResult replaces the original prefix in the result with the new prefix.
func (p *PrefixReplacement) ReplaceResult(key []byte) []byte {
return p.replace(key, p.ContentPrefix, p.SyntheticPrefix)
// Invert replaces the synthetic prefix in the key with the content prefix.
func (p *PrefixReplacement) Invert(src []byte) []byte {
return p.replace(src, p.SyntheticPrefix, p.ContentPrefix)
}

func (p *PrefixReplacement) replace(key, from, to []byte) []byte {
Expand Down
12 changes: 6 additions & 6 deletions sstable/reader_virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func (v *VirtualReader) NewRawRangeDelIter(
upper := &v.vState.upper

if v.vState.prefixChange != nil {
lower = &InternalKey{UserKey: v.vState.prefixChange.ReplaceArg(lower.UserKey), Trailer: lower.Trailer}
upper = &InternalKey{UserKey: v.vState.prefixChange.ReplaceArg(upper.UserKey), Trailer: upper.Trailer}
lower = &InternalKey{UserKey: v.vState.prefixChange.Invert(lower.UserKey), Trailer: lower.Trailer}
upper = &InternalKey{UserKey: v.vState.prefixChange.Invert(upper.UserKey), Trailer: upper.Trailer}

iter = keyspan.Truncate(
v.reader.Compare, iter, lower.UserKey, upper.UserKey,
Expand Down Expand Up @@ -229,8 +229,8 @@ func (v *VirtualReader) NewRawRangeKeyIter(
}

if v.vState.prefixChange != nil {
lower = &InternalKey{UserKey: v.vState.prefixChange.ReplaceArg(lower.UserKey), Trailer: lower.Trailer}
upper = &InternalKey{UserKey: v.vState.prefixChange.ReplaceArg(upper.UserKey), Trailer: upper.Trailer}
lower = &InternalKey{UserKey: v.vState.prefixChange.Invert(lower.UserKey), Trailer: lower.Trailer}
upper = &InternalKey{UserKey: v.vState.prefixChange.Invert(upper.UserKey), Trailer: upper.Trailer}
iter = keyspan.Truncate(
v.reader.Compare, iter, lower.UserKey, upper.UserKey,
lower, upper, !v.vState.upper.IsExclusiveSentinel(), /* panicOnUpperTruncate */
Expand Down Expand Up @@ -287,8 +287,8 @@ func (v *virtualState) constrainBounds(
}
}
if v.prefixChange != nil {
first = v.prefixChange.ReplaceArg(first)
last = v.prefixChange.ReplaceArg(last)
first = v.prefixChange.Invert(first)
last = v.prefixChange.Invert(last)
}
// TODO(bananabrick): What if someone passes in bounds completely outside of
// virtual sstable bounds?
Expand Down

0 comments on commit c10f722

Please sign in to comment.