only specify upper key bound when querying load
As a querying node does not always know the lower bound of the queried segment – determined by the predecessor – let the currently responsible node provide that bound instead. affects #71
This commit is contained in:
		
							parent
							
								
									30bf0529ed
								
							
						
					
					
						commit
						5e745cd035
					
				
					 5 changed files with 25 additions and 26 deletions
				
			
		|  | @ -104,13 +104,13 @@ PingRequestPayload ::= NULL		-- do not include a node/ vserver ID, so that | ||||||
| PingResponsePayload ::= SEQUENCE OF NodeState | PingResponsePayload ::= SEQUENCE OF NodeState | ||||||
| 
 | 
 | ||||||
| LoadRequestPayload ::= SEQUENCE { | LoadRequestPayload ::= SEQUENCE { | ||||||
| 	lowerBound		NodeID, | 	upperSegmentBound		NodeID | ||||||
| 	upperBound		NodeID |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| LoadResponsePayload ::= SEQUENCE { | LoadResponsePayload ::= SEQUENCE { | ||||||
| 	loadSum					REAL, | 	loadSum					REAL, | ||||||
| 	remainingLoadTarget		REAL | 	remainingLoadTarget		REAL, | ||||||
|  | 	lowerBound				NodeID | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| END | END | ||||||
|  |  | ||||||
|  | @ -186,14 +186,14 @@ encodePayload payload'@PingResponsePayload{} = | ||||||
|   <> [End Sequence] |   <> [End Sequence] | ||||||
| encodePayload payload'@LoadRequestPayload{} = | encodePayload payload'@LoadRequestPayload{} = | ||||||
|   [ Start Sequence |   [ Start Sequence | ||||||
|   , IntVal . getNodeID $ loadLowerBound payload' |   , IntVal . getNodeID $ loadSegmentUpperBound payload' | ||||||
|   , IntVal . getNodeID $ loadUpperBound payload' |  | ||||||
|   , End Sequence |   , End Sequence | ||||||
|   ] |   ] | ||||||
| encodePayload payload'@LoadResponsePayload{} = | encodePayload payload'@LoadResponsePayload{} = | ||||||
|   [ Start Sequence |   [ Start Sequence | ||||||
|   , Real $ loadSum payload' |   , Real $ loadSum payload' | ||||||
|   , Real $ loadRemainingTarget payload' |   , Real $ loadRemainingTarget payload' | ||||||
|  |   , IntVal . getNodeID $ loadSegmentLowerBound payload' | ||||||
|   , End Sequence |   , End Sequence | ||||||
|   ] |   ] | ||||||
| 
 | 
 | ||||||
|  | @ -461,19 +461,19 @@ parsePingResponsePayload = onNextContainer Sequence $ do | ||||||
| 
 | 
 | ||||||
| parseLoadRequestPayload :: ParseASN1 ActionPayload | parseLoadRequestPayload :: ParseASN1 ActionPayload | ||||||
| parseLoadRequestPayload = onNextContainer Sequence $ do | parseLoadRequestPayload = onNextContainer Sequence $ do | ||||||
|     loadLowerBound' <- fromInteger <$> parseInteger |  | ||||||
|     loadUpperBound' <- fromInteger <$> parseInteger |     loadUpperBound' <- fromInteger <$> parseInteger | ||||||
|     pure LoadRequestPayload |     pure LoadRequestPayload | ||||||
|         { loadLowerBound = loadLowerBound' |         { loadSegmentUpperBound = loadUpperBound' | ||||||
|         , loadUpperBound = loadUpperBound' |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| parseLoadResponsePayload :: ParseASN1 ActionPayload | parseLoadResponsePayload :: ParseASN1 ActionPayload | ||||||
| parseLoadResponsePayload = onNextContainer Sequence $ do | parseLoadResponsePayload = onNextContainer Sequence $ do | ||||||
|     loadSum' <- parseReal |     loadSum' <- parseReal | ||||||
|     loadRemainingTarget' <- parseReal |     loadRemainingTarget' <- parseReal | ||||||
|  |     loadSegmentLowerBound' <- fromInteger <$> parseInteger | ||||||
|     pure LoadResponsePayload |     pure LoadResponsePayload | ||||||
|         { loadSum = loadSum' |         { loadSum = loadSum' | ||||||
|         , loadRemainingTarget = loadRemainingTarget' |         , loadRemainingTarget = loadRemainingTarget' | ||||||
|  |         , loadSegmentLowerBound = loadSegmentLowerBound' | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -751,16 +751,14 @@ requestPing ns target = do | ||||||
| requestQueryLoad :: (MonadError String m, MonadIO m) | requestQueryLoad :: (MonadError String m, MonadIO m) | ||||||
|                  => LocalNodeState s |                  => LocalNodeState s | ||||||
|                  -> NodeID |                  -> NodeID | ||||||
|                  -> NodeID |  | ||||||
|                  -> RemoteNodeState |                  -> RemoteNodeState | ||||||
|                  -> m SegmentLoadStats |                  -> m SegmentLoadStats | ||||||
| requestQueryLoad ns lowerIdBound upperIdBound target = do | requestQueryLoad ns upperIdBound target = do | ||||||
|     nodeConf <- nodeConfig <$> liftIO (readTVarIO $ parentRealNode ns) |     nodeConf <- nodeConfig <$> liftIO (readTVarIO $ parentRealNode ns) | ||||||
|     let |     let | ||||||
|         srcAddr = confIP nodeConf |         srcAddr = confIP nodeConf | ||||||
|         loadPl = LoadRequestPayload |         loadReqPl = LoadRequestPayload | ||||||
|             { loadLowerBound = lowerIdBound |             { loadSegmentUpperBound = upperIdBound | ||||||
|             , loadUpperBound = upperIdBound |  | ||||||
|             } |             } | ||||||
|     responses <- liftIO $ bracket (mkSendSocket srcAddr (getDomain target) (getDhtPort target)) close |     responses <- liftIO $ bracket (mkSendSocket srcAddr (getDomain target) (getDhtPort target)) close | ||||||
|         (fmap Right . sendRequestTo (confRequestTimeout nodeConf) (confRequestRetries nodeConf) (\rid -> |         (fmap Right . sendRequestTo (confRequestTimeout nodeConf) (confRequestRetries nodeConf) (\rid -> | ||||||
|  | @ -770,13 +768,13 @@ requestQueryLoad ns lowerIdBound upperIdBound target = do | ||||||
|                   , part = 1 |                   , part = 1 | ||||||
|                   , isFinalPart = False |                   , isFinalPart = False | ||||||
|                   , action = QueryLoad |                   , action = QueryLoad | ||||||
|                   , payload = Just loadPl |                   , payload = Just loadReqPl | ||||||
|                         } |                         } | ||||||
|                                                                                                         ) |                                                                                                         ) | ||||||
|         ) `catch`  (\e -> pure . Left $ displayException (e :: IOException)) |         ) `catch`  (\e -> pure . Left $ displayException (e :: IOException)) | ||||||
|     responseMsgSet <- liftEither responses |     responseMsgSet <- liftEither responses | ||||||
|     -- throws an error if an exception happened |     -- throws an error if an exception happened | ||||||
|     loadPl <- maybe (throwError "no load response payload found") pure |     loadResPl <- maybe (throwError "no load response payload found") pure | ||||||
|         (foldr' (\msg acc -> case payload msg of |         (foldr' (\msg acc -> case payload msg of | ||||||
|             -- just extract the first found LoadResponsePayload |             -- just extract the first found LoadResponsePayload | ||||||
|               Just pl@LoadResponsePayload{} | isNothing acc -> Just pl |               Just pl@LoadResponsePayload{} | isNothing acc -> Just pl | ||||||
|  | @ -786,10 +784,10 @@ requestQueryLoad ns lowerIdBound upperIdBound target = do | ||||||
|             responseMsgSet |             responseMsgSet | ||||||
|         ) |         ) | ||||||
|     pure SegmentLoadStats |     pure SegmentLoadStats | ||||||
|         { segmentLowerKeyBound = lowerIdBound |         { segmentLowerKeyBound = loadSegmentLowerBound loadResPl | ||||||
|         , segmentUpperKeyBound = upperIdBound |         , segmentUpperKeyBound = upperIdBound | ||||||
|         , segmentLoad = loadSum loadPl |         , segmentLoad = loadSum loadResPl | ||||||
|         , segmentOwnerLoadTarget = loadRemainingTarget loadPl |         , segmentOwnerLoadTarget = loadRemainingTarget loadResPl | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -58,6 +58,10 @@ data ActionPayload = QueryIDRequestPayload | ||||||
|     } |     } | ||||||
|     | StabiliseRequestPayload |     | StabiliseRequestPayload | ||||||
|     | PingRequestPayload |     | PingRequestPayload | ||||||
|  |     | LoadRequestPayload | ||||||
|  |     { loadSegmentUpperBound :: NodeID | ||||||
|  |     -- ^ upper bound of segment interested in, | ||||||
|  |     } | ||||||
|     | QueryIDResponsePayload |     | QueryIDResponsePayload | ||||||
|     { queryResult :: QueryResponse |     { queryResult :: QueryResponse | ||||||
|     } |     } | ||||||
|  | @ -74,13 +78,10 @@ data ActionPayload = QueryIDRequestPayload | ||||||
|     | PingResponsePayload |     | PingResponsePayload | ||||||
|     { pingNodeStates :: [RemoteNodeState] |     { pingNodeStates :: [RemoteNodeState] | ||||||
|     } |     } | ||||||
|     | LoadRequestPayload |  | ||||||
|     { loadLowerBound :: NodeID |  | ||||||
|     , loadUpperBound :: NodeID |  | ||||||
|     } |  | ||||||
|     | LoadResponsePayload |     | LoadResponsePayload | ||||||
|     { loadSum               :: Double |     { loadSum               :: Double | ||||||
|     , loadRemainingTarget   :: Double |     , loadRemainingTarget   :: Double | ||||||
|  |     , loadSegmentLowerBound :: NodeID | ||||||
|     } |     } | ||||||
|     deriving (Show, Eq) |     deriving (Show, Eq) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -222,12 +222,12 @@ spec = do | ||||||
|                                  ] |                                  ] | ||||||
|                                               } |                                               } | ||||||
|             qLoadReqPayload = LoadRequestPayload |             qLoadReqPayload = LoadRequestPayload | ||||||
|                 { loadLowerBound = fromInteger 12 |                 { loadSegmentUpperBound = 1025 | ||||||
|                 , loadUpperBound = fromInteger 1025 |  | ||||||
|                 } |                 } | ||||||
|             qLoadResPayload = LoadResponsePayload |             qLoadResPayload = LoadResponsePayload | ||||||
|                 { loadSum = 3.141 |                 { loadSum = 3.141 | ||||||
|                 , loadRemainingTarget = -1.337 |                 , loadRemainingTarget = -1.337 | ||||||
|  |                 , loadSegmentLowerBound = 12 | ||||||
|                 } |                 } | ||||||
|             requestTemplate = Request { |             requestTemplate = Request { | ||||||
|                 requestID = 2342 |                 requestID = 2342 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue