github.com/matrixorigin/matrixone@v1.2.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 DefaultTNStoreTimeout = 10 * time.Second 25 DefaultCNStoreTimeout = 30 * time.Second 26 DefaultProxyStoreTimeout = 30 * time.Second 27 ) 28 29 type Config struct { 30 // TickPerSecond indicates how many ticks every second. 31 // In HAKeeper, we do not use actual time to measure time elapse. 32 // Instead, we use ticks. 33 TickPerSecond int 34 35 // LogStoreTimeout is the actual time limit between a log store's heartbeat. 36 // If HAKeeper does not receive two heartbeat within LogStoreTimeout, 37 // it regards the log store as down. 38 LogStoreTimeout time.Duration 39 40 // TNStoreTimeout is the actual time limit between a tn store's heartbeat. 41 // If HAKeeper does not receive two heartbeat within TNStoreTimeout, 42 // it regards the tn store as down. 43 TNStoreTimeout time.Duration 44 45 // CNStoreTimeout is the actual time limit between a cn store's heartbeat. 46 // If HAKeeper does not receive two heartbeat within CNStoreTimeout, 47 // it regards the tn store as down. 48 CNStoreTimeout time.Duration 49 50 // ProxyStoreTimeout is the actual time limit between a proxy store's heartbeat. 51 // If HAKeeper does not receive two heartbeat within ProxyStoreTimeout, 52 // it regards the proxy store as down. 53 ProxyStoreTimeout time.Duration 54 } 55 56 func (cfg Config) Validate() error { 57 return nil 58 } 59 60 func (cfg *Config) Fill() { 61 if cfg.TickPerSecond == 0 { 62 cfg.TickPerSecond = DefaultTickPerSecond 63 } 64 if cfg.LogStoreTimeout == 0 { 65 cfg.LogStoreTimeout = DefaultLogStoreTimeout 66 } 67 if cfg.TNStoreTimeout == 0 { 68 cfg.TNStoreTimeout = DefaultTNStoreTimeout 69 } 70 if cfg.CNStoreTimeout == 0 { 71 cfg.CNStoreTimeout = DefaultCNStoreTimeout 72 } 73 if cfg.ProxyStoreTimeout == 0 { 74 cfg.ProxyStoreTimeout = DefaultProxyStoreTimeout 75 } 76 } 77 78 func (cfg Config) LogStoreExpired(start, current uint64) bool { 79 return uint64(int(cfg.LogStoreTimeout/time.Second)*cfg.TickPerSecond)+start < current 80 } 81 82 func (cfg Config) TNStoreExpired(start, current uint64) bool { 83 return uint64(int(cfg.TNStoreTimeout/time.Second)*cfg.TickPerSecond)+start < current 84 } 85 86 func (cfg Config) CNStoreExpired(start, current uint64) bool { 87 return uint64(int(cfg.CNStoreTimeout/time.Second)*cfg.TickPerSecond)+start < current 88 } 89 90 func (cfg Config) ProxyStoreExpired(start, current uint64) bool { 91 return uint64(int(cfg.ProxyStoreTimeout/time.Second)*cfg.TickPerSecond)+start < current 92 } 93 94 func (cfg Config) ExpiredTick(start uint64, timeout time.Duration) uint64 { 95 return uint64(timeout/time.Second)*uint64(cfg.TickPerSecond) + start 96 }