start implementing k-choices rebalancing, considering 1 VS each run

only loop implemented, rebalancing not implemented
This commit is contained in:
Trolli Schmittlauch 2020-10-07 00:42:33 +02:00
parent b111515178
commit 0cb4b6815c

View file

@ -322,6 +322,34 @@ kChoicesDepartureCost remainingOwnLoad ownCap thisSegmentLoad segment =
+ abs (remainingOwnLoad + thisSegmentLoad) / ownCap
- abs (segmentOwnerRemainingLoadTarget segment) / segmentOwnerCapacity segment
kChoicesRebalanceThread :: (Service s (RealNodeSTM s)) => RealNodeSTM s -> IO ()
kChoicesRebalanceThread nodeSTM = (confKChoicesRebalanceInterval . nodeConfig <$> readTVarIO nodeSTM) >>= rebalanceVS 0
where
rebalanceVS :: NodeID -> Int -> IO ()
rebalanceVS startAt interval = do
threadDelay interval
(vsToRebalance', serv) <- atomically $ do
node <- readTVar nodeSTM
pure (rMapLookupPred 0 (vservers node), nodeService node)
maybe
-- wait and retry if no active VS available
(rebalanceVS startAt interval)
(\(vsNid, vsSTM) -> do
vs <- readTVarIO vsSTM
-- query neighbour node(s) load
-- query own load
-- calculate departure cost
-- if deciding to re-balance, first leave and then join
-- loop
rebalanceVS vsNid interval
)
vsToRebalance'
-- placeholder
pure ()
-- | Join a new node into the DHT, using a provided bootstrap node as initial cache seed
-- for resolving the new node's position.
fediChordBootstrapJoin :: Service s (RealNodeSTM s)