Safe Haskell | None |
---|---|
Language | Haskell2010 |
Special file we store in the DB dir to avoid unintended deletions
Synopsis
- data DbMarkerError
- checkDbMarker :: forall m h. MonadThrow m => HasFS m h -> MountPoint -> NetworkMagic -> m ( Either DbMarkerError ())
- dbMarkerContents :: NetworkMagic -> ByteString
- dbMarkerFile :: Text
- dbMarkerParse :: Monad m => FilePath -> ByteString -> ExceptT DbMarkerError m NetworkMagic
Documentation
data DbMarkerError Source #
NetworkMagicMismatch |
There was a
|
|
|
NoDbMarkerAndNotEmpty FilePath |
The full path to the
|
CorruptDbMarker FilePath |
The full path to the
|
Instances
Eq DbMarkerError Source # | |
Defined in Ouroboros.Consensus.Node.DbMarker (==) :: DbMarkerError -> DbMarkerError -> Bool Source # (/=) :: DbMarkerError -> DbMarkerError -> Bool Source # |
|
Show DbMarkerError Source # | |
Defined in Ouroboros.Consensus.Node.DbMarker |
|
Exception DbMarkerError Source # | |
Defined in Ouroboros.Consensus.Node.DbMarker |
:: forall m h. MonadThrow m | |
=> HasFS m h | |
-> MountPoint |
Database directory. Should be the mount point of the
|
-> NetworkMagic | |
-> m ( Either DbMarkerError ()) |
Check database marker
The database folder will contain folders for the ImmutableDB (
immutable
),
the VolatileDB (
volatile
), and the LedgerDB (
ledger
). All three
subdatabases can delete files from these folders, e.g., outdated files or
files that are deemed invalid.
For example, when starting a node that will connect to a testnet with a database folder containing mainnet blocks, these blocks will be deemed invalid and will be deleted. This would throw away a perfectly good chain, possibly consisting of gigabytes of data that will have to be synched again.
To protect us from unwanted deletion of valid files, we first check whether
we have been given the path to the right database folder. We do this by
reading the
NetworkMagic
of the net from a file stored in the root of
the database folder. This file's name is defined in
dbMarkerFile
.
-
If the
NetworkMagic
from the file matches that of the net, we have the right database folder. -
If not, we are opening the wrong database folder and abort by throwing a
DbMarkerError
. -
If there is no such file and the folder is empty, we create it and store
the net's
NetworkMagic
in it. -
If there is no such file, but the folder is not empty, we throw a
DbMarkerError
, because we have likely been given the wrong path, maybe to a folder containing user or system files. This includes the case that thedbMarkerFile
has been deleted. -
If there is such a
dbMarkerFile
, but it could not be read or its contents could not be parsed, we also throw aDbMarkerError
.
Note that an
FsError
can also be thrown.
For the benefit of testing only
dbMarkerFile :: Text Source #
For legacy reasons it was using
ProtocolMagicId
not
NetworkMagic
which are really the same thing.
dbMarkerParse :: Monad m => FilePath -> ByteString -> ExceptT DbMarkerError m NetworkMagic Source #
Parse contents of the DB marker file
Must be inverse to
dbMarkerContents