Revision 12e6776a
b/Ganeti/HTools/Node.hs | ||
---|---|---|
60 | 60 |
|
61 | 61 |
import qualified Ganeti.HTools.Container as Container |
62 | 62 |
import qualified Ganeti.HTools.Instance as Instance |
63 |
import qualified Ganeti.HTools.PeerMap as PeerMap
|
|
63 |
import qualified Ganeti.HTools.PeerMap as P |
|
64 | 64 |
|
65 | 65 |
import qualified Ganeti.HTools.Types as T |
66 | 66 |
|
67 | 67 |
-- * Type declarations |
68 | 68 |
|
69 | 69 |
-- | The node type. |
70 |
data Node = Node { name :: String -- ^ The node name |
|
71 |
, tMem :: Double -- ^ Total memory (MiB) |
|
72 |
, nMem :: Int -- ^ Node memory (MiB) |
|
73 |
, fMem :: Int -- ^ Free memory (MiB) |
|
74 |
, xMem :: Int -- ^ Unaccounted memory (MiB) |
|
75 |
, tDsk :: Double -- ^ Total disk space (MiB) |
|
76 |
, fDsk :: Int -- ^ Free disk space (MiB) |
|
77 |
, tCpu :: Double -- ^ Total CPU count |
|
78 |
, uCpu :: Int -- ^ Used VCPU count |
|
79 |
, pList :: [T.Idx]-- ^ List of primary instance indices |
|
80 |
, sList :: [T.Idx]-- ^ List of secondary instance indices |
|
81 |
, idx :: T.Ndx -- ^ Internal index for book-keeping |
|
82 |
, peers :: PeerMap.PeerMap -- ^ Pnode to instance mapping |
|
83 |
, failN1 :: Bool -- ^ Whether the node has failed n1 |
|
84 |
, rMem :: Int -- ^ Maximum memory needed for |
|
85 |
-- failover by primaries of this node |
|
86 |
, pMem :: Double -- ^ Percent of free memory |
|
87 |
, pDsk :: Double -- ^ Percent of free disk |
|
88 |
, pRem :: Double -- ^ Percent of reserved memory |
|
89 |
, pCpu :: Double -- ^ Ratio of virtual to physical CPUs |
|
90 |
, mDsk :: Double -- ^ Minimum free disk ratio |
|
91 |
, mCpu :: Double -- ^ Max ratio of virt-to-phys CPUs |
|
92 |
, loDsk :: Int -- ^ Autocomputed from mDsk low disk |
|
93 |
-- threshold |
|
94 |
, hiCpu :: Int -- ^ Autocomputed from mCpu high cpu |
|
95 |
-- threshold |
|
96 |
, offline :: Bool -- ^ Whether the node should not be used |
|
97 |
-- for allocations and skipped from |
|
98 |
-- score computations |
|
99 |
, utilPool :: T.DynUtil -- ^ Total utilisation capacity |
|
100 |
, utilLoad :: T.DynUtil -- ^ Sum of instance utilisation |
|
101 |
} deriving (Show) |
|
70 |
data Node = Node |
|
71 |
{ name :: String -- ^ The node name |
|
72 |
, tMem :: Double -- ^ Total memory (MiB) |
|
73 |
, nMem :: Int -- ^ Node memory (MiB) |
|
74 |
, fMem :: Int -- ^ Free memory (MiB) |
|
75 |
, xMem :: Int -- ^ Unaccounted memory (MiB) |
|
76 |
, tDsk :: Double -- ^ Total disk space (MiB) |
|
77 |
, fDsk :: Int -- ^ Free disk space (MiB) |
|
78 |
, tCpu :: Double -- ^ Total CPU count |
|
79 |
, uCpu :: Int -- ^ Used VCPU count |
|
80 |
, pList :: [T.Idx] -- ^ List of primary instance indices |
|
81 |
, sList :: [T.Idx] -- ^ List of secondary instance indices |
|
82 |
, idx :: T.Ndx -- ^ Internal index for book-keeping |
|
83 |
, peers :: P.PeerMap -- ^ Pnode to instance mapping |
|
84 |
, failN1 :: Bool -- ^ Whether the node has failed n1 |
|
85 |
, rMem :: Int -- ^ Maximum memory needed for failover by |
|
86 |
-- primaries of this node |
|
87 |
, pMem :: Double -- ^ Percent of free memory |
|
88 |
, pDsk :: Double -- ^ Percent of free disk |
|
89 |
, pRem :: Double -- ^ Percent of reserved memory |
|
90 |
, pCpu :: Double -- ^ Ratio of virtual to physical CPUs |
|
91 |
, mDsk :: Double -- ^ Minimum free disk ratio |
|
92 |
, mCpu :: Double -- ^ Max ratio of virt-to-phys CPUs |
|
93 |
, loDsk :: Int -- ^ Autocomputed from mDsk low disk |
|
94 |
-- threshold |
|
95 |
, hiCpu :: Int -- ^ Autocomputed from mCpu high cpu |
|
96 |
-- threshold |
|
97 |
, offline :: Bool -- ^ Whether the node should not be used |
|
98 |
-- for allocations and skipped from score |
|
99 |
-- computations |
|
100 |
, utilPool :: T.DynUtil -- ^ Total utilisation capacity |
|
101 |
, utilLoad :: T.DynUtil -- ^ Sum of instance utilisation |
|
102 |
} deriving (Show) |
|
102 | 103 |
|
103 | 104 |
instance T.Element Node where |
104 | 105 |
nameOf = name |
... | ... | |
146 | 147 |
, sList = [] |
147 | 148 |
, failN1 = True |
148 | 149 |
, idx = -1 |
149 |
, peers = PeerMap.empty
|
|
150 |
, peers = P.empty |
|
150 | 151 |
, rMem = 0 |
151 | 152 |
, pMem = fromIntegral mem_f_init / mem_t_init |
152 | 153 |
, pDsk = fromIntegral dsk_f_init / dsk_t_init |
... | ... | |
194 | 195 |
setMcpu t val = t { mCpu = val, hiCpu = floor (val * tCpu t) } |
195 | 196 |
|
196 | 197 |
-- | Computes the maximum reserved memory for peers from a peer map. |
197 |
computeMaxRes :: PeerMap.PeerMap -> PeerMap.Elem
|
|
198 |
computeMaxRes = PeerMap.maxElem
|
|
198 |
computeMaxRes :: P.PeerMap -> P.Elem
|
|
199 |
computeMaxRes = P.maxElem |
|
199 | 200 |
|
200 | 201 |
-- | Builds the peer map for a given node. |
201 | 202 |
buildPeers :: Node -> Instance.List -> Node |
... | ... | |
204 | 205 |
(\i_idx -> let inst = Container.find i_idx il |
205 | 206 |
in (Instance.pNode inst, Instance.mem inst)) |
206 | 207 |
(sList t) |
207 |
pmap = PeerMap.accumArray (+) mdata
|
|
208 |
pmap = P.accumArray (+) mdata |
|
208 | 209 |
new_rmem = computeMaxRes pmap |
209 | 210 |
new_failN1 = fMem t <= new_rmem |
210 | 211 |
new_prem = fromIntegral new_rmem / tMem t |
... | ... | |
262 | 263 |
new_slist = delete iname (sList t) |
263 | 264 |
new_dsk = fDsk t + Instance.dsk inst |
264 | 265 |
old_peers = peers t |
265 |
old_peem = PeerMap.find pnode old_peers
|
|
266 |
old_peem = P.find pnode old_peers |
|
266 | 267 |
new_peem = old_peem - Instance.mem inst |
267 |
new_peers = PeerMap.add pnode new_peem old_peers
|
|
268 |
new_peers = P.add pnode new_peem old_peers |
|
268 | 269 |
old_rmem = rMem t |
269 | 270 |
new_rmem = if old_peem < old_rmem |
270 | 271 |
then old_rmem |
... | ... | |
310 | 311 |
old_peers = peers t |
311 | 312 |
old_mem = fMem t |
312 | 313 |
new_dsk = fDsk t - Instance.dsk inst |
313 |
new_peem = PeerMap.find pdx old_peers + Instance.mem inst
|
|
314 |
new_peers = PeerMap.add pdx new_peem old_peers
|
|
314 |
new_peem = P.find pdx old_peers + Instance.mem inst |
|
315 |
new_peers = P.add pdx new_peem old_peers |
|
315 | 316 |
new_rmem = max (rMem t) new_peem |
316 | 317 |
new_prem = fromIntegral new_rmem / tMem t |
317 | 318 |
new_failn1 = old_mem <= new_rmem |
Also available in: Unified diff