Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 808065a

Browse files
iohk-bors[bot]erikdkarknudeepfiredcoutts
committed
Merge #3920
3920: Karknu/rcd 43 mitigation r=jmitchell a=karknu ## Description Improvement that makes the network disconnect in RCD-43 less likely to happen. ## Linked issue <!--- Put here the relevant issue from YouTrack --> Co-authored-by: Erik de Castro Lopo <[email protected]> Co-authored-by: Karl Knutsson <[email protected]> Co-authored-by: Kosyrev Serge <[email protected]> Co-authored-by: Duncan Coutts <[email protected]>
2 parents 8b3fdd5 + e1bca52 commit 808065a

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

db/cardano-sl-db.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ library
141141
, ekg-core
142142
, ether >= 0.5
143143
, exceptions
144+
, extra
144145
, filepath
145146
, formatting
146147
, lens

db/src/Pos/DB/Block/Epoch.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import Data.Binary (decode, encode)
4747
import qualified Data.ByteString.Char8 as BS
4848
import qualified Data.ByteString.Lazy as LBS
4949
import Data.Either (partitionEithers)
50+
import Data.List.Extra (chunksOf)
5051
import Formatting (build, int, sformat, shown, (%))
5152
import System.Directory (removeFile)
5253
import System.FilePath ((</>))
@@ -363,7 +364,12 @@ consolidateOneEpoch ccp epochSlots = do
363364

364365
-- After the check point is written, delete old blunds for the epoch we have just
365366
-- consolidated.
366-
lift $ mapM_ deleteOldBlund sihs
367+
lift $ mapM_ deleter $ chunksOf 1000 sihs
368+
where
369+
deleter :: ConsolidateM ctx m => [SlotIndexHash] -> m ()
370+
deleter xs = do
371+
mapM_ deleteOldBlund xs
372+
sleepSeconds 2
367373

368374
deleteOldBlund :: ConsolidateM ctx m => SlotIndexHash -> m ()
369375
deleteOldBlund (SlotIndexHash _ hh) = do
@@ -389,16 +395,18 @@ consolidateEpochBlocks fpath xs = ExceptT $ do
389395
(liftIO . hClose)
390396
(\hdl -> do
391397
liftIO $ BS.hPutStr hdl epochFileHeader
392-
mapM (consolidate hdl) xs
398+
mapM (consolidate hdl) $ zip [0 .. ] xs
393399
)
394400
pure $ case partitionEithers ys of
395401
([], zs) -> Right $ epochIndexToOffset zs
396402
(e:_, _) -> Left e
397403
where
398404
consolidate
399405
:: ConsolidateM ctx m
400-
=> Handle -> SlotIndexHash -> m (Either ConsolidateError SlotIndexLength)
401-
consolidate hdl (SlotIndexHash lsi hh) = do
406+
=> Handle -> (Int, SlotIndexHash) -> m (Either ConsolidateError SlotIndexLength)
407+
consolidate hdl (indx, SlotIndexHash lsi hh) = do
408+
when (indx `mod` 1000 == 0) $
409+
sleepSeconds 2
402410
mblund <- getSerializedBlund hh
403411
case mblund of
404412
Nothing ->

db/src/Pos/DB/Rocks/Functions.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import qualified Database.RocksDB as Rocks
4141
import System.Directory (createDirectoryIfMissing, doesDirectoryExist,
4242
removeDirectoryRecursive)
4343
import System.FilePath (takeDirectory, (</>))
44+
import qualified System.Info (os)
4445

4546
import Pos.Binary.Class (Bi, serialize')
4647
import Pos.DB.BatchOp (rocksWriteBatch)
@@ -82,6 +83,7 @@ openNodeDBs recreate fp = do
8283
let gStatePath = fp </> "gState"
8384
let lrcPath = fp </> "lrc"
8485
let miscPath = fp </> "misc"
86+
8587
mapM_ ensureDirectoryExists
8688
[ blocksDir
8789
, _blockDataDir
@@ -91,6 +93,11 @@ openNodeDBs recreate fp = do
9193
, lrcPath
9294
, miscPath
9395
]
96+
97+
when (System.Info.os == "darwin") $
98+
-- Prevent indexing of blocks on OSX
99+
ensureEmptyFileExists (fp </> ".metadata_never_index")
100+
94101
_blockIndexDB <- openRocksDB blocksIndexPath
95102
_gStateDB <- openRocksDB gStatePath
96103
_lrcDB <- openRocksDB lrcPath
@@ -101,6 +108,9 @@ openNodeDBs recreate fp = do
101108
ensureDirectoryExists :: MonadIO m => FilePath -> m ()
102109
ensureDirectoryExists = liftIO . createDirectoryIfMissing True
103110

111+
ensureEmptyFileExists :: MonadIO m => FilePath -> m ()
112+
ensureEmptyFileExists file = liftIO $ withFile file AppendMode (\_ -> return ())
113+
104114
-- | Safely close all databases from 'NodeDBs'.
105115
closeNodeDBs :: MonadIO m => NodeDBs -> m ()
106116
closeNodeDBs NodeDBs {..} =

pkgs/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16188,6 +16188,7 @@ license = stdenv.lib.licenses.mit;
1618816188
, ekg-core
1618916189
, ether
1619016190
, exceptions
16191+
, extra
1619116192
, filepath
1619216193
, formatting
1619316194
, hedgehog
@@ -16241,6 +16242,7 @@ directory
1624116242
ekg-core
1624216243
ether
1624316244
exceptions
16245+
extra
1624416246
filepath
1624516247
formatting
1624616248
lens

0 commit comments

Comments
 (0)