github.com/cockroachdb/pebble@v1.1.1-0.20240513155919-3622ade60459/internal/keyspan/internal_iter_shim.go (about) 1 // Copyright 2022 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package keyspan 6 7 import "github.com/cockroachdb/pebble/internal/base" 8 9 // InternalIteratorShim is a temporary iterator type used as a shim between 10 // keyspan.MergingIter and base.InternalIterator. It's used temporarily for 11 // range deletions during compactions, allowing range deletions to be 12 // interleaved by a compaction input iterator. 13 // 14 // TODO(jackson): This type should be removed, and the usages converted to using 15 // an InterleavingIterator type that interleaves keyspan.Spans from a 16 // keyspan.FragmentIterator with point keys. 17 type InternalIteratorShim struct { 18 miter MergingIter 19 mbufs MergingBuffers 20 span *Span 21 iterKey base.InternalKey 22 } 23 24 // Assert that InternalIteratorShim implements InternalIterator. 25 var _ base.InternalIterator = &InternalIteratorShim{} 26 27 // Init initializes the internal iterator shim to merge the provided fragment 28 // iterators. 29 func (i *InternalIteratorShim) Init(cmp base.Compare, iters ...FragmentIterator) { 30 i.miter.Init(cmp, noopTransform, &i.mbufs, iters...) 31 } 32 33 // Span returns the span containing the full set of keys over the key span at 34 // the current iterator position. 35 func (i *InternalIteratorShim) Span() *Span { 36 return i.span 37 } 38 39 // SeekGE implements (base.InternalIterator).SeekGE. 40 func (i *InternalIteratorShim) SeekGE( 41 key []byte, flags base.SeekGEFlags, 42 ) (*base.InternalKey, base.LazyValue) { 43 panic("unimplemented") 44 } 45 46 // SeekPrefixGE implements (base.InternalIterator).SeekPrefixGE. 47 func (i *InternalIteratorShim) SeekPrefixGE( 48 prefix, key []byte, flags base.SeekGEFlags, 49 ) (*base.InternalKey, base.LazyValue) { 50 panic("unimplemented") 51 } 52 53 // SeekLT implements (base.InternalIterator).SeekLT. 54 func (i *InternalIteratorShim) SeekLT( 55 key []byte, flags base.SeekLTFlags, 56 ) (*base.InternalKey, base.LazyValue) { 57 panic("unimplemented") 58 } 59 60 // First implements (base.InternalIterator).First. 61 func (i *InternalIteratorShim) First() (*base.InternalKey, base.LazyValue) { 62 i.span = i.miter.First() 63 for i.span != nil && i.span.Empty() { 64 i.span = i.miter.Next() 65 } 66 if i.span == nil { 67 return nil, base.LazyValue{} 68 } 69 i.iterKey = base.InternalKey{UserKey: i.span.Start, Trailer: i.span.Keys[0].Trailer} 70 return &i.iterKey, base.MakeInPlaceValue(i.span.End) 71 } 72 73 // Last implements (base.InternalIterator).Last. 74 func (i *InternalIteratorShim) Last() (*base.InternalKey, base.LazyValue) { 75 panic("unimplemented") 76 } 77 78 // Next implements (base.InternalIterator).Next. 79 func (i *InternalIteratorShim) Next() (*base.InternalKey, base.LazyValue) { 80 i.span = i.miter.Next() 81 for i.span != nil && i.span.Empty() { 82 i.span = i.miter.Next() 83 } 84 if i.span == nil { 85 return nil, base.LazyValue{} 86 } 87 i.iterKey = base.InternalKey{UserKey: i.span.Start, Trailer: i.span.Keys[0].Trailer} 88 return &i.iterKey, base.MakeInPlaceValue(i.span.End) 89 } 90 91 // NextPrefix implements (base.InternalIterator).NextPrefix. 92 func (i *InternalIteratorShim) NextPrefix([]byte) (*base.InternalKey, base.LazyValue) { 93 panic("unimplemented") 94 } 95 96 // Prev implements (base.InternalIterator).Prev. 97 func (i *InternalIteratorShim) Prev() (*base.InternalKey, base.LazyValue) { 98 panic("unimplemented") 99 } 100 101 // Error implements (base.InternalIterator).Error. 102 func (i *InternalIteratorShim) Error() error { 103 return i.miter.Error() 104 } 105 106 // Close implements (base.InternalIterator).Close. 107 func (i *InternalIteratorShim) Close() error { 108 return i.miter.Close() 109 } 110 111 // SetBounds implements (base.InternalIterator).SetBounds. 112 func (i *InternalIteratorShim) SetBounds(lower, upper []byte) { 113 } 114 115 // String implements fmt.Stringer. 116 func (i *InternalIteratorShim) String() string { 117 return i.miter.String() 118 }