Skip to content

Commit

Permalink
fix seeds not able to re-join when restart (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Time-Hu authored Oct 28, 2022
1 parent c094c03 commit 03b3f82
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions hstream-gossip/src/HStream/Gossip/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import Control.Concurrent.STM (TVar, atomically,
newBroadcastTChanIO,
newTQueueIO, newTVarIO,
stateTVar)
import Control.Exception (handle, throwIO, try)
import Control.Exception (SomeException, handle,
throwIO, try)
import Control.Monad (void, when)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as BL
Expand Down Expand Up @@ -155,22 +156,25 @@ bootstrap initialServers gc@GossipContext{..} = handle
amIASeed :: I.ServerNode -> [(ByteString, Int)] -> IO (Bool, [(ByteString, Int)], Bool)
amIASeed self@I.ServerNode{..} seeds = do
Log.debug . Log.buildString' $ seeds
if current `elem` seeds then return (True, L.delete current seeds, False) else pingToFindOut (False, seeds, False) seeds
if current `elem` seeds then pingToFindOut (True, L.delete current seeds, False) (L.delete current seeds)
else pingToFindOut (False, seeds, False) seeds
where
current = (serverNodeHost, fromIntegral serverNodeGossipPort)
pingToFindOut old@(isSeed, oldSeeds, wasDead) (join@(joinHost, joinPort):rest) = do
GRPC.withGRPCClient (mkGRPCClientConf' joinHost joinPort) $ \client -> do
new <- GRPC.withGRPCClient (mkGRPCClientConf' joinHost joinPort) $ \client -> do
started <- try (bootstrapPing join client)
new <- case started of
case started of
Right Nothing -> do
Log.debug . Log.buildString $ "I am not " <> show join
return old
Right (Just node) -> if node == self then do
Log.debug ("I am a seed: " <> Log.buildString' join)
return (True, L.delete join oldSeeds, wasDead)
else return old
Left (_ :: ClusterReadyErr) -> return (isSeed, oldSeeds, True)
pingToFindOut new rest
Left (_ :: ClusterReadyErr) -> do
Log.debug . Log.buildString $ "The cluster has been bootstrapped and is running"
return (isSeed, oldSeeds, True)
pingToFindOut new rest
pingToFindOut old _ = return old

handleINITEDEvent :: MVar (Maybe (TVar Int)) -> Int -> MVar () -> EventPayload -> IO ()
Expand Down

0 comments on commit 03b3f82

Please sign in to comment.