router

package
v1.32.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package router provides an abstraction for determining the optimal routing plans for reads and writes within a Weaviate cluster. It handles logic around sharding, replication, and consistency, helping determine which nodes and shards (replicas) should be queried for a given operation.

The Router interface is implemented by single-tenant and multi-tenant routers, depending on the system's configuration. Use NewBuilder to create the appropriate router based on whether partitioning is enabled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder added in v1.32.0

type Builder struct {
	// contains filtered or unexported fields
}

Builder provides a builder for creating router instances based on configuration. Use NewBuilder() with all required parameters, then call Build() to get the appropriate Router implementation, either a multi-tenant router or a single tenant router. The multi-tenant router will use the tenant name as the partitioning key to identify a specific tenant's partitioning.

func NewBuilder added in v1.32.0

func NewBuilder(
	collection string,
	partitioningEnabled bool,
	nodeSelector cluster.NodeSelector,
	schemaGetter schema.SchemaGetter,
	schemaReader schemaTypes.SchemaReader,
	replicationFSMReader replicationTypes.ReplicationFSMReader,
) *Builder

NewBuilder creates a new Builder with the provided configuration.

Parameters:

  • collection: the name of the collection that this router will handle.
  • partitioningEnabled: true for multi-tenant mode, false for single-tenant mode.
  • nodeSelector: provides cluster node state information and hostnames.
  • schemaGetter: provides collection schemas, sharding states, and tenant information.
  • schemaReader: provides shard replica (or node names) metadata.
  • replicationFSMReader: provides replica state information for replication consistency.

Returns:

  • *Builder: a new builder instance ready to build the appropriate router.

func (*Builder) Build added in v1.32.0

func (b *Builder) Build() Router

Build builds and returns the appropriate router implementation based on the partitioning configuration.

Returns:

  • Router: a concrete router implementation (*multiTenantRouter or *singleTenantRouter) that implements the Router interface.

type Router

type Router interface {
	// GetReadWriteReplicasLocation returns the read and write replicas for a given
	// collection.
	//
	// Parameters:
	//   - collection: the name of the collection to get replicas for.
	//   - shard: the shard identifier (matches the tenant name for multi-tenant collections).
	//
	// Returns:
	//   - readReplicas: a replica set serving as read replicas.
	//   - writeReplicas: a replica set serving as primary write replicas.
	//   - additionalWriteReplicas: a replica set serving as additional write replicas.
	//   - error: if an error occurs while retrieving replicas.
	GetReadWriteReplicasLocation(collection string, shard string) (readReplicas types.ReplicaSet, writeReplicas types.ReplicaSet, additionalWriteReplicas types.ReplicaSet, err error)

	// GetWriteReplicasLocation returns the write replicas for a given collection.
	//
	// Parameters:
	//   - collection: the name of the collection to get write replicas for.
	//   - shard: the shard identifier (matches the tenant name for multi-tenant collections).
	//
	// Returns:
	//   - writeReplicas: a replica set serving as primary write replicas.
	//   - additionalWriteReplicas: a replica set serving as additional write replicas.
	//   - error: if an error occurs while retrieving replicas.
	GetWriteReplicasLocation(collection string, shard string) (types.ReplicaSet, types.ReplicaSet, error)

	// GetReadReplicasLocation returns the read replicas for a given collection.
	//
	// Parameters:
	//   - collection: the name of the collection to get read replicas for.
	//   - shard: the shard identifier (matches the tenant name for multi-tenant collections).
	//
	// Returns:
	//   - readReplicas: a replica set serving as read replicas.
	//   - error: if an error occurs while retrieving replicas.
	GetReadReplicasLocation(collection string, shard string) (types.ReplicaSet, error)

	// BuildReadRoutingPlan constructs a routing plan for reading data from the cluster including only shards
	// which the client is allowed to read.
	//
	// Parameters:
	//   - params: routing plan build options containing collection name, (optional) shard name, consistency level,
	//     and optional direct candidate replica preference.
	//
	// Returns:
	//   - routingPlan: the routing plan includes replicas ordered with the direct candidate first,
	//     followed by the remaining replicas in no guaranteed order. If no direct candidate is provided,
	//     the local node name is used and placed first as the local replica.
	//   - error: if validation fails, no suitable replicas are found, or consistency level is invalid.
	BuildReadRoutingPlan(params types.RoutingPlanBuildOptions) (types.ReadRoutingPlan, error)

	// BuildWriteRoutingPlan constructs a routing plan for writing data to the cluster including only shards
	// which the client is allowed to write.
	//
	// Parameters:
	//   - params: routing plan build options containing collection name, (optional) shard name), consistency level,
	//     and optional direct candidate replica preference.
	//
	// Returns:
	//   - routingPlan: the constructed write routing plan with ordered replicas.
	//   - error: if validation fails, no suitable replicas are found, or consistency level is invalid.
	BuildWriteRoutingPlan(params types.RoutingPlanBuildOptions) (types.WriteRoutingPlan, error)

	// NodeHostname returns the hostname for a given node name.
	//
	// Parameters:
	//   - nodeName: the name of the node to get the hostname for.
	//
	// Returns:
	//   - hostname: the hostname of the node.
	//   - ok: true if the hostname was found, false if the node name is unknown or unregistered.
	NodeHostname(nodeName string) (string, bool)

	// AllHostnames returns all known hostnames in the cluster.
	//
	// Returns:
	//   - hostnames: a slice of all known hostnames; always returns a valid slice, possibly empty.
	AllHostnames() []string
}

Router defines the contract for determining routing plans for reads and writes within a cluster. It abstracts the logic to identify read/write replicas, construct routing plans, and access cluster host information including hostnames and ip addresses.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL