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

Store: add doesStreamPartitionValExist #1520

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
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
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