Skip to content

Commit

Permalink
hstream: trim log which stores changelog of query state after snapsho…
Browse files Browse the repository at this point in the history
…tting (#1745)
  • Loading branch information
Commelina authored Jan 19, 2024
1 parent 43b96cb commit 95c266f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
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

0 comments on commit 95c266f

Please sign in to comment.