Skip to content

Commit

Permalink
chore(hserver): return empty if trimShards request send empty recordI…
Browse files Browse the repository at this point in the history
…ds (#1797)
  • Loading branch information
YangKian authored Apr 23, 2024
1 parent ee9e1b3 commit 46fe1c5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions hstream/src/HStream/Server/Handler/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module HStream.Server.Handler.Stream
) where

import Control.Exception
import qualified Data.Map as Map
import Data.Maybe (fromJust, isNothing)
import qualified Data.Vector as V
import qualified HsGrpc.Server as G
Expand Down Expand Up @@ -183,19 +184,18 @@ trimShardsHandler
trimShardsHandler sc (ServerNormalRequest _metadata request@TrimShardsRequest{..}) = defaultExceptionHandle $ do
Log.info $ "Receive trim Shards Request: " <> Log.buildString' request
validateNameAndThrow ResStream trimShardsRequestStreamName
when (V.null trimShardsRequestRecordIds) $
throwIO . HE.InvalidRecordId $ "recordIds shouldn't be empty"
C.trimShards sc trimShardsRequestStreamName trimShardsRequestRecordIds
>>= returnResp . TrimShardsResponse
if V.null trimShardsRequestRecordIds
then returnResp $ TrimShardsResponse Map.empty
else C.trimShards sc trimShardsRequestStreamName trimShardsRequestRecordIds >>= returnResp . TrimShardsResponse

-- FIXME: update TrimShardsResponse to return successed and failed result
handleTrimShards :: ServerContext -> G.UnaryHandler TrimShardsRequest TrimShardsResponse
handleTrimShards sc _ request@TrimShardsRequest{..} = catchDefaultEx $ do
Log.info $ "Receive trim Shards Request: " <> Log.buildString' request
validateNameAndThrow ResStream trimShardsRequestStreamName
when (V.null trimShardsRequestRecordIds) $
throwIO . HE.InvalidRecordId $ "recordIds shouldn't be empty"
TrimShardsResponse <$> C.trimShards sc trimShardsRequestStreamName trimShardsRequestRecordIds
if V.null trimShardsRequestRecordIds
then return $ TrimShardsResponse Map.empty
else TrimShardsResponse <$> C.trimShards sc trimShardsRequestStreamName trimShardsRequestRecordIds

handleGetTailRecordId :: ServerContext -> G.UnaryHandler GetTailRecordIdRequest GetTailRecordIdResponse
handleGetTailRecordId sc _ req = catchDefaultEx $ do
Expand Down

0 comments on commit 46fe1c5

Please sign in to comment.