github.com/matrixorigin/matrixone@v0.7.0/pkg/hakeeper/config.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 "time" 19 ) 20 21 const ( 22 DefaultTickPerSecond = 10 23 DefaultLogStoreTimeout = 5 * time.Minute 24 DefaultDNStoreTimeout = 10 * time.Second 25 DefaultCNStoreTimeout = 30 * time.Second 26 ) 27 28 type Config struct { 29 // TickPerSecond indicates how many ticks every second. 30 // In HAKeeper, we do not use actual time to measure time elapse. 31 // Instead, we use ticks. 32 TickPerSecond int 33 34 // LogStoreTimeout is the actual time limit between a log store's heartbeat. 35 // If HAKeeper does not receive two heartbeat within LogStoreTimeout, 36 // it regards the log store as down. 37 LogStoreTimeout time.Duration 38 39 // DNStoreTimeout is the actual time limit between a dn store's heartbeat. 40 // If HAKeeper does not receive two heartbeat within DNStoreTimeout, 41 // it regards the dn store as down. 42 DNStoreTimeout time.Duration 43 44 // CNStoreTimeout is the actual time limit between a cn store's heartbeat. 45 // If HAKeeper does not receive two heartbeat within CNStoreTimeout, 46 // it regards the dn store as down. 47 CNStoreTimeout time.Duration 48 } 49 50 func (cfg Config) Validate() error { 51 return nil 52 } 53 54 func (cfg *Config) Fill() { 55 if cfg.TickPerSecond == 0 { 56 cfg.TickPerSecond = DefaultTickPerSecond 57 } 58 if cfg.LogStoreTimeout == 0 { 59 cfg.LogStoreTimeout = DefaultLogStoreTimeout 60 } 61 if cfg.DNStoreTimeout == 0 { 62 cfg.DNStoreTimeout = DefaultDNStoreTimeout 63 } 64 if cfg.CNStoreTimeout == 0 { 65 cfg.CNStoreTimeout = DefaultCNStoreTimeout 66 } 67 } 68 69 func (cfg Config) LogStoreExpired(start, current uint64) bool { 70 return uint64(int(cfg.LogStoreTimeout/time.Second)*cfg.TickPerSecond)+start < current 71 } 72 73 func (cfg Config) DNStoreExpired(start, current uint64) bool { 74 return uint64(int(cfg.DNStoreTimeout/time.Second)*cfg.TickPerSecond)+start < current 75 } 76 77 func (cfg Config) CNStoreExpired(start, current uint64) bool { 78 return uint64(int(cfg.CNStoreTimeout/time.Second)*cfg.TickPerSecond)+start < current 79 } 80 81 func (cfg Config) ExpiredTick(start uint64, timeout time.Duration) uint64 { 82 return uint64(timeout/time.Second)*uint64(cfg.TickPerSecond) + start 83 }