github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/rom.go (about) 1 // Package cmn provides common constants, types, and utilities for AIS clients 2 // and AIStore. 3 /* 4 * Copyright (c) 2023-2024, NVIDIA CORPORATION. All rights reserved. 5 */ 6 package cmn 7 8 import ( 9 "time" 10 11 "github.com/NVIDIA/aistore/cmn/feat" 12 ) 13 14 // read-mostly and most often used timeouts: assign at startup to reduce the number of GCO.Get() calls 15 // updating: a) upon startup, b) periodically, via stats runner, and c) upon receiving new global config 16 17 type readMostly struct { 18 timeout struct { 19 cplane time.Duration // Config.Timeout.CplaneOperation 20 keepalive time.Duration // ditto MaxKeepalive 21 } 22 features feat.Flags 23 level, modules int 24 testingEnv bool 25 authEnabled bool 26 } 27 28 var Rom readMostly 29 30 func (rom *readMostly) init() { 31 rom.timeout.cplane = time.Second + time.Millisecond 32 rom.timeout.keepalive = 2*time.Second + time.Millisecond 33 } 34 35 func (rom *readMostly) Set(cfg *ClusterConfig) { 36 rom.timeout.cplane = cfg.Timeout.CplaneOperation.D() 37 rom.timeout.keepalive = cfg.Timeout.MaxKeepalive.D() 38 rom.features = cfg.Features 39 rom.authEnabled = cfg.Auth.Enabled 40 41 // pre-parse for FastV (below) 42 rom.level, rom.modules = cfg.Log.Level.Parse() 43 } 44 45 func (rom *readMostly) CplaneOperation() time.Duration { return rom.timeout.cplane } 46 func (rom *readMostly) MaxKeepalive() time.Duration { return rom.timeout.keepalive } 47 func (rom *readMostly) Features() feat.Flags { return rom.features } 48 func (rom *readMostly) TestingEnv() bool { return rom.testingEnv } 49 func (rom *readMostly) AuthEnabled() bool { return rom.authEnabled } 50 51 func (rom *readMostly) FastV(verbosity, fl int) bool { 52 return rom.level >= verbosity || rom.modules&fl != 0 53 }