github.com/matrixorigin/matrixone@v1.2.0/pkg/cnservice/options.go (about) 1 // Copyright 2021 - 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 cnservice 16 17 import ( 18 "context" 19 20 "github.com/matrixorigin/matrixone/pkg/bootstrap" 21 "github.com/matrixorigin/matrixone/pkg/common/morpc" 22 "github.com/matrixorigin/matrixone/pkg/defines" 23 "github.com/matrixorigin/matrixone/pkg/fileservice" 24 "github.com/matrixorigin/matrixone/pkg/lockservice" 25 "github.com/matrixorigin/matrixone/pkg/logservice" 26 logservicepb "github.com/matrixorigin/matrixone/pkg/pb/logservice" 27 qclient "github.com/matrixorigin/matrixone/pkg/queryservice/client" 28 "github.com/matrixorigin/matrixone/pkg/taskservice" 29 "github.com/matrixorigin/matrixone/pkg/txn/client" 30 "github.com/matrixorigin/matrixone/pkg/udf" 31 "github.com/matrixorigin/matrixone/pkg/util" 32 "github.com/matrixorigin/matrixone/pkg/vm/engine" 33 "go.uber.org/zap" 34 ) 35 36 // Option option to create cn service 37 type Option func(*service) 38 39 // WithLogger setup cn service's logger 40 func WithLogger(logger *zap.Logger) Option { 41 return func(s *service) { 42 s.logger = logger 43 } 44 } 45 46 // WithTaskStorageFactory setup the special task storage factory 47 func WithTaskStorageFactory(factory taskservice.TaskStorageFactory) Option { 48 return func(s *service) { 49 s.task.storageFactory = factory 50 } 51 } 52 53 // WithBootstrapOptions setup bootstrap options 54 func WithBootstrapOptions(options ...bootstrap.Option) Option { 55 return func(s *service) { 56 s.options.bootstrapOptions = options 57 } 58 } 59 60 func WithTxnTraceData(traceDataPath string) Option { 61 return func(s *service) { 62 s.options.traceDataPath = traceDataPath 63 } 64 } 65 66 // WithMessageHandle setup message handle 67 func WithMessageHandle(f func(ctx context.Context, 68 cnAddr string, 69 message morpc.Message, 70 cs morpc.ClientSession, 71 engine engine.Engine, 72 fs fileservice.FileService, 73 lockService lockservice.LockService, 74 queryClient qclient.QueryClient, 75 hakeeper logservice.CNHAKeeperClient, 76 udfService udf.Service, 77 cli client.TxnClient, 78 aicm *defines.AutoIncrCacheManager, 79 mAcquirer func() morpc.Message) error) Option { 80 return func(s *service) { 81 s.requestHandler = f 82 } 83 } 84 85 // WithConfigData saves the data from the config file 86 func WithConfigData(data map[string]*logservicepb.ConfigItem) Option { 87 return func(s *service) { 88 if s.config == nil { 89 s.config = util.NewConfigData(data) 90 } else { 91 util.MergeConfig(s.config, data) 92 } 93 } 94 }