github.com/matrixorigin/matrixone@v1.2.0/pkg/common/runtime/types.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package runtime
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/common/log"
    19  	"github.com/matrixorigin/matrixone/pkg/pb/metadata"
    20  	"github.com/matrixorigin/matrixone/pkg/txn/clock"
    21  )
    22  
    23  // The names of all global variables should be defined here.
    24  const (
    25  	// ClusterService cluster service
    26  	ClusterService = "cluster-service"
    27  	// ClusterService cluster service
    28  	LockService = "lock-service"
    29  	// InternalSQLExecutor attr name for internal sql executor
    30  	InternalSQLExecutor = "internal-sql-executor"
    31  	// AutoIncrementService attr name for AutoIncrementService
    32  	AutoIncrementService = "auto-increment-service"
    33  	// StatusServer is the global server of status of cluster.
    34  	StatusServer = "status-server"
    35  	// TxnTraceService txn trance service
    36  	TxnTraceService = "txn-trace-service"
    37  
    38  	// TxnOptions options used to create txn
    39  	TxnOptions = "txn-options"
    40  	// TxnMode runtime default txn mode
    41  	TxnMode = "txn-mode"
    42  	// TxnIsolation runtime default txn isolation
    43  	TxnIsolation = "txn-isolation"
    44  
    45  	// EnableCheckInvalidRCErrors enable check rc errors
    46  	EnableCheckInvalidRCErrors = "enable-check-rc-invalid-error"
    47  
    48  	// MOProtocolVersion is the protocol version of the MO services
    49  	MOProtocolVersion = "protocol-version"
    50  
    51  	// BackgroundCNSelector is the labels of the CN handing the background requests, including mo-logger, task-service.
    52  	BackgroundCNSelector = "background-cn-selector"
    53  )
    54  
    55  // Runtime contains the runtime environment for a MO service. Each CN/DN/LOG service
    56  // needs to receive a Runtime and will pass the Runtime to all components of the service.
    57  // These Runtime may only be created in main or integration test framework.
    58  //
    59  // Because most of our BVT tests and integration tests are run in a single mo-service
    60  // process, which runs multiple CN, TN and LOG services, the Runtime cannot be set as a
    61  // global variable, otherwise we would not be able to set a single Runtime for each service
    62  // and each component.
    63  //
    64  // In other words, there are no global variables inside mo-service, and the scope of global
    65  // variables is in a Runtime.
    66  //
    67  // Since each component holds a Runtime, all mo-service-level parameters should not appear in
    68  // the parameter list of the component's initialization function, but should be replaced by the
    69  // Runtime's global variables.
    70  //
    71  // Unfortunately, we can't fully support the isolation of the service-level runtime between services
    72  // and they still share a process-level runtime, but at least there is an advantage in that all
    73  // service-level components are placed in the runtime, so that the configuration and components can be
    74  // easily retrieved from the runtime without having to pass them as parameters, so that when adding
    75  // service-level components in the future, there is no need to modify the parameter list.
    76  type Runtime interface {
    77  	// ServiceType return service type
    78  	ServiceType() metadata.ServiceType
    79  	// ServiceUUID return service uuid
    80  	ServiceUUID() string
    81  	// Logger returns the top-level logger is set at the start of the MO and contains
    82  	// the service type and unique ID of the service; all subsequent loggers must be
    83  	// built on this logger.
    84  	Logger() *log.MOLogger
    85  	// SubLogger returns sub-loggers used for different purposes.
    86  	SubLogger(LoggerName) *log.MOLogger
    87  	// Clock returns the Clock instance of the current runtime environment
    88  	Clock() clock.Clock
    89  	// SetGlobalVariables set global variables which scope based in runtime.
    90  	SetGlobalVariables(name string, value any)
    91  	// GetGlobalVariables get global variables, return false if variables not found.
    92  	GetGlobalVariables(name string) (any, bool)
    93  }
    94  
    95  // Option used to setup runtime
    96  type Option func(*runtime)