github.com/matrixorigin/matrixone@v1.2.0/pkg/logservice/service_wrap.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 logservice 16 17 import ( 18 "github.com/lni/dragonboat/v4" 19 "github.com/matrixorigin/matrixone/pkg/fileservice" 20 pb "github.com/matrixorigin/matrixone/pkg/pb/logservice" 21 "github.com/matrixorigin/matrixone/pkg/taskservice" 22 ) 23 24 type WrappedService struct { 25 svc *Service 26 } 27 28 func NewWrappedService( 29 c Config, 30 fileService fileservice.FileService, 31 shutdownC chan struct{}, 32 opts ...Option, 33 ) (*WrappedService, error) { 34 svc, err := NewService(c, fileService, shutdownC, opts...) 35 if err != nil { 36 return nil, err 37 } 38 return &WrappedService{svc: svc}, nil 39 } 40 41 func (w *WrappedService) Start() error { 42 return nil 43 } 44 45 func (w *WrappedService) Close() error { 46 return w.svc.Close() 47 } 48 49 func (w *WrappedService) ID() string { 50 return w.svc.ID() 51 } 52 53 func (w *WrappedService) IsLeaderHakeeper() (bool, error) { 54 isLeader, _, err := w.svc.store.isLeaderHAKeeper() 55 return isLeader, err 56 } 57 58 func (w *WrappedService) GetClusterState() (*pb.CheckerState, error) { 59 return w.svc.store.getCheckerState() 60 } 61 62 func (w *WrappedService) SetInitialClusterInfo( 63 logShardNum, tnShartnum, logReplicaNum uint64, 64 ) error { 65 return w.svc.store.setInitialClusterInfo( 66 logShardNum, tnShartnum, logReplicaNum, 0, nil, 67 ) 68 } 69 70 func (w *WrappedService) GetTaskService() (taskservice.TaskService, bool) { 71 w.svc.task.RLock() 72 defer w.svc.task.RUnlock() 73 if w.svc.task.holder == nil { 74 return nil, false 75 } 76 return w.svc.task.holder.Get() 77 } 78 79 // StartHAKeeperReplica 80 // TODO: start hakeeper with specified log store, specified by caller 81 func (w *WrappedService) StartHAKeeperReplica( 82 replicaID uint64, replicas map[uint64]dragonboat.Target, join bool, 83 ) error { 84 return w.svc.store.startHAKeeperReplica(replicaID, replicas, join) 85 }