Documentation ¶
Index ¶
- type LeaseHolderChoosingPolicy
- type SpanResolver
- type SpanResolverIterator
- func (it *SpanResolverIterator) Desc() roachpb.RangeDescriptor
- func (it *SpanResolverIterator) Error() error
- func (it *SpanResolverIterator) NeedAnother() bool
- func (it *SpanResolverIterator) Next(ctx context.Context)
- func (it *SpanResolverIterator) ReplicaInfo(ctx context.Context) (kv.ReplicaInfo, error)
- func (it *SpanResolverIterator) Seek(ctx context.Context, span roachpb.Span, scanDir kv.ScanDirection)
- func (it *SpanResolverIterator) Valid() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LeaseHolderChoosingPolicy ¶
type LeaseHolderChoosingPolicy byte
LeaseHolderChoosingPolicy enumerates the implementors of leaseHolderOracle.
const ( // RandomLeaseHolderChoice chooses lease holders randomly. RandomLeaseHolderChoice LeaseHolderChoosingPolicy = iota // BinPackingLeaseHolderChoice bin-packs the choices. BinPackingLeaseHolderChoice )
type SpanResolver ¶
type SpanResolver struct {
// contains filtered or unexported fields
}
SpanResolver resolves key spans to their respective ranges and lease holders. Used for planning physical execution of distributed SQL queries.
Sample usage for resolving a bunch of spans:
func resolveSpans(
ctx context.Context, it *distsql.SpanResolverIterator, spans ...spanWithDir,
) ([][]kv.ReplicaInfo, error) { lr := distsql.NewSpanResolver( distSender, gossip, nodeDescriptor, distsql.BinPackingLeaseHolderChoice) it := lr.NewSpanResolverIterator() res := make([][]kv.ReplicaInfo, 0) for _, span := range spans { repls := make([]kv.ReplicaInfo, 0) for it.Seek(ctx, span.Span, span.dir); ; it.Next(ctx) { if !it.Valid() { return nil, it.Error() } repl, err := it.ReplicaInfo(ctx) if err != nil { return nil, err } repls = append(repls, repl) if !it.NeedAnother() { break } } res = append(res, repls) } return res, nil }
func NewSpanResolver ¶
func NewSpanResolver( distSender *kv.DistSender, gossip *gossip.Gossip, nodeDesc roachpb.NodeDescriptor, choosingPolicy LeaseHolderChoosingPolicy, ) *SpanResolver
NewSpanResolver creates a new SpanResolver.
func (*SpanResolver) NewSpanResolverIterator ¶
func (sr *SpanResolver) NewSpanResolverIterator() *SpanResolverIterator
NewSpanResolverIterator creates a new SpanResolverIterator.
type SpanResolverIterator ¶
type SpanResolverIterator struct {
// contains filtered or unexported fields
}
SpanResolverIterator iterates over the ranges composing a key span.
func (*SpanResolverIterator) Desc ¶
func (it *SpanResolverIterator) Desc() roachpb.RangeDescriptor
Desc returns the current RangeDescriptor.
func (*SpanResolverIterator) Error ¶
func (it *SpanResolverIterator) Error() error
func (*SpanResolverIterator) NeedAnother ¶
func (it *SpanResolverIterator) NeedAnother() bool
NeedAnother returns true if the current range is not the last for the span that was last Seek()ed.
func (*SpanResolverIterator) Next ¶
func (it *SpanResolverIterator) Next(ctx context.Context)
Next advances the iterator to the next range. Possible errors encountered should be checked for with Valid().
func (*SpanResolverIterator) ReplicaInfo ¶
func (it *SpanResolverIterator) ReplicaInfo(ctx context.Context) (kv.ReplicaInfo, error)
ReplicaInfo returns information about the replica that has been picked for the current range. A RangeUnavailableError is returned if there's no information in gossip about any of the replicas.
func (*SpanResolverIterator) Seek ¶
func (it *SpanResolverIterator) Seek( ctx context.Context, span roachpb.Span, scanDir kv.ScanDirection, )
Seek positions the iterator on the start of a span (span.Key or span.EndKey, depending on ScanDir). Note that span.EndKey is exclusive, regardless of scanDir. After calling this, ReplicaInfo() will return information about the range containing the start key of the span (or the end key, if the direction is Descending). NeedAnother() will return true until the iterator is positioned on or after the end of the span. Possible errors encountered should be checked for with Valid().
Seek can be called repeatedly on the same iterator. To make optimal uses of caches, Seek()s should be performed on spans sorted according to the scanDir (if Descending, then the span with the highest keys should be Seek()ed first).
scanDir changes the direction in which Next() will advance the iterator.
func (*SpanResolverIterator) Valid ¶
func (it *SpanResolverIterator) Valid() bool
Valid returns false if an error was encoutered by the last Seek() or Next().