router

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package router which will route an actual datasource according to route strategy and sql type. the package defines two interfaces, RouteStrategy interface and Router interface.

Index

Constants

View Source
const (
	SingleReadWrite      = "single-read-write"
	LocalReadSingleWrite = "local-read-single-write"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AbstractRouter

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

AbstractRouter implements Router interface.

func (*AbstractRouter) Route

func (ar *AbstractRouter) Route(isSQLOnlyRead bool, runtimeCtx *RuntimeContext, exclusives map[datasource.DataSource]bool) datasource.DataSource

Route according to router's strategy.

type ClusterRouteStrategy

type ClusterRouteStrategy struct {
}

ClusterRouteStrategy route the active node

func (*ClusterRouteStrategy) Decorate

func (cs *ClusterRouteStrategy) Decorate(isSQLOnlyRead bool, runtimeCtx *RuntimeContext,
	exclusives map[datasource.DataSource]bool) datasource.DataSource

Decorate return RouteResult contains active node datasource

type ClusterRouter

type ClusterRouter struct {
	AbstractRouter
}

ClusterRouter with router strategy.

func NewClusterRouter

func NewClusterRouter(routeType string) *ClusterRouter

NewClusterRouter return ClusterRouter according to the route type.

type LocationBaseClusterRouteStrategy

type LocationBaseClusterRouteStrategy struct {
}

Location base cluster router strategy.

func (*LocationBaseClusterRouteStrategy) Decorate

func (ls *LocationBaseClusterRouteStrategy) Decorate(isSQLOnlyRead bool, runtimeCtx *RuntimeContext,
	exclusives map[datasource.DataSource]bool) datasource.DataSource

Decorate return target node datasource according to sql type and clusterDatasource's region.

type NodeRouteStrategy

type NodeRouteStrategy struct {
}

NodeRouteStrategy route an actual datasource

func (*NodeRouteStrategy) Decorate

func (ns *NodeRouteStrategy) Decorate(isSQLOnlyRead bool, runtimeCtx *RuntimeContext, exclusives map[datasource.DataSource]bool) datasource.DataSource

Decorate implements RouteStrategy

type NodeRouter

type NodeRouter struct {
	AbstractRouter
}

NodeRouter with router strategy.

func NewNodeRouter

func NewNodeRouter() *NodeRouter

NewNodeRouter return *NodeRouter with nodeRouteStrategy

type RouteStrategy

type RouteStrategy interface {
	// Decorate return routing results based on strategy, the result contains target datasource.
	Decorate(isSQLOnlyRead bool, runtimeCtx *RuntimeContext, exclusives map[datasource.DataSource]bool) datasource.DataSource
}

type Router

type Router interface {
	// Route return routeResult
	Route(isSQLOnlyRead bool, runtimeCtx *RuntimeContext, exclusives map[datasource.DataSource]bool) datasource.DataSource
}

Router interface

type RuntimeContext

type RuntimeContext struct {
	DataSource    datasource.DataSource
	InTransaction bool
	RequestId     int64
}

Jump to

Keyboard shortcuts

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