From c10f722de54338e1e953a3ec089d47770855d393 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Thu, 22 Feb 2024 15:03:30 -0800 Subject: [PATCH] manifest: rename PrefixReplacement methods 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`. --- sstable/reader_common.go | 12 ++++++------ sstable/reader_virtual.go | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sstable/reader_common.go b/sstable/reader_common.go index 573d08f6cc..2a704573b7 100644 --- a/sstable/reader_common.go +++ b/sstable/reader_common.go @@ -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 { diff --git a/sstable/reader_virtual.go b/sstable/reader_virtual.go index 88badcfbc8..a86fa2d3c6 100644 --- a/sstable/reader_virtual.go +++ b/sstable/reader_virtual.go @@ -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, @@ -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 */ @@ -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?