Skip to content

Commit

Permalink
Store: add doesStreamPartitionValExist (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
4eUeP authored Jul 20, 2023
1 parent a8f3455 commit 703fcef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions hstream-store/HStream/Store/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module HStream.Store.Stream
, doesStreamExist
, listStreamPartitions
, doesStreamPartitionExist
, doesStreamPartitionValExist
, getStreamExtraAttrs
, updateStreamExtraAttrs
-- ** helpers
Expand Down Expand Up @@ -504,6 +505,22 @@ doesStreamPartitionExist client streamid m_key = do
Right _loggroup -> return True
#endif

doesStreamPartitionValExist
:: HasCallStack
=> FFI.LDClient
-> StreamId
-> FFI.C_LogID
-> IO Bool
doesStreamPartitionValExist client streamid logid = do
r <- try $ do
dir_path <- getStreamDirPath streamid
keys <- LD.logDirLogsNames =<< LD.getLogDirectory client dir_path
logids <- forM keys $ getUnderlyingLogId client streamid . Just
pure $ logid `elem` logids
case r of
Left (_ :: E.NOTFOUND) -> return False
Right x -> return x

-------------------------------------------------------------------------------
-- StreamAttrs

Expand Down
3 changes: 3 additions & 0 deletions hstream-store/test/HStream/Store/StreamSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ base = describe "BaseSpec" $ do

log_id <- S.createStreamPartition client stream1 key Map.empty
S.doesStreamPartitionExist client stream1 key `shouldReturn` True
log_id `shouldNotBe` 1234
S.doesStreamPartitionValExist client stream1 1234 `shouldReturn` False
S.doesStreamPartitionValExist client stream1 log_id `shouldReturn` True
S.listStreamPartitions client stream1 >>= (`shouldSatisfy` M.member keyString)

S.renameStream' client stream1 streamName2
Expand Down

0 comments on commit 703fcef

Please sign in to comment.