Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(hserver): return empty if trimShards request send empty recordIds #1797

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading