runtime

package
v1.2.3-hotfix-20241101 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ClusterService cluster service
	ClusterService = "cluster-service"
	// ClusterService cluster service
	LockService = "lock-service"
	// InternalSQLExecutor attr name for internal sql executor
	InternalSQLExecutor = "internal-sql-executor"
	// AutoIncrementService attr name for AutoIncrementService
	AutoIncrementService = "auto-increment-service"
	// StatusServer is the global server of status of cluster.
	StatusServer = "status-server"
	// TxnTraceService txn trance service
	TxnTraceService = "txn-trace-service"

	// TxnOptions options used to create txn
	TxnOptions = "txn-options"
	// TxnMode runtime default txn mode
	TxnMode = "txn-mode"
	// TxnIsolation runtime default txn isolation
	TxnIsolation = "txn-isolation"

	// EnableCheckInvalidRCErrors enable check rc errors
	EnableCheckInvalidRCErrors = "enable-check-rc-invalid-error"

	// MOProtocolVersion is the protocol version of the MO services
	MOProtocolVersion = "protocol-version"

	// BackgroundCNSelector is the labels of the CN handing the background requests, including mo-logger, task-service.
	BackgroundCNSelector = "background-cn-selector"
)

The names of all global variables should be defined here.

Variables

This section is empty.

Functions

func CheckMethodVersion added in v1.1.0

func CheckMethodVersion[Req interface{ GetMethod() T }, T methodType](ctx context.Context, versionMap map[T]int64, req Req) error

func SetupProcessLevelRuntime

func SetupProcessLevelRuntime(r Runtime)

SetupProcessLevelRuntime set a process-level runtime. If the service does not support a service-level runtime when running in launch mode, it will use the process-level runtime. The process-level runtime must setup in main.

Types

type LoggerName

type LoggerName int
const (
	Default LoggerName = iota
	SystemInit
)

type Option

type Option func(*runtime)

Option used to setup runtime

func WithClock

func WithClock(clock clock.Clock) Option

WithClock setup clock for a runtime, CN and TN must contain an instance of the Clock that is used to provide the timestamp service to the transaction.

type Runtime

type Runtime interface {
	// ServiceType return service type
	ServiceType() metadata.ServiceType
	// ServiceUUID return service uuid
	ServiceUUID() string
	// Logger returns the top-level logger is set at the start of the MO and contains
	// the service type and unique ID of the service; all subsequent loggers must be
	// built on this logger.
	Logger() *log.MOLogger
	// SubLogger returns sub-loggers used for different purposes.
	SubLogger(LoggerName) *log.MOLogger
	// Clock returns the Clock instance of the current runtime environment
	Clock() clock.Clock
	// SetGlobalVariables set global variables which scope based in runtime.
	SetGlobalVariables(name string, value any)
	// GetGlobalVariables get global variables, return false if variables not found.
	GetGlobalVariables(name string) (any, bool)
}

Runtime contains the runtime environment for a MO service. Each CN/DN/LOG service needs to receive a Runtime and will pass the Runtime to all components of the service. These Runtime may only be created in main or integration test framework.

Because most of our BVT tests and integration tests are run in a single mo-service process, which runs multiple CN, TN and LOG services, the Runtime cannot be set as a global variable, otherwise we would not be able to set a single Runtime for each service and each component.

In other words, there are no global variables inside mo-service, and the scope of global variables is in a Runtime.

Since each component holds a Runtime, all mo-service-level parameters should not appear in the parameter list of the component's initialization function, but should be replaced by the Runtime's global variables.

Unfortunately, we can't fully support the isolation of the service-level runtime between services and they still share a process-level runtime, but at least there is an advantage in that all service-level components are placed in the runtime, so that the configuration and components can be easily retrieved from the runtime without having to pass them as parameters, so that when adding service-level components in the future, there is no need to modify the parameter list.

func DefaultRuntime

func DefaultRuntime() Runtime

DefaultRuntime used to test

func DefaultRuntimeWithLevel added in v0.8.0

func DefaultRuntimeWithLevel(level zapcore.Level) Runtime

DefaultRuntime used to test

func NewRuntime

func NewRuntime(service metadata.ServiceType, uuid string, logger *zap.Logger, opts ...Option) Runtime

NewRuntime create a mo runtime environment.

func ProcessLevelRuntime

func ProcessLevelRuntime() Runtime

ProcessLevelRuntime returns a process-lelve runtime

Jump to

Keyboard shortcuts

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