runtime

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 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"
	// ShardService shard service
	ShardService = "shard-service"
	// ProcessCodecService process codec service
	ProcessCodecService = "process-codec-service"
	// PartitionService partition service
	PartitionService = "partition-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"

	PipelineClient = "pipeline-client"

	// TestingContextKey is the key of context for testing
	TestingContextKey = "testing-context"

	CNMemoryThrottler = "cn-memory-throttler"
)

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,
	service string,
	versionMap map[T]int64,
	req Req,
) error

func CheckMethodVersionWithRuntime

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

func GetLogger

func GetLogger(
	sid string,
) *log.MOLogger

GetLogger returns the runtime's logger

func InTesting

func InTesting(
	sid string,
) bool

func RunTest

func RunTest(
	sid string,
	fn func(rt Runtime),
)

RunTest run runtime test.

func SetupServiceBasedRuntime

func SetupServiceBasedRuntime(
	service string,
	r Runtime,
)

SetupServiceBasedRuntime setup service based runtime.

func SetupServiceRuntimeTestingContext

func SetupServiceRuntimeTestingContext(
	sid string,
)

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 ServiceRuntime

func ServiceRuntime(
	service string,
) Runtime

ServiceRuntime returns a service based runtime

type TestingContext

type TestingContext struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func MustGetTestingContext

func MustGetTestingContext(
	sid string,
) *TestingContext

func (*TestingContext) GetAdjustLockResultFunc

func (tc *TestingContext) GetAdjustLockResultFunc() func(txnID []byte, tableID uint64, res *lock.Result)

func (*TestingContext) GetBeforeLockFunc

func (tc *TestingContext) GetBeforeLockFunc() func(txnID []byte, tableID uint64)

func (*TestingContext) SetAdjustLockResultFunc

func (tc *TestingContext) SetAdjustLockResultFunc(
	fn func(txnID []byte, tableID uint64, res *lock.Result),
)

func (*TestingContext) SetBeforeLockFunc

func (tc *TestingContext) SetBeforeLockFunc(
	fn func(txnID []byte, tableID uint64),
)

Jump to

Keyboard shortcuts

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