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