cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.DB.Sqlite.Delete

Description

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

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.

data DeleteSqliteDatabaseLog Source #

Log messages that may arise from deleteSqliteDatabase .

Instances

Instances details
Eq DeleteSqliteDatabaseLog Source #
Instance details

Defined in Cardano.DB.Sqlite.Delete

Show DeleteSqliteDatabaseLog Source #
Instance details

Defined in Cardano.DB.Sqlite.Delete

Generic DeleteSqliteDatabaseLog Source #
Instance details

Defined in Cardano.DB.Sqlite.Delete

ToJSON DeleteSqliteDatabaseLog Source #
Instance details

Defined in Cardano.DB.Sqlite.Delete

ToText DeleteSqliteDatabaseLog Source #
Instance details

Defined in Cardano.DB.Sqlite.Delete

HasPrivacyAnnotation DeleteSqliteDatabaseLog Source #
Instance details

Defined in Cardano.DB.Sqlite.Delete

HasSeverityAnnotation DeleteSqliteDatabaseLog Source #
Instance details

Defined in Cardano.DB.Sqlite.Delete

type Rep DeleteSqliteDatabaseLog Source #
Instance details

Defined in Cardano.DB.Sqlite.Delete

Ref-counting open databases

data RefCount ix Source #

Mutable variable containing reference counts to IDs of type ix .

newRefCount :: Ord ix => IO ( RefCount ix) Source #

Construct a RefCount with zero references.

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.

waitForFree Source #

Arguments

:: 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.

waitForFree' Source #

Arguments

:: Ord ix
=> Tracer IO ( Maybe Int )

Logging of current number of references

-> RetryPolicy

How and when to poll the RefCount

-> 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.