Documentation
¶
Index ¶
- type ConsistencyLevel
- type ReadRoutingPlan
- func (p ReadRoutingPlan) HostAddresses() []string
- func (p ReadRoutingPlan) LogFields() logrus.Fields
- func (p ReadRoutingPlan) NodeNames() []string
- func (p ReadRoutingPlan) Replicas() []Replica
- func (p ReadRoutingPlan) Shards() []string
- func (p ReadRoutingPlan) String() string
- func (p ReadRoutingPlan) ValidateConsistencyLevel() (int, error)
- type RepairResponse
- type Replica
- type ReplicaSet
- type Router
- type RoutingPlanBuildOptions
- type WriteRoutingPlan
- func (p WriteRoutingPlan) AdditionalHostAddresses() []string
- func (p WriteRoutingPlan) AdditionalHostNames() []string
- func (p WriteRoutingPlan) AdditionalReplicas() []Replica
- func (p WriteRoutingPlan) AdditionalShards() []string
- func (p WriteRoutingPlan) HostAddresses() []string
- func (p WriteRoutingPlan) HostNames() []string
- func (p WriteRoutingPlan) LogFields() logrus.Fields
- func (p WriteRoutingPlan) Replicas() []Replica
- func (p WriteRoutingPlan) Shards() []string
- func (p WriteRoutingPlan) String() string
- func (p WriteRoutingPlan) ValidateConsistencyLevel() (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsistencyLevel ¶
type ConsistencyLevel string
ConsistencyLevel is an enum of all possible consistency level
const ( ConsistencyLevelOne ConsistencyLevel = "ONE" ConsistencyLevelQuorum ConsistencyLevel = "QUORUM" ConsistencyLevelAll ConsistencyLevel = "ALL" )
func (ConsistencyLevel) ToInt ¶
func (l ConsistencyLevel) ToInt(n int) int
ToInt returns the minimum number needed to satisfy consistency level l among N
type ReadRoutingPlan ¶ added in v1.32.0
type ReadRoutingPlan struct {
Shard string
ReplicaSet ReplicaSet
ConsistencyLevel ConsistencyLevel
IntConsistencyLevel int
}
ReadRoutingPlan represents the plan for routing a read operation.
Fields:
- Shard: The (optional) shard targeted by this routing plan. If empty, all relevant shards are targeted.
- ReplicaSet: The ordered list of replicas to contact.
- ConsistencyLevel: The user-specified consistency level.
- IntConsistencyLevel: The resolved numeric value for the consistency level.
func (ReadRoutingPlan) HostAddresses ¶ added in v1.32.0
func (p ReadRoutingPlan) HostAddresses() []string
HostAddresses returns the host addresses of all replicas in the ReadRoutingPlan.
func (ReadRoutingPlan) LogFields ¶ added in v1.32.0
func (p ReadRoutingPlan) LogFields() logrus.Fields
LogFields returns a structured representation of the ReadRoutingPlan for logging purposes.
func (ReadRoutingPlan) NodeNames ¶ added in v1.32.0
func (p ReadRoutingPlan) NodeNames() []string
NodeNames returns the hostnames of the replicas included in the ReadRoutingPlan.
func (ReadRoutingPlan) Replicas ¶ added in v1.32.0
func (p ReadRoutingPlan) Replicas() []Replica
Replicas returns the replicas involved in the read operation.
func (ReadRoutingPlan) Shards ¶ added in v1.32.0
func (p ReadRoutingPlan) Shards() []string
Shards returns the logical shard names associated with the replicas in the ReadRoutingPlan.
func (ReadRoutingPlan) String ¶ added in v1.32.0
func (p ReadRoutingPlan) String() string
String returns a human-readable representation of the ReadRoutingPlan, including shard, consistency level, and list of replicas.
func (ReadRoutingPlan) ValidateConsistencyLevel ¶ added in v1.32.0
func (p ReadRoutingPlan) ValidateConsistencyLevel() (int, error)
ValidateConsistencyLevel validates that the resolved consistency level can be satisfied by the number of available read replicas.
Returns:
- The resolved numeric consistency level.
- An error if the level exceeds the number of available replicas.
type RepairResponse ¶
type Replica ¶ added in v1.32.0
Replica represents a single replica in the system, containing enough information to route traffic to it: the node name, shard name, and host address.
type ReplicaSet ¶ added in v1.32.0
type ReplicaSet struct {
Replicas []Replica
}
ReplicaSet groups multiple replicas together. Typically used to represent the set of replicas responsible for a given shard or tenant.
func (ReplicaSet) HostAddresses ¶ added in v1.32.0
func (s ReplicaSet) HostAddresses() []string
HostAddresses returns a list of host addresses for all replicas in the ReplicaSet.
func (ReplicaSet) NodeNames ¶ added in v1.32.0
func (s ReplicaSet) NodeNames() []string
NodeNames returns a list of node names contained in the ReplicaSet.
func (ReplicaSet) Shards ¶ added in v1.32.0
func (s ReplicaSet) Shards() []string
Shards returns a list of shard names for all replicas in the ReplicaSet.
func (ReplicaSet) String ¶ added in v1.32.0
func (s ReplicaSet) String() string
String returns a human-readable representation of a ReplicaSet, showing all replicas in the set.
type Router ¶
type Router interface {
// GetReadWriteReplicasLocation returns the primary and additional replicas
// for both reading and writing to the specified collection and partitioning key (e.g., tenant).
GetReadWriteReplicasLocation(collection string, partitioningKey string) (ReplicaSet, ReplicaSet, error)
// GetWriteReplicasLocation returns the primary replicas that should receive write requests
// for the specified collection and partitioning key.
GetWriteReplicasLocation(collection string, partitioningKey string) (ReplicaSet, error)
// GetReadReplicasLocation returns the replicas that should be used to serve read requests
// for the specified collection and partitioning key.
GetReadReplicasLocation(collection string, partitioningKey string) (ReplicaSet, error)
// BuildReadRoutingPlan constructs a routing plan for a read operation based on the provided options.
BuildReadRoutingPlan(params RoutingPlanBuildOptions) (ReadRoutingPlan, error)
// BuildWriteRoutingPlan constructs a routing plan for a write operation based on the provided options.
BuildWriteRoutingPlan(params RoutingPlanBuildOptions) (WriteRoutingPlan, error)
// NodeHostname returns the host address for a given node name.
// The second return value indicates whether the hostname was found.
NodeHostname(nodeName string) (string, bool)
// AllHostnames returns a list of all hostnames known to the router.
AllHostnames() []string
}
Router defines the interface for routing logic in a distributed system. It determines which nodes (replicas) should be used for read and write operations, and provides information about node hostnames.
type RoutingPlanBuildOptions ¶
type RoutingPlanBuildOptions struct {
Shard string
ConsistencyLevel ConsistencyLevel
DirectCandidateNode string
}
RoutingPlanBuildOptions contains parameters used to construct a routing plan for either read or write operations.
Fields:
- Shard: The name of the shard to route to. For multi-tenant collections, this must be the tenant name. For single-tenant collections, this should be empty to route to all shards, or optionally set to a specific shard if targeting all shards when creating routing plans for reading.
- ConsistencyLevel: The desired level of consistency for the operation.
- DirectCandidateNode: Optional. The preferred node to use first when building the routing plan. If empty, the local node is used as the default candidate.
func (RoutingPlanBuildOptions) String ¶ added in v1.32.0
func (o RoutingPlanBuildOptions) String() string
String returns a human-readable representation of the RoutingPlanBuildOptions. Useful for debugging and logging.
type WriteRoutingPlan ¶ added in v1.32.0
type WriteRoutingPlan struct {
Shard string
ReplicaSet ReplicaSet
AdditionalReplicaSet ReplicaSet
ConsistencyLevel ConsistencyLevel
IntConsistencyLevel int
}
WriteRoutingPlan represents the plan for routing a write operation.
Fields:
- Shard: The shard targeted by this routing plan. For writing, this is required as a write operation always targets a specific shard. Usually, the shard is determined based on the object's UUID.
- ReplicaSet: The ordered list of primary write replicas. Write replicas will normally also include read replicas. A node that accepts writes is also eligible to serve reads.
- AdditionalReplicaSet: Any secondary or additional replicas to include in the write operation.
- ConsistencyLevel: The user-specified consistency level.
- IntConsistencyLevel: The resolved numeric value for the consistency level.
func (WriteRoutingPlan) AdditionalHostAddresses ¶ added in v1.32.0
func (p WriteRoutingPlan) AdditionalHostAddresses() []string
AdditionalHostAddresses returns the host addresses of the additional write replicas, which are not part of the primary ReplicaSet, in the WriteRoutingPlan.
func (WriteRoutingPlan) AdditionalHostNames ¶ added in v1.32.0
func (p WriteRoutingPlan) AdditionalHostNames() []string
AdditionalHostNames returns the hostnames of the additional write replicas, which are not part of the primary ReplicaSet, in the WriteRoutingPlan.
func (WriteRoutingPlan) AdditionalReplicas ¶ added in v1.32.0
func (p WriteRoutingPlan) AdditionalReplicas() []Replica
AdditionalReplicas returns secondary write replicas, typically used during shard migration or replication.
func (WriteRoutingPlan) AdditionalShards ¶ added in v1.32.0
func (p WriteRoutingPlan) AdditionalShards() []string
AdditionalShards returns the shard names associated with the additional write replicas in the WriteRoutingPlan.
func (WriteRoutingPlan) HostAddresses ¶ added in v1.32.0
func (p WriteRoutingPlan) HostAddresses() []string
HostAddresses returns the host addresses of the primary write replicas in the WriteRoutingPlan.
func (WriteRoutingPlan) HostNames ¶ added in v1.32.0
func (p WriteRoutingPlan) HostNames() []string
HostNames returns the hostnames of the primary write replicas in the WriteRoutingPlan.
func (WriteRoutingPlan) LogFields ¶ added in v1.32.0
func (p WriteRoutingPlan) LogFields() logrus.Fields
LogFields returns a structured representation of the WriteRoutingPlan for logging purposes.
func (WriteRoutingPlan) Replicas ¶ added in v1.32.0
func (p WriteRoutingPlan) Replicas() []Replica
Replicas returns the primary write replicas for the operation.
func (WriteRoutingPlan) Shards ¶ added in v1.32.0
func (p WriteRoutingPlan) Shards() []string
Shards returns the logical shard names associated with the primary write replicas in the WriteRoutingPlan.
func (WriteRoutingPlan) String ¶ added in v1.32.0
func (p WriteRoutingPlan) String() string
String returns a human-readable representation of the WriteRoutingPlan, including shard, consistency level, write replicas, and additional replicas.
func (WriteRoutingPlan) ValidateConsistencyLevel ¶ added in v1.32.0
func (p WriteRoutingPlan) ValidateConsistencyLevel() (int, error)
ValidateConsistencyLevel validates that the resolved consistency level can be satisfied by the number of available write replicas.
Returns:
- The resolved numeric consistency level.
- An error if the level exceeds the number of available replicas.