@@ -22,15 +22,14 @@ module Database.LSMTree.Internal.Snapshot (
22
22
-- * Opening from levels snapshot format
23
23
, fromSnapLevels
24
24
-- * Hard links
25
- , HardLinkDurable (.. )
26
25
, hardLinkRunFiles
27
26
) where
28
27
29
28
import Control.ActionRegistry
30
29
import Control.Concurrent.Class.MonadMVar.Strict
31
30
import Control.Concurrent.Class.MonadSTM (MonadSTM )
32
31
import Control.DeepSeq (NFData (.. ))
33
- import Control.Monad (void , when )
32
+ import Control.Monad (void )
34
33
import Control.Monad.Class.MonadST (MonadST )
35
34
import Control.Monad.Class.MonadThrow (MonadMask )
36
35
import Control.Monad.Primitive (PrimMonad )
@@ -271,13 +270,13 @@ snapshotWriteBuffer reg hfs hbio activeUc snapUc activeDir snapDir wb wbb = do
271
270
-- Hard link the write buffer and write buffer blobs to the snapshot directory.
272
271
snapWriteBufferNumber <- uniqueToRunNumber <$> incrUniqCounter snapUc
273
272
let snapWriteBufferPaths = WriteBufferFsPaths (getNamedSnapshotDir snapDir) snapWriteBufferNumber
274
- hardLink reg hfs hbio HardLinkDurable
273
+ hardLink reg hfs hbio
275
274
(writeBufferKOpsPath activeWriteBufferPaths)
276
275
(writeBufferKOpsPath snapWriteBufferPaths)
277
- hardLink reg hfs hbio HardLinkDurable
276
+ hardLink reg hfs hbio
278
277
(writeBufferBlobPath activeWriteBufferPaths)
279
278
(writeBufferBlobPath snapWriteBufferPaths)
280
- hardLink reg hfs hbio HardLinkDurable
279
+ hardLink reg hfs hbio
281
280
(writeBufferChecksumsPath activeWriteBufferPaths)
282
281
(writeBufferChecksumsPath snapWriteBufferPaths)
283
282
pure snapWriteBufferPaths
@@ -334,36 +333,30 @@ openWriteBuffer reg resolve hfs hbio uc activeDir snapWriteBufferPaths = do
334
333
335
334
{-# SPECIALISE snapshotRuns ::
336
335
ActionRegistry IO
337
- -> HasBlockIO IO h
338
336
-> UniqCounter IO
339
337
-> NamedSnapshotDir
340
338
-> SnapLevels (Ref (Run IO h))
341
339
-> IO (SnapLevels RunNumber) #-}
342
340
-- | @'snapshotRuns' _ _ snapUc targetDir levels@ creates hard links for all run
343
341
-- files associated with the runs in @levels@, and puts the new directory
344
342
-- entries in the @targetDir@ directory. The entries are renamed using @snapUc@.
345
- -- The hard links and the @targetDir@ are made durable on disk.
346
343
snapshotRuns ::
347
344
(MonadMask m , PrimMonad m )
348
345
=> ActionRegistry m
349
- -> HasBlockIO m h
350
346
-> UniqCounter m
351
347
-> NamedSnapshotDir
352
348
-> SnapLevels (Ref (Run m h ))
353
349
-> m (SnapLevels RunNumber )
354
- snapshotRuns reg hbio0 snapUc (NamedSnapshotDir targetDir) levels = do
355
- levels' <-
356
- for levels $ \ run@ (DeRef Run. Run {
357
- Run. runHasFS = hfs,
358
- Run. runHasBlockIO = hbio
359
- }) -> do
360
- rn <- uniqueToRunNumber <$> incrUniqCounter snapUc
361
- let sourcePaths = Run. runFsPaths run
362
- let targetPaths = sourcePaths { runDir = targetDir , runNumber = rn}
363
- hardLinkRunFiles reg hfs hbio HardLinkDurable sourcePaths targetPaths
364
- pure (runNumber targetPaths)
365
- FS. synchroniseDirectory hbio0 targetDir
366
- pure levels'
350
+ snapshotRuns reg snapUc (NamedSnapshotDir targetDir) levels = do
351
+ for levels $ \ run@ (DeRef Run. Run {
352
+ Run. runHasFS = hfs,
353
+ Run. runHasBlockIO = hbio
354
+ }) -> do
355
+ rn <- uniqueToRunNumber <$> incrUniqCounter snapUc
356
+ let sourcePaths = Run. runFsPaths run
357
+ let targetPaths = sourcePaths { runDir = targetDir , runNumber = rn}
358
+ hardLinkRunFiles reg hfs hbio sourcePaths targetPaths
359
+ pure (runNumber targetPaths)
367
360
368
361
{-# SPECIALISE openRuns ::
369
362
ActionRegistry IO
@@ -404,7 +397,7 @@ openRuns
404
397
let sourcePaths = RunFsPaths sourceDir runNum
405
398
runNum' <- uniqueToRunNumber <$> incrUniqCounter uc
406
399
let targetPaths = RunFsPaths targetDir runNum'
407
- hardLinkRunFiles reg hfs hbio NoHardLinkDurable sourcePaths targetPaths
400
+ hardLinkRunFiles reg hfs hbio sourcePaths targetPaths
408
401
409
402
withRollback reg
410
403
(Run. openFromDisk hfs hbio caching targetPaths)
@@ -490,64 +483,53 @@ fromSnapLevels reg hfs hbio conf@TableConfig{..} uc resolve dir (SnapLevels leve
490
483
Hard links
491
484
-------------------------------------------------------------------------------}
492
485
493
- data HardLinkDurable = HardLinkDurable | NoHardLinkDurable
494
- deriving stock Eq
495
-
496
486
{-# SPECIALISE hardLinkRunFiles ::
497
487
ActionRegistry IO
498
488
-> HasFS IO h
499
489
-> HasBlockIO IO h
500
- -> HardLinkDurable
501
490
-> RunFsPaths
502
491
-> RunFsPaths
503
492
-> IO () #-}
504
- -- | @'hardLinkRunFiles' _ _ _ dur sourcePaths targetPaths@ creates a hard link
505
- -- for each @sourcePaths@ path using the corresponding @targetPaths@ path as the
506
- -- name for the new directory entry. If @dur == HardLinkDurabl@, the links will
507
- -- also be made durable on disk.
493
+ -- | @'hardLinkRunFiles' _ _ _ sourcePaths targetPaths@ creates a hard link for
494
+ -- each @sourcePaths@ path using the corresponding @targetPaths@ path as the
495
+ -- name for the new directory entry.
508
496
hardLinkRunFiles ::
509
497
(MonadMask m , PrimMonad m )
510
498
=> ActionRegistry m
511
499
-> HasFS m h
512
500
-> HasBlockIO m h
513
- -> HardLinkDurable
514
501
-> RunFsPaths
515
502
-> RunFsPaths
516
503
-> m ()
517
- hardLinkRunFiles reg hfs hbio dur sourceRunFsPaths targetRunFsPaths = do
504
+ hardLinkRunFiles reg hfs hbio sourceRunFsPaths targetRunFsPaths = do
518
505
let sourcePaths = pathsForRunFiles sourceRunFsPaths
519
506
targetPaths = pathsForRunFiles targetRunFsPaths
520
- sequenceA_ (hardLink reg hfs hbio dur <$> sourcePaths <*> targetPaths)
521
- hardLink reg hfs hbio dur (runChecksumsPath sourceRunFsPaths) (runChecksumsPath targetRunFsPaths)
507
+ sequenceA_ (hardLink reg hfs hbio <$> sourcePaths <*> targetPaths)
508
+ hardLink reg hfs hbio (runChecksumsPath sourceRunFsPaths) (runChecksumsPath targetRunFsPaths)
522
509
523
510
{-# SPECIALISE
524
511
hardLink ::
525
512
ActionRegistry IO
526
513
-> HasFS IO h
527
514
-> HasBlockIO IO h
528
- -> HardLinkDurable
529
515
-> FS.FsPath
530
516
-> FS.FsPath
531
517
-> IO ()
532
518
#-}
533
- -- | @'hardLink' reg hfs hbio dur sourcePath targetPath@ creates a hard link
534
- -- from @sourcePath@ to @targetPath@.
519
+ -- | @'hardLink' reg hfs hbio sourcePath targetPath@ creates a hard link from
520
+ -- @sourcePath@ to @targetPath@.
535
521
hardLink ::
536
522
(MonadMask m , PrimMonad m )
537
523
=> ActionRegistry m
538
524
-> HasFS m h
539
525
-> HasBlockIO m h
540
- -> HardLinkDurable
541
526
-> FS. FsPath
542
527
-> FS. FsPath
543
528
-> m ()
544
- hardLink reg hfs hbio dur sourcePath targetPath = do
529
+ hardLink reg hfs hbio sourcePath targetPath = do
545
530
withRollback_ reg
546
531
(FS. createHardLink hbio sourcePath targetPath)
547
532
(FS. removeFile hfs targetPath)
548
- when (dur == HardLinkDurable ) $
549
- FS. synchroniseFile hfs hbio targetPath
550
-
551
533
552
534
{- ------------------------------------------------------------------------------
553
535
Copy file
0 commit comments