Upgrade versions of vendored libs
This commit is contained in:
252
vendor/github.com/cockroachdb/pebble/internal/base/iterator.go
generated
vendored
252
vendor/github.com/cockroachdb/pebble/internal/base/iterator.go
generated
vendored
@@ -85,33 +85,19 @@ import "fmt"
|
||||
// them through the Error method. All of the absolute positioning methods
|
||||
// reset any accumulated error before positioning. Relative positioning
|
||||
// methods return without advancing if the iterator has accumulated an error.
|
||||
//
|
||||
// nilv == shorthand for LazyValue{}, which represents a nil value.
|
||||
type InternalIterator interface {
|
||||
// SeekGE moves the iterator to the first key/value pair whose key is greater
|
||||
// than or equal to the given key. Returns the key and value if the iterator
|
||||
// is pointing at a valid entry, and (nil, nil) otherwise. Note that SeekGE
|
||||
// is pointing at a valid entry, and (nil, nilv) otherwise. Note that SeekGE
|
||||
// only checks the upper bound. It is up to the caller to ensure that key
|
||||
// is greater than or equal to the lower bound.
|
||||
//
|
||||
// trySeekUsingNext is a performance optimization that callers can use to
|
||||
// indicate that they have not done any action to move this iterator beyond
|
||||
// the first key that would be found if this iterator were to honestly do
|
||||
// the intended seek. For example, say the caller did a
|
||||
// SeekGE(k1...), followed by SeekGE(k2...) where k1 <= k2, without any
|
||||
// intermediate positioning calls. The caller can safely specify true for this
|
||||
// parameter in the second call. As another example, say the caller did do one
|
||||
// call to Next between the two Seek calls, and k1 < k2. Again, the caller can
|
||||
// safely specify a true value for this parameter. Note that a false value is
|
||||
// always safe. The callee is free to ignore the true value if its
|
||||
// implementation does not permit this optimization.
|
||||
// - We make the caller do this determination since a string comparison of
|
||||
// k1, k2 is not necessarily cheap, and there may be many iterators in
|
||||
// the iterator stack. Doing it once at the root of the iterator stack
|
||||
// is cheaper.
|
||||
SeekGE(key []byte, trySeekUsingNext bool) (*InternalKey, []byte)
|
||||
SeekGE(key []byte, flags SeekGEFlags) (*InternalKey, LazyValue)
|
||||
|
||||
// SeekPrefixGE moves the iterator to the first key/value pair whose key is
|
||||
// greater than or equal to the given key. Returns the key and value if the
|
||||
// iterator is pointing at a valid entry, and (nil, nil) otherwise. Note that
|
||||
// iterator is pointing at a valid entry, and (nil, nilv) otherwise. Note that
|
||||
// SeekPrefixGE only checks the upper bound. It is up to the caller to ensure
|
||||
// that key is greater than or equal to the lower bound.
|
||||
//
|
||||
@@ -120,7 +106,7 @@ type InternalIterator interface {
|
||||
// function must be supplied to the Comparer for the DB. The supplied prefix
|
||||
// will be the prefix of the given key returned by that Split function. If
|
||||
// the iterator is able to determine that no key with the prefix exists, it
|
||||
// can return (nil,nil). Unlike SeekGE, this is not an indication that
|
||||
// can return (nil,nilv). Unlike SeekGE, this is not an indication that
|
||||
// iteration is exhausted.
|
||||
//
|
||||
// Note that the iterator may return keys not matching the prefix. It is up
|
||||
@@ -132,78 +118,53 @@ type InternalIterator interface {
|
||||
// not supporting reverse iteration in prefix iteration mode until a
|
||||
// different positioning routine (SeekGE, SeekLT, First or Last) switches the
|
||||
// iterator out of prefix iteration.
|
||||
//
|
||||
// trySeekUsingNext is a performance optimization that callers can use to
|
||||
// indicate that they have not done any action to move this iterator
|
||||
// beyond the first key that would be found if this iterator were to
|
||||
// honestly do the indicated seek. For example, say the caller did a
|
||||
// SeekPrefixGE(k1...), followed by SeekPrefixGE(k2...) where k1 <= k2,
|
||||
// without any intermediate positioning calls. The caller can safely
|
||||
// specify true for this parameter in the second call. As another example,
|
||||
// say the caller did do one call to Next between the two SeekPrefixGE
|
||||
// calls, and k1 < k2. Again, the caller can safely specify a true value
|
||||
// for this parameter. Note that a false value is always safe. The callee
|
||||
// is free to ignore the true value if its implementation does not permit
|
||||
// this optimization.
|
||||
// - We make the caller do this determination since a string comparison of
|
||||
// k1, k2 is not necessarily cheap, and there may be many iterators in
|
||||
// the iterator stack. Doing it once at the root of the iterator stack
|
||||
// is cheaper.
|
||||
// - This optimization could also be applied to SeekLT (where it would be
|
||||
// trySeekUsingPrev). We currently only do it for SeekPrefixGE and SeekGE
|
||||
// because this is where this optimization helps the performance of
|
||||
// CockroachDB. The SeekLT cases in CockroachDB are typically accompanied
|
||||
// with bounds that change between seek calls, and is optimized inside
|
||||
// certain iterator implementations, like singleLevelIterator, without any
|
||||
// extra parameter passing (though the same amortization of string
|
||||
// comparisons could be done to improve that optimization, by making the
|
||||
// root of the iterator stack do it).
|
||||
SeekPrefixGE(prefix, key []byte, trySeekUsingNext bool) (*InternalKey, []byte)
|
||||
SeekPrefixGE(prefix, key []byte, flags SeekGEFlags) (*InternalKey, LazyValue)
|
||||
|
||||
// SeekLT moves the iterator to the last key/value pair whose key is less
|
||||
// than the given key. Returns the key and value if the iterator is pointing
|
||||
// at a valid entry, and (nil, nil) otherwise. Note that SeekLT only checks
|
||||
// at a valid entry, and (nil, nilv) otherwise. Note that SeekLT only checks
|
||||
// the lower bound. It is up to the caller to ensure that key is less than
|
||||
// the upper bound.
|
||||
SeekLT(key []byte) (*InternalKey, []byte)
|
||||
SeekLT(key []byte, flags SeekLTFlags) (*InternalKey, LazyValue)
|
||||
|
||||
// First moves the iterator the the first key/value pair. Returns the key and
|
||||
// value if the iterator is pointing at a valid entry, and (nil, nil)
|
||||
// value if the iterator is pointing at a valid entry, and (nil, nilv)
|
||||
// otherwise. Note that First only checks the upper bound. It is up to the
|
||||
// caller to ensure that First() is not called when there is a lower bound,
|
||||
// and instead call SeekGE(lower).
|
||||
First() (*InternalKey, []byte)
|
||||
First() (*InternalKey, LazyValue)
|
||||
|
||||
// Last moves the iterator the the last key/value pair. Returns the key and
|
||||
// value if the iterator is pointing at a valid entry, and (nil, nil)
|
||||
// value if the iterator is pointing at a valid entry, and (nil, nilv)
|
||||
// otherwise. Note that Last only checks the lower bound. It is up to the
|
||||
// caller to ensure that Last() is not called when there is an upper bound,
|
||||
// and instead call SeekLT(upper).
|
||||
Last() (*InternalKey, []byte)
|
||||
Last() (*InternalKey, LazyValue)
|
||||
|
||||
// Next moves the iterator to the next key/value pair. Returns the key and
|
||||
// value if the iterator is pointing at a valid entry, and (nil, nil)
|
||||
// value if the iterator is pointing at a valid entry, and (nil, nilv)
|
||||
// otherwise. Note that Next only checks the upper bound. It is up to the
|
||||
// caller to ensure that key is greater than or equal to the lower bound.
|
||||
//
|
||||
// It is valid to call Next when the iterator is positioned before the first
|
||||
// key/value pair due to either a prior call to SeekLT or Prev which returned
|
||||
// (nil, nil). It is not allowed to call Next when the previous call to SeekGE,
|
||||
// SeekPrefixGE or Next returned (nil, nil).
|
||||
Next() (*InternalKey, []byte)
|
||||
// (nil, nilv). It is not allowed to call Next when the previous call to SeekGE,
|
||||
// SeekPrefixGE or Next returned (nil, nilv).
|
||||
Next() (*InternalKey, LazyValue)
|
||||
|
||||
// Prev moves the iterator to the previous key/value pair. Returns the key
|
||||
// and value if the iterator is pointing at a valid entry, and (nil, nil)
|
||||
// and value if the iterator is pointing at a valid entry, and (nil, nilv)
|
||||
// otherwise. Note that Prev only checks the lower bound. It is up to the
|
||||
// caller to ensure that key is less than the upper bound.
|
||||
//
|
||||
// It is valid to call Prev when the iterator is positioned after the last
|
||||
// key/value pair due to either a prior call to SeekGE or Next which returned
|
||||
// (nil, nil). It is not allowed to call Prev when the previous call to SeekLT
|
||||
// or Prev returned (nil, nil).
|
||||
Prev() (*InternalKey, []byte)
|
||||
// (nil, nilv). It is not allowed to call Prev when the previous call to SeekLT
|
||||
// or Prev returned (nil, nilv).
|
||||
Prev() (*InternalKey, LazyValue)
|
||||
|
||||
// Error returns any accumulated error.
|
||||
// Error returns any accumulated error. It may not include errors returned
|
||||
// to the client when calling LazyValue.Value().
|
||||
Error() error
|
||||
|
||||
// Close closes the iterator and returns any accumulated error. Exhausting
|
||||
@@ -225,11 +186,137 @@ type InternalIterator interface {
|
||||
fmt.Stringer
|
||||
}
|
||||
|
||||
// InternalIteratorWithStats extends InternalIterator to expose stats.
|
||||
type InternalIteratorWithStats interface {
|
||||
InternalIterator
|
||||
Stats() InternalIteratorStats
|
||||
ResetStats()
|
||||
// SeekGEFlags holds flags that may configure the behavior of a forward seek.
|
||||
// Not all flags are relevant to all iterators.
|
||||
type SeekGEFlags uint8
|
||||
|
||||
const (
|
||||
seekGEFlagTrySeekUsingNext uint8 = iota
|
||||
seekGEFlagRelativeSeek
|
||||
seekGEFlagBatchJustRefreshed
|
||||
)
|
||||
|
||||
// SeekGEFlagsNone is the default value of SeekGEFlags, with all flags disabled.
|
||||
const SeekGEFlagsNone = SeekGEFlags(0)
|
||||
|
||||
// TrySeekUsingNext indicates whether a performance optimization was enabled
|
||||
// by a caller, indicating the caller has not done any action to move this
|
||||
// iterator beyond the first key that would be found if this iterator were to
|
||||
// honestly do the intended seek. For example, say the caller did a
|
||||
// SeekGE(k1...), followed by SeekGE(k2...) where k1 <= k2, without any
|
||||
// intermediate positioning calls. The caller can safely specify true for this
|
||||
// parameter in the second call. As another example, say the caller did do one
|
||||
// call to Next between the two Seek calls, and k1 < k2. Again, the caller can
|
||||
// safely specify a true value for this parameter. Note that a false value is
|
||||
// always safe. The callee is free to ignore the true value if its
|
||||
// implementation does not permit this optimization.
|
||||
//
|
||||
// We make the caller do this determination since a string comparison of k1, k2
|
||||
// is not necessarily cheap, and there may be many iterators in the iterator
|
||||
// stack. Doing it once at the root of the iterator stack is cheaper.
|
||||
//
|
||||
// This optimization could also be applied to SeekLT (where it would be
|
||||
// trySeekUsingPrev). We currently only do it for SeekPrefixGE and SeekGE
|
||||
// because this is where this optimization helps the performance of CockroachDB.
|
||||
// The SeekLT cases in CockroachDB are typically accompanied with bounds that
|
||||
// change between seek calls, and is optimized inside certain iterator
|
||||
// implementations, like singleLevelIterator, without any extra parameter
|
||||
// passing (though the same amortization of string comparisons could be done to
|
||||
// improve that optimization, by making the root of the iterator stack do it).
|
||||
func (s SeekGEFlags) TrySeekUsingNext() bool { return (s & (1 << seekGEFlagTrySeekUsingNext)) != 0 }
|
||||
|
||||
// RelativeSeek is set when in the course of a forward positioning operation, a
|
||||
// higher-level iterator seeks a lower-level iterator to a larger key than the
|
||||
// one at the current iterator position.
|
||||
//
|
||||
// Concretely, this occurs when the merging iterator observes a range deletion
|
||||
// covering the key at a level's current position, and the merging iterator
|
||||
// seeks the level to the range deletion's end key. During lazy-combined
|
||||
// iteration, this flag signals to the level iterator that the seek is NOT an
|
||||
// absolute-positioning operation from the perspective of the pebble.Iterator,
|
||||
// and the level iterator must look for range keys in tables between the current
|
||||
// iterator position and the new seeked position.
|
||||
func (s SeekGEFlags) RelativeSeek() bool { return (s & (1 << seekGEFlagRelativeSeek)) != 0 }
|
||||
|
||||
// BatchJustRefreshed is set by Seek[Prefix]GE when an iterator's view of an
|
||||
// indexed batch was just refreshed. It serves as a signal to the batch iterator
|
||||
// to ignore the TrySeekUsingNext optimization, because the external knowledge
|
||||
// imparted by the TrySeekUsingNext flag does not apply to the batch iterator's
|
||||
// position. See (pebble.Iterator).batchJustRefreshed.
|
||||
func (s SeekGEFlags) BatchJustRefreshed() bool { return (s & (1 << seekGEFlagBatchJustRefreshed)) != 0 }
|
||||
|
||||
// EnableTrySeekUsingNext returns the provided flags with the
|
||||
// try-seek-using-next optimization enabled. See TrySeekUsingNext for an
|
||||
// explanation of this optimization.
|
||||
func (s SeekGEFlags) EnableTrySeekUsingNext() SeekGEFlags {
|
||||
return s | (1 << seekGEFlagTrySeekUsingNext)
|
||||
}
|
||||
|
||||
// DisableTrySeekUsingNext returns the provided flags with the
|
||||
// try-seek-using-next optimization disabled.
|
||||
func (s SeekGEFlags) DisableTrySeekUsingNext() SeekGEFlags {
|
||||
return s &^ (1 << seekGEFlagTrySeekUsingNext)
|
||||
}
|
||||
|
||||
// EnableRelativeSeek returns the provided flags with the relative-seek flag
|
||||
// enabled. See RelativeSeek for an explanation of this flag's use.
|
||||
func (s SeekGEFlags) EnableRelativeSeek() SeekGEFlags {
|
||||
return s | (1 << seekGEFlagRelativeSeek)
|
||||
}
|
||||
|
||||
// DisableRelativeSeek returns the provided flags with the relative-seek flag
|
||||
// disabled.
|
||||
func (s SeekGEFlags) DisableRelativeSeek() SeekGEFlags {
|
||||
return s &^ (1 << seekGEFlagRelativeSeek)
|
||||
}
|
||||
|
||||
// EnableBatchJustRefreshed returns the provided flags with the
|
||||
// batch-just-refreshed bit set. See BatchJustRefreshed for an explanation of
|
||||
// this flag.
|
||||
func (s SeekGEFlags) EnableBatchJustRefreshed() SeekGEFlags {
|
||||
return s | (1 << seekGEFlagBatchJustRefreshed)
|
||||
}
|
||||
|
||||
// DisableBatchJustRefreshed returns the provided flags with the
|
||||
// batch-just-refreshed bit unset.
|
||||
func (s SeekGEFlags) DisableBatchJustRefreshed() SeekGEFlags {
|
||||
return s &^ (1 << seekGEFlagBatchJustRefreshed)
|
||||
}
|
||||
|
||||
// SeekLTFlags holds flags that may configure the behavior of a reverse seek.
|
||||
// Not all flags are relevant to all iterators.
|
||||
type SeekLTFlags uint8
|
||||
|
||||
const (
|
||||
seekLTFlagRelativeSeek uint8 = iota
|
||||
)
|
||||
|
||||
// SeekLTFlagsNone is the default value of SeekLTFlags, with all flags disabled.
|
||||
const SeekLTFlagsNone = SeekLTFlags(0)
|
||||
|
||||
// RelativeSeek is set when in the course of a reverse positioning operation, a
|
||||
// higher-level iterator seeks a lower-level iterator to a smaller key than the
|
||||
// one at the current iterator position.
|
||||
//
|
||||
// Concretely, this occurs when the merging iterator observes a range deletion
|
||||
// covering the key at a level's current position, and the merging iterator
|
||||
// seeks the level to the range deletion's start key. During lazy-combined
|
||||
// iteration, this flag signals to the level iterator that the seek is NOT an
|
||||
// absolute-positioning operation from the perspective of the pebble.Iterator,
|
||||
// and the level iterator must look for range keys in tables between the current
|
||||
// iterator position and the new seeked position.
|
||||
func (s SeekLTFlags) RelativeSeek() bool { return s&(1<<seekLTFlagRelativeSeek) != 0 }
|
||||
|
||||
// EnableRelativeSeek returns the provided flags with the relative-seek flag
|
||||
// enabled. See RelativeSeek for an explanation of this flag's use.
|
||||
func (s SeekLTFlags) EnableRelativeSeek() SeekLTFlags {
|
||||
return s | (1 << seekLTFlagRelativeSeek)
|
||||
}
|
||||
|
||||
// DisableRelativeSeek returns the provided flags with the relative-seek flag
|
||||
// disabled.
|
||||
func (s SeekLTFlags) DisableRelativeSeek() SeekLTFlags {
|
||||
return s &^ (1 << seekLTFlagRelativeSeek)
|
||||
}
|
||||
|
||||
// InternalIteratorStats contains miscellaneous stats produced by
|
||||
@@ -238,8 +325,8 @@ type InternalIteratorWithStats interface {
|
||||
// are aggregated as one goes up the InternalIterator tree.
|
||||
type InternalIteratorStats struct {
|
||||
// Bytes in the loaded blocks. If the block was compressed, this is the
|
||||
// compressed bytes. Currently, only the second-level index and data blocks
|
||||
// containing points are included.
|
||||
// compressed bytes. Currently, only the index blocks, data blocks
|
||||
// containing points, and filter blocks are included.
|
||||
BlockBytes uint64
|
||||
// Subset of BlockBytes that were in the block cache.
|
||||
BlockBytesInCache uint64
|
||||
@@ -271,30 +358,3 @@ func (s *InternalIteratorStats) Merge(from InternalIteratorStats) {
|
||||
s.PointCount += from.PointCount
|
||||
s.PointsCoveredByRangeTombstones += from.PointsCoveredByRangeTombstones
|
||||
}
|
||||
|
||||
type internalIteratorWithEmptyStats struct {
|
||||
InternalIterator
|
||||
}
|
||||
|
||||
var _ InternalIteratorWithStats = internalIteratorWithEmptyStats{}
|
||||
|
||||
// Stats implements InternalIteratorWithStats.
|
||||
func (i internalIteratorWithEmptyStats) Stats() InternalIteratorStats {
|
||||
return InternalIteratorStats{}
|
||||
}
|
||||
|
||||
// ResetStats implements InternalIteratorWithStats.
|
||||
func (i internalIteratorWithEmptyStats) ResetStats() {}
|
||||
|
||||
// WrapIterWithStats ensures that either iter implements the stats methods or
|
||||
// wraps it, such that the return value implements InternalIteratorWithStats.
|
||||
func WrapIterWithStats(iter InternalIterator) InternalIteratorWithStats {
|
||||
if iter == nil {
|
||||
return nil
|
||||
}
|
||||
i, ok := iter.(InternalIteratorWithStats)
|
||||
if ok {
|
||||
return i
|
||||
}
|
||||
return internalIteratorWithEmptyStats{InternalIterator: iter}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user