cockroach: Index | Files

package replicaoracle

import ""

Package replicaoracle provides functionality for physicalplan to choose a replica for a range.


Package Files



var (
    // RandomChoice chooses lease replicas randomly.
    RandomChoice = RegisterPolicy(newRandomOracleFactory)
    // BinPackingChoice bin-packs the choices.
    BinPackingChoice = RegisterPolicy(newBinPackingOracleFactory)
    // ClosestChoice chooses the node closest to the current node.
    ClosestChoice = RegisterPolicy(newClosestOracleFactory)

type Config Uses

type Config struct {
    NodeDescs  kvcoord.NodeDescStore
    NodeDesc   roachpb.NodeDescriptor // current node
    Settings   *cluster.Settings
    RPCContext *rpc.Context

Config is used to construct an OracleFactory.

type Oracle Uses

type Oracle interface {
    // ChoosePreferredReplica returns a choice for one range. Implementors are
    // free to use the QueryState param, which has info about the number of	ranges
    // already handled by each node for the current SQL query. The state is not
    // updated with the result of this method; the caller is in charge of that.
    // When the range's leaseholder is known, leaseHolder is passed in; leaseHolder
    // is nil otherwise. Implementors are free to use it, or ignore it if they
    // don't care about the leaseholder (e.g. when we're planning for follower
    // reads).
    // A RangeUnavailableError can be returned if there's no information in gossip
    // about any of the nodes that might be tried.
        ctx context.Context, rng *roachpb.RangeDescriptor, leaseholder *roachpb.ReplicaDescriptor, qState QueryState,
    ) (roachpb.ReplicaDescriptor, error)

Oracle is used to choose the lease holder for ranges. This interface was extracted so we can experiment with different choosing policies. Note that choices that start out random can act as self-fulfilling prophecies - if there's no active lease, the node that will be asked to execute part of the query (the chosen node) will acquire a new lease.

type OracleFactory Uses

type OracleFactory interface {
    Oracle(*kv.Txn) Oracle

OracleFactory creates an oracle for a Txn.

func NewOracleFactory Uses

func NewOracleFactory(policy Policy, cfg Config) OracleFactory

NewOracleFactory creates an oracle with the given policy.

type OracleFactoryFunc Uses

type OracleFactoryFunc func(Config) OracleFactory

OracleFactoryFunc creates an OracleFactory from a Config.

type Policy Uses

type Policy byte

Policy determines how an Oracle should select a replica.

func RegisterPolicy Uses

func RegisterPolicy(f OracleFactoryFunc) Policy

RegisterPolicy creates a new policy given a function which constructs an OracleFactory. RegisterPolicy is intended to be called only during init and is not safe for concurrent use.

type QueryState Uses

type QueryState struct {
    RangesPerNode  map[roachpb.NodeID]int
    AssignedRanges map[roachpb.RangeID]roachpb.ReplicaDescriptor

QueryState encapsulates the history of assignments of ranges to nodes done by an oracle on behalf of one particular query.

func MakeQueryState Uses

func MakeQueryState() QueryState

MakeQueryState creates an initialized QueryState.

Package replicaoracle imports 10 packages (graph) and is imported by 10 packages. Updated 2020-08-12. Refresh now. Tools for package owners.