github.com/matrixorigin/matrixone@v0.7.0/pkg/hakeeper/checker.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 hakeeper 16 17 import ( 18 "context" 19 20 "github.com/matrixorigin/matrixone/pkg/hakeeper/checkers/util" 21 pb "github.com/matrixorigin/matrixone/pkg/pb/logservice" 22 "github.com/matrixorigin/matrixone/pkg/pb/task" 23 ) 24 25 type IDAllocator interface { 26 // Next returns a new ID that can be used as the replica ID of a DN shard or 27 // Log shard. When the return boolean value is false, it means no more ID 28 // can be allocated at this time. 29 Next() (uint64, bool) 30 Set(first uint64, last uint64) 31 Capacity() uint64 32 } 33 34 // Checker is the interface suppose to be implemented by HAKeeper's 35 // coordinator. Checker is supposed to be stateless - Checker is free to 36 // maintain whatever internal states, but those states should never be 37 // assumed to be persistent across reboots. 38 type Checker interface { 39 // Check is periodically called by the HAKeeper for checking the cluster 40 // health status, a list of Operator instances will be returned describing 41 // actions required to ensure the high availability of the cluster. 42 Check(alloc util.IDAllocator, state pb.CheckerState) []pb.ScheduleCommand 43 } 44 45 // BootstrapManager is the interface suppose to be implemented by HAKeeper's 46 // bootstrap manager. 47 type BootstrapManager interface { 48 Bootstrap(util.IDAllocator, pb.DNState, pb.LogState) ([]pb.ScheduleCommand, error) 49 50 CheckBootstrap(pb.LogState) bool 51 } 52 53 type TaskScheduler interface { 54 Schedule(cnState pb.CNState, currentTick uint64) 55 56 // Create an asynchronous task that executes a single time, this method is idempotent, the 57 // same task is not created repeatedly based on multiple calls. 58 Create(context.Context, []task.TaskMetadata) error 59 60 // StartScheduleCronTask start schedule cron tasks. A timer will be started to pull the latest CronTask 61 // from the TaskStore at regular intervals, and a timer will be maintained in memory for all Cron's to be 62 // triggered at regular intervals. 63 StartScheduleCronTask() 64 // StopScheduleCronTask stop schedule cron tasks. 65 StopScheduleCronTask() 66 }