Skip to content

Commit

Permalink
Merge pull request #22 from imviv3kshukla/fix/MissingNodeException
Browse files Browse the repository at this point in the history
MissingNodeException bugfix
  • Loading branch information
aravindgopall authored Mar 27, 2023
2 parents 3f49188 + 638e652 commit a21fa1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/Database/Redis/Cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ data Connection = Connection (HM.HashMap NodeID NodeConnection) (MVar Pipeline)
-- | A connection to a single node in the cluster, similar to 'ProtocolPipelining.Connection'
data NodeConnection = NodeConnection CC.ConnectionContext (IOR.IORef (Maybe B.ByteString)) NodeID

instance Show NodeConnection where
show (NodeConnection _ _ id1) = "nodeId: " <> show id1

instance Eq NodeConnection where
(NodeConnection _ _ id1) == (NodeConnection _ _ id2) = id1 == id2

Expand Down Expand Up @@ -239,7 +242,13 @@ rawResponse (CompletedRequest _ _ r) = r
evaluatePipeline :: MVar ShardMap -> IO ShardMap -> Connection -> [[B.ByteString]] -> IO [Reply]
evaluatePipeline shardMapVar refreshShardmapAction conn requests = do
shardMap <- hasLocked $ readMVar shardMapVar
requestsByNode <- getRequestsByNode shardMap
erequestsByNode <- try $ getRequestsByNode shardMap
requestsByNode <- case erequestsByNode of
Right reqByNode-> pure reqByNode
Left (_ :: MissingNodeException) -> do
refreshShardMapVar
newShardMap <- hasLocked $ readMVar shardMapVar
getRequestsByNode newShardMap
-- catch the exception thrown at each node level
-- send the command to random node.
-- merge the current responses with new responses.
Expand Down
4 changes: 3 additions & 1 deletion src/Database/Redis/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,6 @@ refreshShardMapWithConn pipelineConn _ = do
slotsResponse <- runRedisInternal pipelineConn clusterSlots
case slotsResponse of
Left e -> throwIO $ ClusterConnectError e
Right slots -> shardMapFromClusterSlotsResponse slots
Right slots -> case clusterSlotsResponseEntries slots of
[] -> throwIO $ ClusterConnectError $ SingleLine "empty slotsResponse"
_ -> shardMapFromClusterSlotsResponse slots

0 comments on commit a21fa1b

Please sign in to comment.