Skip to content

Commit cbfea02

Browse files
committed
base: move BlobReferenceID, BlobFileMapping
Move blob.ReferenceID and blob.FileMapping types into the base package, renaming them BlobReferenceID and BlobFileMapping. This removes any dependency from internal/manifest onto the sstable/blob package.
1 parent 436c169 commit cbfea02

15 files changed

+60
-60
lines changed

blob_rewrite_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func TestBlobRewriteRandomized(t *testing.T) {
296296
base.MakeInternalKey(keys[i], base.SeqNum(i), base.InternalKeyKindSet),
297297
blob.InlineHandle{
298298
InlineHandlePreface: blob.InlineHandlePreface{
299-
ReferenceID: blob.ReferenceID(0),
299+
ReferenceID: base.BlobReferenceID(0),
300300
ValueLen: uint32(len(values[i])),
301301
},
302302
HandleSuffix: blob.HandleSuffix{
@@ -415,11 +415,11 @@ func TestBlobRewriteRandomized(t *testing.T) {
415415
}
416416
}
417417

418-
// constantFileMapping implements blob.FileMapping and always maps to itself.
418+
// constantFileMapping implements base.BlobFileMapping and always maps to itself.
419419
type constantFileMapping base.DiskFileNum
420420

421-
// Assert that (*inputFileMapping) implements blob.FileMapping.
422-
var _ blob.FileMapping = constantFileMapping(0)
421+
// Assert that (*inputFileMapping) implements base.BlobFileMapping.
422+
var _ base.BlobFileMapping = constantFileMapping(0)
423423

424424
func (m constantFileMapping) Lookup(fileID base.BlobFileID) (base.DiskFileNum, bool) {
425425
return base.DiskFileNum(m), true

internal/base/filenames.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ func (id BlobFileID) SafeFormat(w redact.SafePrinter, _ rune) {
5959
w.Printf("B%06d", redact.SafeUint(id))
6060
}
6161

62+
// BlobReferenceID identifies a particular blob reference within a table. It's
63+
// implemented as an index into the slice of the BlobReferences recorded in the
64+
// manifest.
65+
type BlobReferenceID uint32
66+
67+
// BlobFileMapping defines the mapping between blob file IDs and disk file numbers.
68+
// It's implemented by *manifest.BlobFileSet.
69+
type BlobFileMapping interface {
70+
// Lookup returns the disk file number for the given blob file ID. It
71+
// returns false for the second return value if the blob file ID is not
72+
// present in the mapping.
73+
Lookup(BlobFileID) (DiskFileNum, bool)
74+
}
75+
6276
// A DiskFileNum identifies a file or object with exists on disk.
6377
type DiskFileNum uint64
6478

internal/blobtest/handles.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,13 @@ type References struct {
297297
}
298298

299299
// MapToReferenceID maps the given file number to a reference ID.
300-
func (b *References) MapToReferenceID(fileID base.BlobFileID) blob.ReferenceID {
300+
func (b *References) MapToReferenceID(fileID base.BlobFileID) base.BlobReferenceID {
301301
for i, fn := range b.fileIDs {
302302
if fn == fileID {
303-
return blob.ReferenceID(i)
303+
return base.BlobReferenceID(i)
304304
}
305305
}
306306
i := uint32(len(b.fileIDs))
307307
b.fileIDs = append(b.fileIDs, fileID)
308-
return blob.ReferenceID(i)
308+
return base.BlobReferenceID(i)
309309
}

internal/manifest/blob_metadata.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/cockroachdb/pebble/internal/invariants"
2222
"github.com/cockroachdb/pebble/internal/strparse"
2323
"github.com/cockroachdb/pebble/sstable"
24-
"github.com/cockroachdb/pebble/sstable/blob"
2524
"github.com/cockroachdb/redact"
2625
)
2726

@@ -291,20 +290,20 @@ type BlobReferences []BlobReference
291290
var _ sstable.BlobReferences = (*BlobReferences)(nil)
292291

293292
// BlobFileIDByID returns the BlobFileID for the identified BlobReference.
294-
func (br *BlobReferences) BlobFileIDByID(i blob.ReferenceID) base.BlobFileID {
293+
func (br *BlobReferences) BlobFileIDByID(i base.BlobReferenceID) base.BlobFileID {
295294
return (*br)[i].FileID
296295
}
297296

298297
// IDByBlobFileID returns the reference ID for the given BlobFileID. If the
299298
// blob file ID is not found, the second return value is false.
300299
// IDByBlobFileID is linear in the length of the BlobReferences slice.
301-
func (br *BlobReferences) IDByBlobFileID(fileID base.BlobFileID) (blob.ReferenceID, bool) {
300+
func (br *BlobReferences) IDByBlobFileID(fileID base.BlobFileID) (base.BlobReferenceID, bool) {
302301
for i, ref := range *br {
303302
if ref.FileID == fileID {
304-
return blob.ReferenceID(i), true
303+
return base.BlobReferenceID(i), true
305304
}
306305
}
307-
return blob.ReferenceID(len(*br)), false
306+
return base.BlobReferenceID(len(*br)), false
308307
}
309308

310309
// BlobFileSet contains a set of blob files that are referenced by a version.
@@ -386,8 +385,8 @@ func (s *BlobFileSet) LookupPhysical(fileID base.BlobFileID) (*PhysicalBlobFile,
386385
return nil, false
387386
}
388387

389-
// Assert that (*BlobFileSet) implements blob.FileMapping.
390-
var _ blob.FileMapping = (*BlobFileSet)(nil)
388+
// Assert that (*BlobFileSet) implements base.BlobFileMapping.
389+
var _ base.BlobFileMapping = (*BlobFileSet)(nil)
391390

392391
// clone returns a copy-on-write clone of the blob file set.
393392
func (s *BlobFileSet) clone() BlobFileSet {

level_checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ func validateBlobValueLiveness(
786786
}
787787
if err := fc.withReader(ctx, readEnv, t, func(r *sstable.Reader, readEnv sstable.ReadEnv) error {
788788
// For this sstable, gather all the blob handles -- tracking
789-
// each blob.ReferenceID + blob.BlockID's referenced
789+
// each base.BlobReferenceID + blob.BlockID's referenced
790790
// blob.BlockValueIDs.
791791
referenced, err := gatherBlobHandles(ctx, r, t.BlobReferences, valueFetcher)
792792
if err != nil {

sstable/blob/fetcher.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ type ValueReader interface {
3838
ReadIndexBlock(context.Context, block.ReadEnv, objstorage.ReadHandle) (block.BufferHandle, error)
3939
}
4040

41-
// A FileMapping defines the mapping between blob file IDs and disk file numbers.
42-
// It's implemented by *manifest.BlobFileSet.
43-
type FileMapping interface {
44-
// Lookup returns the disk file number for the given blob file ID. It
45-
// returns false for the second return value if the blob file ID is not
46-
// present in the mapping.
47-
Lookup(base.BlobFileID) (base.DiskFileNum, bool)
48-
}
49-
5041
// A ReaderProvider is an interface that can be used to retrieve a ValueReader
5142
// for a given file number.
5243
type ReaderProvider interface {
@@ -64,7 +55,7 @@ type ReaderProvider interface {
6455
// When finished with a ValueFetcher, one must call Close to release all cached
6556
// readers and block buffers.
6657
type ValueFetcher struct {
67-
fileMapping FileMapping
58+
fileMapping base.BlobFileMapping
6859
readerProvider ReaderProvider
6960
env block.ReadEnv
7061
fetchCount int
@@ -78,7 +69,7 @@ type ValueFetcher struct {
7869
var _ base.ValueFetcher = (*ValueFetcher)(nil)
7970

8071
// Init initializes the ValueFetcher.
81-
func (r *ValueFetcher) Init(fm FileMapping, rp ReaderProvider, env block.ReadEnv) {
72+
func (r *ValueFetcher) Init(fm base.BlobFileMapping, rp ReaderProvider, env block.ReadEnv) {
8273
r.fileMapping = fm
8374
r.readerProvider = rp
8475
r.env = env

sstable/blob/fetcher_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import (
2525
"github.com/stretchr/testify/require"
2626
)
2727

28-
// identityFileMapping is an implementation of FileMapping that casts a
28+
// identityFileMapping is an implementation of base.BlobFileMapping that casts a
2929
// BlobFileID to a DiskFileNum.
3030
type identityFileMapping struct{}
3131

32-
// Assert that (identityFileMapping) implements FileMapping.
33-
var _ FileMapping = identityFileMapping{}
32+
// Assert that (identityFileMapping) implements base.BlobFileMapping.
33+
var _ base.BlobFileMapping = identityFileMapping{}
3434

3535
func (identityFileMapping) Lookup(blobFileID base.BlobFileID) (base.DiskFileNum, bool) {
3636
return base.DiskFileNum(blobFileID), true

sstable/blob/handle.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,10 @@ type InlineHandle struct {
6767
HandleSuffix
6868
}
6969

70-
// ReferenceID identifies a particular blob reference within a table. It's
71-
// implemented as an index into the slice of the BlobReferences recorded in the
72-
// manifest.
73-
type ReferenceID uint32
74-
7570
// InlineHandlePreface is the prefix of an inline handle. It's eagerly decoded
7671
// when returning an InternalValue to higher layers.
7772
type InlineHandlePreface struct {
78-
ReferenceID ReferenceID
73+
ReferenceID base.BlobReferenceID
7974
ValueLen uint32
8075
}
8176

@@ -158,7 +153,7 @@ func DecodeInlineHandlePreface(src []byte) (InlineHandlePreface, []byte) {
158153
}
159154

160155
return InlineHandlePreface{
161-
ReferenceID: ReferenceID(refIdx),
156+
ReferenceID: base.BlobReferenceID(refIdx),
162157
ValueLen: valueLen,
163158
}, src
164159
}

sstable/blob/rewrite.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ func (rw *FileRewriter) Close() (FileWriterStats, error) {
110110
return stats, errors.CombineErrors(err, rw.f.Close())
111111
}
112112

113-
// inputFileMapping implements blob.FileMapping and always maps to itself.
113+
// inputFileMapping implements base.BlobFileMapping and always maps to itself.
114114
type inputFileMapping base.DiskFileNum
115115

116-
// Assert that (*inputFileMapping) implements blob.FileMapping.
117-
var _ FileMapping = inputFileMapping(0)
116+
// Assert that (*inputFileMapping) implements base.BlobFileMapping.
117+
var _ base.BlobFileMapping = inputFileMapping(0)
118118

119119
func (m inputFileMapping) Lookup(fileID base.BlobFileID) (base.DiskFileNum, bool) {
120120
return base.DiskFileNum(m), true

sstable/blob_reference_index.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *blobReferenceValues) finishCurrentBlock() {
6565
// blocks for a sstable's blob references. It maintains a refState, a slice of
6666
// blobRefValueLivenessState. This tracks the in-progress value liveness for
6767
// each blob value block for our sstable's blob references. The index of the
68-
// slice corresponds to the blob.ReferenceID.
68+
// slice corresponds to the base.BlobReferenceID.
6969
type blobRefValueLivenessWriter struct {
7070
refState []blobReferenceValues
7171
}
@@ -87,10 +87,10 @@ func (w *blobRefValueLivenessWriter) numReferences() int {
8787
// blockID, a new state is created.
8888
//
8989
// addLiveValue adds a new state for the provided refID if one does
90-
// not already exist. It assumes that any new blob.ReferenceIDs are visited in
90+
// not already exist. It assumes that any new base.BlobReferenceIDs are visited in
9191
// monotonically increasing order.
9292
func (w *blobRefValueLivenessWriter) addLiveValue(
93-
refID blob.ReferenceID, blockID blob.BlockID, valueID blob.BlockValueID, valueSize uint64,
93+
refID base.BlobReferenceID, blockID blob.BlockID, valueID blob.BlockValueID, valueSize uint64,
9494
) error {
9595
// Compute the minimum expected length of the state slice in order for our
9696
// refID to be indexable.
@@ -123,12 +123,12 @@ func (w *blobRefValueLivenessWriter) addLiveValue(
123123

124124
// finish finishes encoding the per-blob reference liveness encodings, and
125125
// returns an in-order sequence of (referenceID, encoding) pairs.
126-
func (w *blobRefValueLivenessWriter) finish() iter.Seq2[blob.ReferenceID, []byte] {
127-
return func(yield func(blob.ReferenceID, []byte) bool) {
128-
// N.B. `i` is equivalent to blob.ReferenceID.
126+
func (w *blobRefValueLivenessWriter) finish() iter.Seq2[base.BlobReferenceID, []byte] {
127+
return func(yield func(base.BlobReferenceID, []byte) bool) {
128+
// N.B. `i` is equivalent to base.BlobReferenceID.
129129
for i, state := range w.refState {
130130
state.finishCurrentBlock()
131-
if !yield(blob.ReferenceID(i), state.encodedFinishedBlocks) {
131+
if !yield(base.BlobReferenceID(i), state.encodedFinishedBlocks) {
132132
return
133133
}
134134
}

0 commit comments

Comments
 (0)