Skip to content

Commit ddaf374

Browse files
committed
Allow for different DB paths for immutable and volatile data
1 parent 9b792c3 commit ddaf374

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Run.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ analyse DBAnalyserConfig{analysis, confLimit, dbDir, selectDB, validation, verbo
7171
chunkInfo
7272
(const True)
7373
(Node.stdMkChainDbHasFS dbDir)
74+
(Node.stdMkChainDbHasFS dbDir)
7475
$ defaultArgs
7576
immutableDbArgs = ChainDB.cdbImmDbArgs chainDbArgs
7677
ledgerDbFS = lgrHasFS $ ChainDB.cdbLgrDbArgs chainDbArgs

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBSynthesizer/Run.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ synthesize genTxs DBSynthesizerConfig{confOptions, confShelleyGenesis, confDbDir
131131
chunkInfo
132132
(const True)
133133
(Node.stdMkChainDbHasFS confDbDir)
134+
(Node.stdMkChainDbHasFS confDbDir)
134135
$ ChainDB.defaultArgs
135136

136137
forgers <- blockForging
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Breaking
2+
3+
- The `StdRunNodeArgs(srnDatabasePath)` argument becomes of type `NodeDatabasePaths`
4+
which will allow storing the immutable db (which doesn't need to be in a very
5+
performant device) somewhere different than the volatile data.

ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/Node.hs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module Ouroboros.Consensus.Node (
4242
, LastShutDownWasClean (..)
4343
, LowLevelRunNodeArgs (..)
4444
, MempoolCapacityBytesOverride (..)
45+
, NodeDatabasePaths (..)
4546
, NodeKernel (..)
4647
, NodeKernelArgs (..)
4748
, ProtocolInfo (..)
@@ -221,9 +222,13 @@ data LowLevelRunNodeArgs m addrNTN addrNTC versionDataNTN versionDataNTC blk
221222
-- | The " static " ChainDB arguments
222223
, llrnChainDbArgsDefaults :: Incomplete ChainDbArgs m blk
223224

224-
-- | File-system on which the directories for the different databases will
225+
-- | File-system on which the directory for the ImmutableDB will
225226
-- be created.
226-
, llrnMkHasFS :: ChainDB.RelativeMountPoint -> SomeHasFS m
227+
, llrnMkImmutableHasFS :: ChainDB.RelativeMountPoint -> SomeHasFS m
228+
229+
-- | File-system on which the directories for databases other than the ImmutableDB will
230+
-- be created.
231+
, llrnMkVolatileHasFS :: ChainDB.RelativeMountPoint -> SomeHasFS m
227232

228233
-- | Customise the 'ChainDbArgs'
229234
, llrnCustomiseChainDbArgs ::
@@ -285,6 +290,27 @@ data LowLevelRunNodeArgs m addrNTN addrNTC versionDataNTN versionDataNTC blk
285290
, llrnPublicPeerSelectionStateVar :: StrictSTM.StrictTVar m (Diffusion.PublicPeerSelectionState addrNTN)
286291
}
287292

293+
data NodeDatabasePaths =
294+
OnePathForAllDbs
295+
FilePath -- ^ Databases will be stored under this path, such that given a
296+
-- path @/foo@, databases will be in @/foo/{immutable,volatile,...}@.
297+
| MultipleDbPaths
298+
FilePath -- ^ Immutable path, usually pointing to a non-necessarily
299+
-- performant volume. ImmutableDB will be stored under this path,
300+
-- so given @/foo@, the ImmutableDB will be in @/foo/immutable@.
301+
FilePath -- ^ Non-immutable (volatile data) path, usually pointing to a
302+
-- performant volume. Databases other than the ImmutableDB will
303+
-- be stored under this path, so given @/bar@, it will contain
304+
-- @/bar/{volatile,ledger,...}@.
305+
306+
immutableDbPath :: NodeDatabasePaths -> FilePath
307+
immutableDbPath (OnePathForAllDbs f) = f
308+
immutableDbPath (MultipleDbPaths imm _) = imm
309+
310+
nonImmutableDbPath :: NodeDatabasePaths -> FilePath
311+
nonImmutableDbPath (OnePathForAllDbs f) = f
312+
nonImmutableDbPath (MultipleDbPaths _ vol) = vol
313+
288314
-- | Higher-level arguments that can determine the 'LowLevelRunNodeArgs' under
289315
-- some usual assumptions for realistic use cases such as in @cardano-node@.
290316
--
@@ -295,7 +321,7 @@ data StdRunNodeArgs m blk (p2p :: Diffusion.P2P) = StdRunNodeArgs
295321
, srnChainDbValidateOverride :: Bool
296322
-- ^ If @True@, validate the ChainDB on init no matter what
297323
, srnDiskPolicyArgs :: DiskPolicyArgs
298-
, srnDatabasePath :: FilePath
324+
, srnDatabasePath :: NodeDatabasePaths
299325
-- ^ Location of the DBs
300326
, srnDiffusionArguments :: Diffusion.Arguments
301327
IO
@@ -431,7 +457,8 @@ runWith RunNodeArgs{..} encAddrNtN decAddrNtN LowLevelRunNodeArgs{..} =
431457
inFuture
432458
cfg
433459
initLedger
434-
llrnMkHasFS
460+
llrnMkImmutableHasFS
461+
llrnMkVolatileHasFS
435462
llrnChainDbArgsDefaults
436463
( setLoEinChainDbArgs
437464
. maybeValidateAll
@@ -686,20 +713,24 @@ openChainDB ::
686713
-> ExtLedgerState blk
687714
-- ^ Initial ledger
688715
-> (ChainDB.RelativeMountPoint -> SomeHasFS m)
716+
-- ^ Immutable FS, see 'NodeDatabasePaths'
717+
-> (ChainDB.RelativeMountPoint -> SomeHasFS m)
718+
-- ^ Volatile FS, see 'NodeDatabasePaths'
689719
-> Incomplete ChainDbArgs m blk
690720
-- ^ A set of default arguments (possibly modified from 'defaultArgs')
691721
-> (Complete ChainDbArgs m blk -> Complete ChainDbArgs m blk)
692722
-- ^ Customise the 'ChainDbArgs'
693723
-> m (ChainDB m blk, Complete ChainDbArgs m blk)
694-
openChainDB registry inFuture cfg initLedger fs defArgs customiseArgs =
724+
openChainDB registry inFuture cfg initLedger fsImm fsVol defArgs customiseArgs =
695725
let args = customiseArgs $ ChainDB.completeChainDbArgs
696726
registry
697727
inFuture
698728
cfg
699729
initLedger
700730
(nodeImmutableDbChunkInfo (configStorage cfg))
701731
(nodeCheckIntegrity (configStorage cfg))
702-
fs
732+
fsImm
733+
fsVol
703734
defArgs
704735
in (,args) <$> ChainDB.openDB args
705736

@@ -876,7 +907,8 @@ stdLowLevelRunNodeArgsIO RunNodeArgs{ rnProtocolInfo
876907
, llrnCustomiseHardForkBlockchainTimeArgs = id
877908
, llrnGsmAntiThunderingHerd
878909
, llrnKeepAliveRng
879-
, llrnMkHasFS = stdMkChainDbHasFS srnDatabasePath
910+
, llrnMkImmutableHasFS = stdMkChainDbHasFS $ immutableDbPath srnDatabasePath
911+
, llrnMkVolatileHasFS = stdMkChainDbHasFS $ nonImmutableDbPath srnDatabasePath
880912
, llrnChainDbArgsDefaults = updateChainDbDefaults ChainDB.defaultArgs
881913
, llrnCustomiseChainDbArgs = id
882914
, llrnCustomiseNodeKernelArgs
@@ -910,7 +942,9 @@ stdLowLevelRunNodeArgsIO RunNodeArgs{ rnProtocolInfo
910942
snd
911943
(supportedNodeToClientVersions (Proxy @blk))
912944
, llrnWithCheckedDB =
913-
stdWithCheckedDB (Proxy @blk) srnTraceChainDB srnDatabasePath networkMagic
945+
-- 'stdWithCheckedDB' uses the FS just to check for the clean file.
946+
-- We put that one in the immutable path.
947+
stdWithCheckedDB (Proxy @blk) srnTraceChainDB (immutableDbPath srnDatabasePath) networkMagic
914948
, llrnMaxCaughtUpAge = secondsToNominalDiffTime $ 20 * 60 -- 20 min
915949
, llrnMaxClockSkew =
916950
InFuture.defaultClockSkew
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Breaking
2+
3+
- `completeChainDbArgs` now requires two file-systems. This allows to place the
4+
immutable data (which doesn't need to be stored in a very performant device)
5+
somewhere else than the volatile data.

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/Args.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ completeChainDbArgs ::
159159
-> (blk -> Bool)
160160
-- ^ Check integrity
161161
-> (RelativeMountPoint -> SomeHasFS m)
162+
-- ^ Immutable FS, see 'NodeDatabasePaths'
163+
-> (RelativeMountPoint -> SomeHasFS m)
164+
-- ^ Volatile FS, see 'NodeDatabasePaths'
162165
-> Incomplete ChainDbArgs m blk
163166
-- ^ A set of incomplete arguments, possibly modified wrt @defaultArgs@
164167
-> Complete ChainDbArgs m blk
@@ -169,31 +172,32 @@ completeChainDbArgs
169172
initLedger
170173
immChunkInfo
171174
checkIntegrity
172-
mkFS
175+
mkImmFS
176+
mkVolFS
173177
defArgs
174178
= defArgs {
175179
cdbImmDbArgs = (cdbImmDbArgs defArgs) {
176180
ImmutableDB.immChunkInfo
177181
, ImmutableDB.immCheckIntegrity = checkIntegrity
178182
, ImmutableDB.immRegistry = registry
179183
, ImmutableDB.immCodecConfig = configCodec cdbsTopLevelConfig
180-
, ImmutableDB.immHasFS = mkFS $ RelativeMountPoint "immutable"
184+
, ImmutableDB.immHasFS = mkImmFS $ RelativeMountPoint "immutable"
181185
}
182186
, cdbVolDbArgs = (cdbVolDbArgs defArgs) {
183-
VolatileDB.volHasFS = mkFS $ RelativeMountPoint "volatile"
187+
VolatileDB.volHasFS = mkVolFS $ RelativeMountPoint "volatile"
184188
, VolatileDB.volCheckIntegrity = checkIntegrity
185189
, VolatileDB.volCodecConfig = configCodec cdbsTopLevelConfig
186190
}
187191
, cdbLgrDbArgs = (cdbLgrDbArgs defArgs) {
188192
LedgerDB.lgrGenesis = pure initLedger
189-
, LedgerDB.lgrHasFS = mkFS $ RelativeMountPoint "ledger"
193+
, LedgerDB.lgrHasFS = mkVolFS $ RelativeMountPoint "ledger"
190194
, LedgerDB.lgrConfig = LedgerDB.configLedgerDb cdbsTopLevelConfig
191195
}
192196
, cdbsArgs = (cdbsArgs defArgs) {
193197
cdbsCheckInFuture
194198
, cdbsRegistry = registry
195199
, cdbsTopLevelConfig
196-
, cdbsHasFSGsmDB = mkFS $ RelativeMountPoint "gsm"
200+
, cdbsHasFSGsmDB = mkVolFS $ RelativeMountPoint "gsm"
197201
}
198202
}
199203

0 commit comments

Comments
 (0)