2015-02-16 19:08:29 +00:00
|
|
|
{- Persistent sqlite database handles.
|
|
|
|
-
|
2023-02-23 19:28:22 +00:00
|
|
|
- Copyright 2015-2023 Joey Hess <id@joeyh.name>
|
2015-02-16 19:08:29 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2015-02-16 19:08:29 +00:00
|
|
|
-}
|
|
|
|
|
2023-09-15 11:56:10 +00:00
|
|
|
{-# LANGUAGE TypeFamilies, TypeOperators #-}
|
|
|
|
{-# LANGUAGE FlexibleContexts, OverloadedStrings, CPP #-}
|
2019-09-26 16:24:03 +00:00
|
|
|
|
2015-02-16 19:08:29 +00:00
|
|
|
module Database.Handle (
|
|
|
|
DbHandle,
|
|
|
|
openDb,
|
2015-12-23 18:59:58 +00:00
|
|
|
TableName,
|
2015-02-18 18:11:27 +00:00
|
|
|
queryDb,
|
2015-02-16 20:04:23 +00:00
|
|
|
closeDb,
|
2015-02-18 18:11:27 +00:00
|
|
|
commitDb,
|
2015-12-23 18:59:58 +00:00
|
|
|
commitDb',
|
2015-02-16 19:08:29 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Utility.Exception
|
2015-12-23 22:34:51 +00:00
|
|
|
import Utility.FileSystemEncoding
|
2022-06-06 16:36:55 +00:00
|
|
|
import Utility.Debug
|
2022-06-03 18:10:24 +00:00
|
|
|
import Utility.DebugLocks
|
2022-10-18 19:47:20 +00:00
|
|
|
import Utility.InodeCache
|
2015-02-16 19:08:29 +00:00
|
|
|
|
allow for concurrent incremental fsck processes again (sorta)
Sqlite doesn't support multiple concurrent writers
at all. One of them will fail to write. It's not even possible to have two
processes building up separate transactions at the same time. Before using
sqlite, incremental fsck could work perfectly well with multiple fsck
processes running concurrently. I'd like to keep that working.
My partial solution, so far, is to make git-annex buffer writes, and every
so often send them all to sqlite at once, in a transaction. So most of the
time, nothing is writing to the database. (And if it gets unlucky and
a write fails due to a collision with another writer, it can just wait and
retry the write later.) This lets multiple processes write to the database
successfully.
But, for the purposes of concurrent, incremental fsck, it's not ideal.
Each process doesn't immediately learn of files that another process has
checked. So they'll tend to do redundant work.
Only way I can see to improve this is to use some other mechanism for
short-term IPC between the fsck processes. Not yet done.
----
Also, make addDb check if an item is in the database already, and not try
to re-add it. That fixes an intermittent crash with
"SQLite3 returned ErrorConstraint while attempting to perform step."
I am not 100% sure why; it only started happening when I moved write
buffering into the queue. It seemed to generally happen on the same file
each time, so could just be due to multiple files having the same key.
However, I doubt my sound repo has many duplicate keys, and I suspect
something else is going on.
----
Updated benchmark, with the 1000 item queue: 6m33.808s
2015-02-17 20:39:35 +00:00
|
|
|
import Database.Persist.Sqlite
|
2015-02-18 19:54:24 +00:00
|
|
|
import qualified Database.Sqlite as Sqlite
|
2015-02-16 20:48:19 +00:00
|
|
|
import Control.Monad
|
2015-02-16 19:08:29 +00:00
|
|
|
import Control.Monad.IO.Class (liftIO)
|
2019-09-26 16:24:03 +00:00
|
|
|
import Control.Monad.IO.Unlift (MonadUnliftIO, withRunInIO)
|
2021-04-01 16:19:47 +00:00
|
|
|
import Control.Monad.Logger (MonadLoggerIO, askLoggerIO)
|
2015-02-16 19:08:29 +00:00
|
|
|
import Control.Concurrent
|
|
|
|
import Control.Concurrent.Async
|
2015-12-23 20:11:36 +00:00
|
|
|
import Control.Exception (throwIO, BlockedIndefinitelyOnMVar(..))
|
2015-02-16 19:08:29 +00:00
|
|
|
import qualified Data.Text as T
|
2015-02-22 18:08:26 +00:00
|
|
|
import Control.Monad.Trans.Resource (runResourceT)
|
|
|
|
import Control.Monad.Logger (runNoLoggingT)
|
2015-12-09 18:55:47 +00:00
|
|
|
import System.IO
|
2015-02-16 19:08:29 +00:00
|
|
|
|
|
|
|
{- A DbHandle is a reference to a worker thread that communicates with
|
2023-02-23 19:28:22 +00:00
|
|
|
- the database. It has a MVar which Jobs are submitted to.
|
|
|
|
- There is also an MVar which it will fill when there is a fatal error-}
|
|
|
|
data DbHandle = DbHandle RawFilePath (Async ()) (MVar Job) (MVar String)
|
2015-02-16 19:08:29 +00:00
|
|
|
|
2015-12-23 18:59:58 +00:00
|
|
|
{- Name of a table that should exist once the database is initialized. -}
|
|
|
|
type TableName = String
|
|
|
|
|
2015-02-18 19:54:24 +00:00
|
|
|
{- Opens the database, but does not perform any migrations. Only use
|
2017-09-06 21:07:49 +00:00
|
|
|
- once the database is known to exist and have the right tables. -}
|
2021-10-20 16:24:40 +00:00
|
|
|
openDb :: RawFilePath -> TableName -> IO DbHandle
|
|
|
|
openDb db tablename = do
|
2015-02-16 19:08:29 +00:00
|
|
|
jobs <- newEmptyMVar
|
2023-02-23 19:28:22 +00:00
|
|
|
errvar <- newEmptyMVar
|
|
|
|
worker <- async (workerThread db tablename jobs errvar)
|
2015-12-23 22:34:51 +00:00
|
|
|
|
|
|
|
-- work around https://github.com/yesodweb/persistent/issues/474
|
2016-12-30 22:14:19 +00:00
|
|
|
liftIO $ fileEncoding stderr
|
2015-12-23 22:34:51 +00:00
|
|
|
|
2023-02-23 19:28:22 +00:00
|
|
|
return $ DbHandle db worker jobs errvar
|
2015-12-23 18:59:58 +00:00
|
|
|
|
2015-12-23 20:11:36 +00:00
|
|
|
{- This is optional; when the DbHandle gets garbage collected it will
|
|
|
|
- auto-close. -}
|
2015-12-23 18:59:58 +00:00
|
|
|
closeDb :: DbHandle -> IO ()
|
2023-02-23 19:28:22 +00:00
|
|
|
closeDb (DbHandle _db worker jobs _) = do
|
2022-06-03 18:10:24 +00:00
|
|
|
debugLocks $ putMVar jobs CloseJob
|
2015-12-23 18:59:58 +00:00
|
|
|
wait worker
|
|
|
|
|
|
|
|
{- Makes a query using the DbHandle. This should not be used to make
|
|
|
|
- changes to the database!
|
|
|
|
-
|
|
|
|
- Note that the action is not run by the calling thread, but by a
|
|
|
|
- worker thread. Exceptions are propigated to the calling thread.
|
|
|
|
-
|
|
|
|
- Only one action can be run at a time against a given DbHandle.
|
|
|
|
- If called concurrently in the same process, this will block until
|
|
|
|
- it is able to run.
|
|
|
|
-}
|
|
|
|
queryDb :: DbHandle -> SqlPersistM a -> IO a
|
2023-02-23 19:28:22 +00:00
|
|
|
queryDb (DbHandle _db _ jobs errvar) a = do
|
2015-12-23 18:59:58 +00:00
|
|
|
res <- newEmptyMVar
|
|
|
|
putMVar jobs $ QueryJob $
|
2022-06-03 18:10:24 +00:00
|
|
|
debugLocks $ liftIO . putMVar res =<< tryNonAsync a
|
2023-02-23 19:28:22 +00:00
|
|
|
debugLocks $ takeMVarSafe res >>= \case
|
|
|
|
Right r -> either throwIO return r
|
|
|
|
Left BlockedIndefinitelyOnMVar -> do
|
|
|
|
err <- takeMVar errvar
|
2023-04-10 17:38:14 +00:00
|
|
|
giveup $ "sqlite worker thread crashed: " ++ err
|
2015-12-23 18:59:58 +00:00
|
|
|
|
|
|
|
{- Writes a change to the database.
|
|
|
|
-
|
2022-10-17 19:56:19 +00:00
|
|
|
- Writes can fail when another write is happening concurrently.
|
2022-10-18 19:47:20 +00:00
|
|
|
- So write failures are caught and retried.
|
|
|
|
-
|
|
|
|
- Retries repeatedly for up to 60 seconds. Part that point, it continues
|
|
|
|
- retrying only if the database shows signs of being modified by another
|
|
|
|
- process at least once each 30 seconds.
|
2015-12-23 18:59:58 +00:00
|
|
|
-}
|
|
|
|
commitDb :: DbHandle -> SqlPersistM () -> IO ()
|
2023-04-19 16:43:30 +00:00
|
|
|
commitDb h@(DbHandle db _ _ errvar) wa =
|
2022-10-18 19:47:20 +00:00
|
|
|
robustly (commitDb' h wa) maxretries emptyDatabaseInodeCache
|
2015-12-23 18:59:58 +00:00
|
|
|
where
|
2022-10-18 19:47:20 +00:00
|
|
|
robustly a retries ic = do
|
2015-12-23 18:59:58 +00:00
|
|
|
r <- a
|
|
|
|
case r of
|
2023-04-19 16:43:30 +00:00
|
|
|
Right (Right _) -> return ()
|
|
|
|
Right (Left err) -> do
|
2022-10-18 19:47:20 +00:00
|
|
|
threadDelay briefdelay
|
|
|
|
retryHelper "write to" err maxretries db retries ic $
|
|
|
|
robustly a
|
2023-04-19 16:43:30 +00:00
|
|
|
Left BlockedIndefinitelyOnMVar -> do
|
|
|
|
err <- takeMVar errvar
|
|
|
|
giveup $ "sqlite worker thread crashed: " ++ err
|
2022-10-18 19:47:20 +00:00
|
|
|
|
|
|
|
briefdelay = 100000 -- 1/10th second
|
|
|
|
|
|
|
|
maxretries = 300 :: Int -- 30 seconds of briefdelay
|
2015-12-23 18:59:58 +00:00
|
|
|
|
2023-04-19 16:43:30 +00:00
|
|
|
commitDb' :: DbHandle -> SqlPersistM () -> IO (Either BlockedIndefinitelyOnMVar (Either SomeException ()))
|
2023-02-23 19:28:22 +00:00
|
|
|
commitDb' (DbHandle _ _ jobs _) a = do
|
2022-06-06 16:36:55 +00:00
|
|
|
debug "Database.Handle" "commitDb start"
|
2015-12-23 18:59:58 +00:00
|
|
|
res <- newEmptyMVar
|
2021-10-20 16:32:46 +00:00
|
|
|
putMVar jobs $ ChangeJob $
|
2022-06-03 18:10:24 +00:00
|
|
|
debugLocks $ liftIO . putMVar res =<< tryNonAsync a
|
2023-04-19 16:43:30 +00:00
|
|
|
r <- debugLocks $ takeMVarSafe res
|
2022-06-06 16:36:55 +00:00
|
|
|
case r of
|
2023-04-19 16:43:30 +00:00
|
|
|
Right (Right ()) -> debug "Database.Handle" "commitDb done"
|
|
|
|
Right (Left e) -> debug "Database.Handle" ("commitDb failed: " ++ show e)
|
2023-07-25 20:11:06 +00:00
|
|
|
Left BlockedIndefinitelyOnMVar -> debug "Database.Handle" "commitDb BlockedIndefinitelyOnMVar"
|
2022-06-06 16:36:55 +00:00
|
|
|
|
|
|
|
return r
|
2015-02-16 19:08:29 +00:00
|
|
|
|
2015-02-18 18:11:27 +00:00
|
|
|
data Job
|
|
|
|
= QueryJob (SqlPersistM ())
|
2021-10-20 16:32:46 +00:00
|
|
|
| ChangeJob (SqlPersistM ())
|
2015-02-18 18:11:27 +00:00
|
|
|
| CloseJob
|
|
|
|
|
2023-02-23 19:28:22 +00:00
|
|
|
workerThread :: RawFilePath -> TableName -> MVar Job -> MVar String -> IO ()
|
|
|
|
workerThread db tablename jobs errvar = newconn
|
2015-02-16 19:08:29 +00:00
|
|
|
where
|
2021-10-20 16:13:49 +00:00
|
|
|
newconn = do
|
2017-09-18 23:42:20 +00:00
|
|
|
v <- tryNonAsync (runSqliteRobustly tablename db loop)
|
|
|
|
case v of
|
2023-02-23 19:28:22 +00:00
|
|
|
Left e -> putMVar errvar (show e)
|
2021-10-20 16:13:49 +00:00
|
|
|
Right cont -> cont
|
2015-02-22 18:08:26 +00:00
|
|
|
|
2015-02-18 18:11:27 +00:00
|
|
|
loop = do
|
2023-02-23 19:28:22 +00:00
|
|
|
job <- liftIO (takeMVarSafe jobs)
|
2015-02-22 18:21:39 +00:00
|
|
|
case job of
|
2015-12-23 20:11:36 +00:00
|
|
|
-- Exception is thrown when the MVar is garbage
|
|
|
|
-- collected, which means the whole DbHandle
|
|
|
|
-- is not used any longer. Shutdown cleanly.
|
2021-10-20 16:13:49 +00:00
|
|
|
Left BlockedIndefinitelyOnMVar -> return (return ())
|
|
|
|
Right CloseJob -> return (return ())
|
2015-12-23 20:11:36 +00:00
|
|
|
Right (QueryJob a) -> a >> loop
|
2021-10-20 16:24:40 +00:00
|
|
|
Right (ChangeJob a) -> do
|
2021-10-20 16:32:46 +00:00
|
|
|
a
|
|
|
|
-- Exit the sqlite connection so the
|
|
|
|
-- database gets updated on disk.
|
2021-10-20 16:13:49 +00:00
|
|
|
return newconn
|
2022-10-18 19:47:20 +00:00
|
|
|
|
|
|
|
{- Like runSqlite, but more robust.
|
|
|
|
-
|
|
|
|
- New database connections can sometimes take a while to become usable,
|
|
|
|
- and selects will fail with ErrorBusy in the meantime. This may be due to
|
|
|
|
- WAL mode recovering after a crash, or a concurrent writer.
|
|
|
|
- So, wait until a select succeeds; once one succeeds the connection will
|
|
|
|
- stay usable.
|
|
|
|
-
|
|
|
|
- Also sqlite sometimes throws ErrorIO when there's not really an IO
|
|
|
|
- problem, but perhaps just a short read(). So also retry on ErrorIO.
|
|
|
|
-
|
|
|
|
- Retries repeatedly for up to 60 seconds. Part that point, it continues
|
|
|
|
- retrying only if the database shows signs of being modified by another
|
|
|
|
- process at least once each 30 seconds.
|
|
|
|
-}
|
|
|
|
runSqliteRobustly :: TableName -> RawFilePath -> (SqlPersistM a) -> IO a
|
2015-12-23 20:11:36 +00:00
|
|
|
runSqliteRobustly tablename db a = do
|
2022-10-18 19:47:20 +00:00
|
|
|
conn <- opensettle maxretries emptyDatabaseInodeCache
|
|
|
|
go conn maxretries emptyDatabaseInodeCache
|
2015-12-23 20:11:36 +00:00
|
|
|
where
|
2022-10-18 19:47:20 +00:00
|
|
|
go conn retries ic = do
|
2018-10-30 22:03:03 +00:00
|
|
|
r <- try $ runResourceT $ runNoLoggingT $
|
2022-10-18 19:47:20 +00:00
|
|
|
withSqlConnRobustly db (wrapConnection conn) $
|
2018-10-30 22:03:03 +00:00
|
|
|
runSqlConn a
|
|
|
|
case r of
|
|
|
|
Right v -> return v
|
|
|
|
Left ex@(Sqlite.SqliteException { Sqlite.seError = e })
|
2022-10-18 19:47:20 +00:00
|
|
|
| e == Sqlite.ErrorIO -> do
|
|
|
|
briefdelay
|
|
|
|
retryHelper "access" ex maxretries db retries ic $
|
|
|
|
go conn
|
|
|
|
| otherwise -> rethrow $ errmsg "after successful open" ex
|
2018-10-30 22:03:03 +00:00
|
|
|
|
2022-10-18 19:47:20 +00:00
|
|
|
opensettle retries ic = do
|
|
|
|
conn <- Sqlite.open tdb
|
|
|
|
settle conn retries ic
|
2018-10-30 22:03:03 +00:00
|
|
|
|
2022-10-18 19:47:20 +00:00
|
|
|
tdb = T.pack (fromRawFilePath db)
|
|
|
|
|
|
|
|
settle conn retries ic = do
|
2018-10-30 22:03:03 +00:00
|
|
|
r <- try $ do
|
2015-02-22 18:08:26 +00:00
|
|
|
stmt <- Sqlite.prepare conn nullselect
|
|
|
|
void $ Sqlite.step stmt
|
|
|
|
void $ Sqlite.finalize stmt
|
|
|
|
case r of
|
2018-10-30 22:03:03 +00:00
|
|
|
Right _ -> return conn
|
|
|
|
Left ex@(Sqlite.SqliteException { Sqlite.seError = e })
|
2022-10-18 19:47:20 +00:00
|
|
|
| e == Sqlite.ErrorBusy || e == Sqlite.ErrorIO -> do
|
|
|
|
when (e == Sqlite.ErrorIO) $
|
|
|
|
Sqlite.close conn
|
2018-10-30 22:03:03 +00:00
|
|
|
briefdelay
|
2022-10-18 19:47:20 +00:00
|
|
|
retryHelper "open" ex maxretries db retries ic $
|
|
|
|
if e == Sqlite.ErrorIO
|
|
|
|
then opensettle
|
|
|
|
else settle conn
|
|
|
|
| otherwise -> rethrow $ errmsg "while opening database connection" ex
|
2015-02-22 18:08:26 +00:00
|
|
|
|
|
|
|
-- This should succeed for any table.
|
|
|
|
nullselect = T.pack $ "SELECT null from " ++ tablename ++ " limit 1"
|
2018-10-30 22:03:03 +00:00
|
|
|
|
|
|
|
briefdelay = threadDelay 1000 -- 1/1000th second
|
2022-10-18 19:47:20 +00:00
|
|
|
|
|
|
|
maxretries = 30000 :: Int -- 30 seconds of briefdelays
|
|
|
|
|
|
|
|
rethrow = throwIO . userError
|
|
|
|
|
|
|
|
errmsg msg e = show e ++ "(" ++ msg ++ ")"
|
2019-09-26 16:24:03 +00:00
|
|
|
|
|
|
|
-- Like withSqlConn, but more robust.
|
|
|
|
withSqlConnRobustly
|
2019-10-17 15:58:31 +00:00
|
|
|
:: (MonadUnliftIO m
|
2021-04-01 16:19:47 +00:00
|
|
|
, MonadLoggerIO m
|
2019-10-17 15:58:31 +00:00
|
|
|
, IsPersistBackend backend
|
|
|
|
, BaseBackend backend ~ SqlBackend
|
|
|
|
, BackendCompatible SqlBackend backend
|
|
|
|
)
|
2022-10-18 19:47:20 +00:00
|
|
|
=> RawFilePath
|
|
|
|
-> (LogFunc -> IO backend)
|
2019-10-17 15:58:31 +00:00
|
|
|
-> (backend -> m a)
|
|
|
|
-> m a
|
2022-10-18 19:47:20 +00:00
|
|
|
withSqlConnRobustly db open f = do
|
2021-04-01 16:19:47 +00:00
|
|
|
logFunc <- askLoggerIO
|
2019-09-26 16:24:03 +00:00
|
|
|
withRunInIO $ \run -> bracket
|
|
|
|
(open logFunc)
|
2022-10-18 19:47:20 +00:00
|
|
|
(closeRobustly db)
|
2019-09-26 16:24:03 +00:00
|
|
|
(run . f)
|
|
|
|
|
2022-10-18 19:47:20 +00:00
|
|
|
{- Sqlite can throw ErrorBusy while closing a database; this catches
|
|
|
|
- the exception and retries.
|
|
|
|
-
|
|
|
|
- Retries repeatedly for up to 60 seconds. Part that point, it continues
|
|
|
|
- retrying only if the database shows signs of being modified by another
|
|
|
|
- process at least once each 30 seconds.
|
|
|
|
-}
|
2019-09-26 16:24:03 +00:00
|
|
|
closeRobustly
|
2019-10-17 15:58:31 +00:00
|
|
|
:: (IsPersistBackend backend
|
|
|
|
, BaseBackend backend ~ SqlBackend
|
|
|
|
, BackendCompatible SqlBackend backend
|
|
|
|
)
|
2022-10-18 19:47:20 +00:00
|
|
|
=> RawFilePath
|
|
|
|
-> backend
|
2019-09-26 16:24:03 +00:00
|
|
|
-> IO ()
|
2022-10-18 19:47:20 +00:00
|
|
|
closeRobustly db conn = go maxretries emptyDatabaseInodeCache
|
2019-09-26 16:24:03 +00:00
|
|
|
where
|
2022-10-18 19:47:20 +00:00
|
|
|
go retries ic = do
|
2019-09-26 16:24:03 +00:00
|
|
|
r <- try $ close' conn
|
|
|
|
case r of
|
|
|
|
Right () -> return ()
|
|
|
|
Left ex@(Sqlite.SqliteException { Sqlite.seError = e })
|
|
|
|
| e == Sqlite.ErrorBusy -> do
|
2022-10-18 19:47:20 +00:00
|
|
|
threadDelay briefdelay
|
|
|
|
retryHelper "close" ex maxretries db retries ic go
|
|
|
|
| otherwise -> rethrow $ errmsg "while closing database connection" ex
|
|
|
|
|
|
|
|
briefdelay = 1000 -- 1/1000th second
|
|
|
|
|
|
|
|
maxretries = 30000 :: Int -- 30 seconds of briefdelays
|
2019-09-26 16:24:03 +00:00
|
|
|
|
2022-10-18 19:47:20 +00:00
|
|
|
rethrow = throwIO . userError
|
|
|
|
|
|
|
|
errmsg msg e = show e ++ "(" ++ msg ++ ")"
|
|
|
|
|
|
|
|
{- Retries a sqlite action repeatedly, but not forever. Detects situations
|
|
|
|
- when another git-annex process is suspended and has the database locked,
|
|
|
|
- and eventually gives up. The retries is the current number of retries
|
|
|
|
- that are left. The maxretries is how many retries to make each time
|
|
|
|
- the database is seen to have been modified by some other process.
|
|
|
|
-}
|
|
|
|
retryHelper
|
|
|
|
:: Show err
|
|
|
|
=> String
|
|
|
|
-> err
|
|
|
|
-> Int
|
|
|
|
-> RawFilePath
|
|
|
|
-> Int
|
|
|
|
-> DatabaseInodeCache
|
|
|
|
-> (Int -> DatabaseInodeCache -> IO a)
|
|
|
|
-> IO a
|
|
|
|
retryHelper action err maxretries db retries ic a = do
|
|
|
|
let retries' = retries - 1
|
|
|
|
if retries' < 1
|
|
|
|
then do
|
|
|
|
ic' <- getDatabaseInodeCache db
|
|
|
|
if isDatabaseModified ic ic'
|
|
|
|
then a maxretries ic'
|
|
|
|
else giveup (databaseAccessStalledMsg action db err)
|
|
|
|
else a retries' ic
|
|
|
|
|
|
|
|
databaseAccessStalledMsg :: Show err => String -> RawFilePath -> err -> String
|
|
|
|
databaseAccessStalledMsg action db err =
|
|
|
|
"Repeatedly unable to " ++ action ++ " sqlite database " ++ fromRawFilePath db
|
|
|
|
++ ": " ++ show err ++ ". "
|
|
|
|
++ "Perhaps another git-annex process is suspended and is "
|
|
|
|
++ "keeping this database locked?"
|
|
|
|
|
|
|
|
data DatabaseInodeCache = DatabaseInodeCache (Maybe InodeCache) (Maybe InodeCache)
|
|
|
|
|
|
|
|
emptyDatabaseInodeCache :: DatabaseInodeCache
|
|
|
|
emptyDatabaseInodeCache = DatabaseInodeCache Nothing Nothing
|
|
|
|
|
|
|
|
getDatabaseInodeCache :: RawFilePath -> IO DatabaseInodeCache
|
|
|
|
getDatabaseInodeCache db = DatabaseInodeCache
|
|
|
|
<$> genInodeCache db noTSDelta
|
|
|
|
<*> genInodeCache (db <> "-wal") noTSDelta
|
|
|
|
|
|
|
|
isDatabaseModified :: DatabaseInodeCache -> DatabaseInodeCache -> Bool
|
|
|
|
isDatabaseModified (DatabaseInodeCache a1 b1) (DatabaseInodeCache a2 b2) =
|
|
|
|
ismodified a1 a2 || ismodified b1 b2
|
|
|
|
where
|
|
|
|
ismodified (Just a) (Just b) = not (compareStrong a b)
|
|
|
|
ismodified Nothing Nothing = False
|
|
|
|
ismodified _ _ = True
|
2023-02-23 19:28:22 +00:00
|
|
|
|
|
|
|
takeMVarSafe :: MVar a -> IO (Either BlockedIndefinitelyOnMVar a)
|
|
|
|
takeMVarSafe = try . takeMVar
|