github.com/matrixorigin/matrixone@v0.7.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 // TxnOptions options used to create txn 26 TxnOptions = "txn-options" 27 ) 28 29 // Runtime contains the runtime environment for a MO service. Each CN/DN/LOG service 30 // needs to receive a Runtime and will pass the Runtime to all components of the service. 31 // These Runtimes may only be created in main or integration test framework. 32 // 33 // Because most of our BVT tests and integration tests are run in a single mo-service 34 // process, which runs multiple CN, DN and LOG services, the Runtime cannot be set as a 35 // global variable, otherwise we would not be able to set a single Runtime for each service 36 // and each component. 37 // 38 // In other words, there are no global variables inside mo-service, and the scope of global 39 // variables is in a Runtime. 40 // 41 // Since each component holds a Runtime, all mo-service-level parameters should not appear in 42 // the parameter list of the component's initialization function, but should be replaced by the 43 // Runtime's global variables. 44 // 45 // Unfortunately, we can't fully support the isolation of the service-level runtime between services 46 // and they still share a process-level runtime, but at least there is an advantage in that all 47 // service-level components are placed in the runtime, so that the configuration and components can be 48 // easily retrieved from the runtime without having to pass them as parameters, so that when adding 49 // service-level components in the future, there is no need to modify the parameter list. 50 type Runtime interface { 51 // ServiceType return service type 52 ServiceType() metadata.ServiceType 53 // ServiceUUID return service uuid 54 ServiceUUID() string 55 // Logger returns the top-level logger is set at the start of the MO and contains 56 // the service type and unique ID of the service; all subsequent loggers must be 57 // built on this logger. 58 Logger() *log.MOLogger 59 // SubLogger returns sub-loggers used for different purposes. 60 SubLogger(LoggerName) *log.MOLogger 61 // Clock returns the Clock instance of the current runtime environment 62 Clock() clock.Clock 63 // SetGlobalVariables set global variables which scope based in runtime. 64 SetGlobalVariables(name string, value any) 65 // GetGlobalVariables get global variables, return false if variables not found. 66 GetGlobalVariables(name string) (any, bool) 67 } 68 69 // Option used to setup runtime 70 type Option func(*runtime)