Revision 01f6a5d2
b/README | ||
---|---|---|
30 | 30 |
|
31 | 31 |
So basically we aim to determine here: what is the minimum number of instances |
32 | 32 |
that need to be removed (this is called the removal depth) and which are the |
33 |
actual combinations that fit (called the list of removal sets).
|
|
33 |
actual combinations that fit (called the list of removal sets). |
|
34 | 34 |
|
35 | 35 |
In phase 2, for each removal set computed in the previous phase, we take the |
36 | 36 |
removed instances and try to determine where we can put them so that the |
... | ... | |
228 | 228 |
The programs needs only the output of the node list and instance list. That is, |
229 | 229 |
they need the following two commands to be run:: |
230 | 230 |
|
231 |
gnt-node list -oname,mtotal,mfree,dtotal,dfree,pinst_list,sinst_list \
|
|
231 |
gnt-node list -oname,mtotal,mfree,dtotal,dfree \ |
|
232 | 232 |
--separator '|' --no-headers > nodes |
233 |
gnt-instance list -oname,admin_ram,sda_size \ |
|
233 |
gnt-instance list -oname,admin_ram,sda_size,pnode,snodes \
|
|
234 | 234 |
--separator '|' --no-head > instances |
235 | 235 |
|
236 | 236 |
These two files should be saved under the names of 'nodes' and 'instances'. |
b/src/Cluster.hs | ||
---|---|---|
588 | 588 |
(zip [0..] kerows) |
589 | 589 |
in unzip idxrows |
590 | 590 |
|
591 |
-- | Set the primary or secondary node indices on the instance list. |
|
592 |
fixInstances :: [(Int, Node.Node)] |
|
593 |
-> (Node.Node -> [Int]) -- ^ Either 'Node.slist' or 'Node.plist' |
|
594 |
-> (Instance.Instance -> Int -> Instance.Instance) |
|
595 |
-- ^ Either 'Instance.setSec' or 'Instance.setPri' |
|
596 |
-> [(Int, Instance.Instance)] |
|
597 |
-> [(Int, Instance.Instance)] |
|
598 |
fixInstances nl list_fn set_fn il = |
|
599 |
concat $ map |
|
600 |
(\ (n_idx, n) -> |
|
601 |
map |
|
602 |
(\ i_idx -> |
|
603 |
let oldi = fromJust (lookup i_idx il) |
|
604 |
in |
|
605 |
(i_idx, set_fn oldi n_idx) |
|
606 |
) (list_fn n) |
|
607 |
) nl |
|
608 |
|
|
609 |
-- | Splits and returns a list of indexes based on an Instance assoc list. |
|
610 |
csi :: String -> [(String, Int)] -> [Int] |
|
611 |
csi values il = |
|
612 |
map |
|
613 |
(\ x -> fromJust (lookup x il)) |
|
614 |
(commaSplit values) |
|
591 |
-- | For each instance, add its index to its primary and secondary nodes |
|
592 |
fixNodes :: [(Int, Node.Node)] |
|
593 |
-> [(Int, Instance.Instance)] |
|
594 |
-> [(Int, Node.Node)] |
|
595 |
fixNodes nl il = |
|
596 |
foldl (\accu (idx, inst) -> |
|
597 |
let |
|
598 |
assocEqual = (\ (i, _) (j, _) -> i == j) |
|
599 |
pdx = Instance.pnode inst |
|
600 |
sdx = Instance.snode inst |
|
601 |
pold = fromJust $ lookup pdx nl |
|
602 |
sold = fromJust $ lookup sdx nl |
|
603 |
pnew = Node.setPri pold idx |
|
604 |
snew = Node.setSec sold idx |
|
605 |
ac1 = deleteBy assocEqual (pdx, pold) accu |
|
606 |
ac2 = deleteBy assocEqual (sdx, sold) ac1 |
|
607 |
ac3 = (pdx, pnew):(sdx, snew):ac2 |
|
608 |
in ac3) nl il |
|
609 |
|
|
615 | 610 |
|
616 | 611 |
{-| Initializer function that loads the data from a node and list file |
617 | 612 |
and massages it into the correct format. -} |
... | ... | |
621 | 616 |
Container.Container Instance.Instance, |
622 | 617 |
[(Int, String)], [(Int, String)]) |
623 | 618 |
loadData ndata idata = |
624 |
{- instance file: name mem disk -} |
|
625 |
let (kti, il) = loadTabular idata |
|
626 |
(\ (i:j:k:[]) -> (i, Instance.create j k)) Instance.setIdx |
|
627 |
{- node file: name mem disk plist slist -} |
|
619 |
let |
|
620 |
{- node file: name mem disk -} |
|
628 | 621 |
(ktn, nl) = loadTabular ndata |
629 |
(\ (i:jt:jf:kt:kf:l:m:[]) -> |
|
630 |
(i, Node.create jt jf kt kf (csi l kti) (csi m kti))) |
|
622 |
(\ (i:jt:jf:kt:kf:[]) -> (i, Node.create jt jf kt kf)) |
|
631 | 623 |
Node.setIdx |
632 |
il2 = fixInstances nl Node.slist Instance.setSec $ |
|
633 |
fixInstances nl Node.plist Instance.setPri il |
|
634 |
il3 = Container.fromAssocList il2 |
|
624 |
{- instance file: name mem disk -} |
|
625 |
(kti, il) = loadTabular idata |
|
626 |
(\ (i:j:k:l:m:[]) -> (i, |
|
627 |
Instance.create j k |
|
628 |
(fromJust $ lookup l ktn) |
|
629 |
(fromJust $ lookup m ktn))) |
|
630 |
Instance.setIdx |
|
631 |
nl2 = fixNodes nl il |
|
632 |
il3 = Container.fromAssocList il |
|
635 | 633 |
nl3 = Container.fromAssocList |
636 |
(map (\ (k, v) -> (k, Node.buildPeers v il3 (length nl))) nl)
|
|
634 |
(map (\ (k, v) -> (k, Node.buildPeers v il3 (length nl2))) nl2)
|
|
637 | 635 |
in |
638 | 636 |
(nl3, il3, swapPairs ktn, swapPairs kti) |
b/src/Instance.hs | ||
---|---|---|
13 | 13 |
, idx :: Int -- ^ internal index for book-keeping |
14 | 14 |
} deriving (Show) |
15 | 15 |
|
16 |
create :: String -> String -> Instance |
|
17 |
create mem_init disk_init = Instance { |
|
16 |
create :: String -> String -> Int -> Int -> Instance
|
|
17 |
create mem_init disk_init pn sn = Instance {
|
|
18 | 18 |
mem = read mem_init, |
19 | 19 |
disk = read disk_init, |
20 |
pnode = -1,
|
|
21 |
snode = -1,
|
|
20 |
pnode = pn,
|
|
21 |
snode = sn,
|
|
22 | 22 |
idx = -1 |
23 | 23 |
} |
24 | 24 |
|
b/src/Node.hs | ||
---|---|---|
17 | 17 |
, removeSec |
18 | 18 |
, addPri |
19 | 19 |
, addSec |
20 |
, setPri |
|
21 |
, setSec |
|
20 | 22 |
-- * Statistics |
21 | 23 |
, normUsed |
22 | 24 |
-- * Formatting |
... | ... | |
52 | 54 |
later via the 'setIdx' and 'buildPeers' functions. |
53 | 55 |
|
54 | 56 |
-} |
55 |
create :: String -> String -> String -> String -> [Int] -> [Int] -> Node
|
|
57 |
create :: String -> String -> String -> String -> Node |
|
56 | 58 |
create mem_t_init mem_f_init disk_t_init disk_f_init |
57 |
plist_init slist_init = Node
|
|
59 |
= Node |
|
58 | 60 |
{ |
59 | 61 |
t_mem = read mem_t_init, |
60 | 62 |
f_mem = read mem_f_init, |
61 | 63 |
t_disk = read disk_t_init, |
62 | 64 |
f_disk = read disk_f_init, |
63 |
plist = plist_init,
|
|
64 |
slist = slist_init,
|
|
65 |
plist = [],
|
|
66 |
slist = [],
|
|
65 | 67 |
failN1 = True, |
66 | 68 |
idx = -1, |
67 | 69 |
peers = PeerMap.empty, |
... | ... | |
158 | 160 |
peers = new_peers, failN1 = new_failn1, |
159 | 161 |
maxRes = new_rmem} |
160 | 162 |
|
163 |
-- | Add a primary instance to a node without other updates |
|
164 |
setPri :: Node -> Int -> Node |
|
165 |
setPri t idx = t { plist = idx:(plist t) } |
|
166 |
|
|
167 |
-- | Add a secondary instance to a node without other updates |
|
168 |
setSec :: Node -> Int -> Node |
|
169 |
setSec t idx = t { slist = idx:(slist t) } |
|
170 |
|
|
161 | 171 |
-- | Simple converter to string. |
162 | 172 |
str :: Node -> String |
163 | 173 |
str t = |
Also available in: Unified diff