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

hstream: trim log which stores changelog of query state after snapshotting #1745

Merged
merged 1 commit into from
Jan 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import qualified RIO.ByteString.Lazy as BL
class ChangeLogger h where
logChangelog :: h -> BL.ByteString -> IO ()
getChangelogProgress :: h -> IO Word64 -- FIXME: use type variable i
trimChangelog :: h -> Word64 -> IO () -- FIXME: use type variable i

data StateStoreChangelog k v ser
= CLKSPut Text k v -- HS.table: K/V; HG.aggregate: K/V; HTW.aggregate: K/V
Expand Down
6 changes: 6 additions & 0 deletions hstream/src/HStream/Server/Handler/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,14 @@ data QueryRunner = QueryRunner {
instance ChangeLogger () where
logChangelog () _ = return ()
getChangelogProgress () = return minBound
trimChangelog () _ = return ()

-- use logdevice stream
instance ChangeLogger (S.LDClient, S.C_LogID) where
logChangelog (ldClient, logId) bs =
void $ S.append ldClient logId (lazyByteStringToBytes bs) Nothing
getChangelogProgress (ldClient, logId) = S.getTailLSN ldClient logId
trimChangelog (ldClient, logId) lsn = S.trim ldClient logId lsn

---- store processing node states (snapshot)
-- do nothing
Expand All @@ -325,6 +327,8 @@ instance Snapshotter () where
instance Snapshotter RocksDB.DB where
snapshot db = RocksDB.put db def

-- | Do snapshot for a task, then trim old changelogs for this task.
-- May throw exceptions.
doSnapshot :: (ChangeLogger h1, Snapshotter h2) => h1 -> h2 -> Task -> IO ()
doSnapshot h1 h2 Task{..} = do
changelogTail <- getChangelogProgress h1
Expand All @@ -350,6 +354,8 @@ doSnapshot h1 h2 Task{..} = do
valueSer = BL.toStrict $ Aeson.encode value
snapshot h2 keySer valueSer
Log.debug $ "Query " <> Log.build taskName <> ": I have successfully done a snapshot!"
trimChangelog h1 changelogTail
Log.debug $ "Query " <> Log.build taskName <> ": I have successfully trimmed the old changelog!"

--------------------------------------------------------------------------------

Expand Down