Copyright | © 2018-2020 IOHK |
---|---|
License | Apache-2.0 |
Safe Haskell | None |
Language | Haskell2010 |
A function to wait until a suitable time to delete a SQLite database file, and a function to delete a SQLite database file, which isn't as straightforward as it sounds.
Synopsis
- deleteSqliteDatabase :: Tracer IO DeleteSqliteDatabaseLog -> FilePath -> IO ()
- deleteSqliteDatabase' :: Tracer IO DeleteSqliteDatabaseLog -> RetryPolicy -> FilePath -> IO ()
- deleteSqliteDatabaseRetryPolicy :: RetryPolicy
- data DeleteSqliteDatabaseLog
- data RefCount ix
- newRefCount :: Ord ix => IO ( RefCount ix)
- withRef :: Ord ix => RefCount ix -> ix -> IO a -> IO a
- waitForFree :: Ord ix => Tracer IO ( Maybe Int ) -> RefCount ix -> ix -> ( Int -> IO a) -> IO a
- waitForFree' :: Ord ix => Tracer IO ( Maybe Int ) -> RetryPolicy -> RefCount ix -> ix -> ( Int -> IO a) -> IO a
- waitForFreeRetryPolicy :: RetryPolicy
Removing files with retry
deleteSqliteDatabase :: Tracer IO DeleteSqliteDatabaseLog -> FilePath -> IO () Source #
Remove a SQLite database file.
If
SQLite temporary files
are present
(
-wal
and
-shm
), we remove them as well. Normally, they would be removed
when the SQLite connection is closed. But we attempt to remove them anyway,
in case cardano-wallet was unable to close the SQLite connection.
Additionally, on Windows, the deletion operations will be retried for a short time if they fail. The reason for this is that a FileDelete command just marks a file for deletion. The file is really only removed when the last handle to the file is closed. Unfortunately there are a lot of system services that can have a file temporarily opened using a shared read-only lock, such as the built in AV and search indexer.
We can't really guarantee that these are all off, so what we can do is whenever after an rm the file still exists to try again and wait a bit.
See https://github.com/haskell/directory/issues/96 for more information about this issue.
deleteSqliteDatabase' :: Tracer IO DeleteSqliteDatabaseLog -> RetryPolicy -> FilePath -> IO () Source #
A variant of
deleteSqliteDatabase
where the caller can specify the
RetryPolicy
.
deleteSqliteDatabaseRetryPolicy :: RetryPolicy Source #
Recommended retry policy for
deleteSqliteDatabase
.
data DeleteSqliteDatabaseLog Source #
Log messages that may arise from
deleteSqliteDatabase
.
Instances
Ref-counting open databases
withRef :: Ord ix => RefCount ix -> ix -> IO a -> IO a Source #
Acquire a reference to the given identifier, perform the given action, then
release the reference. Multiple
withRef
calls can take references at the
same time.
:: Ord ix | |
=> Tracer IO ( Maybe Int ) |
Logging of current number of references |
-> RefCount ix |
Mutable variable containing reference counts |
-> ix |
Identifier |
-> ( Int -> IO a) |
Action to run, passed number of references in use |
-> IO a |
Attempt to wait until all
withRef
calls for the given identifier have
completed, then perform an action.
This will block for up to 2 minutes before running the action. The action is
passed the reference count, which should be
0
under normal conditions.
No new references can be taken using
withRef
while the action is running.
:: Ord ix | |
=> Tracer IO ( Maybe Int ) |
Logging of current number of references |
-> RetryPolicy |
How and when to poll the
|
-> RefCount ix |
Mutable variable containing reference counts |
-> ix |
Identifier |
-> ( Int -> IO a) |
Action to run, passed number of references in use |
-> IO a |
A variant of
waitForFree
where the caller can specify the
RetryPolicy
.
waitForFreeRetryPolicy :: RetryPolicy Source #
Recommended retry schedule for polling the
RefCount
. It will poll for up
to 2 minutes.