Skip to content

Commit cdab159

Browse files
committed
fix database debug mode and docs
1 parent 0376699 commit cdab159

File tree

67 files changed

+283
-428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+283
-428
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Revision history for cardano-db-sync
22

3+
## 13.7.0.0
4+
5+
### Summary
6+
- Complete migration from Persistent ORM to Hasql for direct PostgreSQL access.
7+
8+
### Performance Improvements
9+
- 3-4x faster epoch processing: ~30min → ~8min per epoch
10+
- Improved cache efficiency: Stake address hit rates increased from 57-79% to 89-99%
11+
- Reduced memory overhead: Eliminated ORM abstraction layer
12+
13+
### Compatibility
14+
- PostgreSQL schema remains unchanged
15+
- Existing database instances compatible without migration
16+
317
## 13.6.0.5
418
- Fix offchain data so it supports files up to 3MB [#1928]
519
- Upgrade to PostgreSQL 17

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway/Scenarios.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#if __GLASGOW_HASKELL__ >= 908
77
{-# OPTIONS_GHC -Wno-x-partial #-}
8+
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
9+
{-# HLINT ignore "Use zipWith" #-}
810
#endif
911

1012
module Cardano.Mock.Forging.Tx.Conway.Scenarios (

cardano-chain-gen/test/Test/Cardano/Db/Mock/UnifiedApi.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import qualified Cardano.Mock.Forging.Tx.Conway.Scenarios as Conway
3333
import Cardano.Mock.Forging.Types
3434
import Cardano.Slotting.Slot (SlotNo (..))
3535
import Control.Concurrent.Class.MonadSTM.Strict (atomically)
36-
import Control.Monad (forM, replicateM)
36+
import Control.Monad (replicateM)
3737
import Data.Word (Word64)
3838
import Ouroboros.Consensus.Cardano.Block (
3939
BabbageEra,
@@ -63,7 +63,7 @@ forgeNextSkipSlotsFindLeaderAndSubmit interpreter mockServer skipSlots txs' = do
6363

6464
forgeAndSubmitBlocks :: Interpreter -> ServerHandle IO CardanoBlock -> Int -> IO [CardanoBlock]
6565
forgeAndSubmitBlocks interpreter mockServer blocksToCreate =
66-
forM [1 .. blocksToCreate] $ \_ -> forgeNextFindLeaderAndSubmit interpreter mockServer []
66+
replicateM blocksToCreate (forgeNextFindLeaderAndSubmit interpreter mockServer [])
6767

6868
withAlonzoFindLeaderAndSubmit ::
6969
Interpreter ->

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Config.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ insertConfig = do
3434
, sioPoolStats = PoolStatsConfig False
3535
, sioJsonType = JsonTypeDisable
3636
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
37-
, sioDbDebug = False
3837
}
3938

4039
dncInsertOptions cfg @?= expected

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/JsonbInSchema.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE NumericUnderscores #-}
21
{-# LANGUAGE OverloadedStrings #-}
32

43
module Test.Cardano.Db.Mock.Unit.Conway.Config.JsonbInSchema (

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ insertConfig = do
104104
, sioPoolStats = PoolStatsConfig False
105105
, sioJsonType = JsonTypeDisable
106106
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
107-
, sioDbDebug = False
108107
}
109108

110109
dncInsertOptions cfg @?= expected

cardano-db-sync/app/http-get-json-metadata.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{-# LANGUAGE LambdaCase #-}
22
{-# LANGUAGE OverloadedStrings #-}
3+
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
4+
5+
{-# HLINT ignore "Avoid restricted alias" #-}
36

47
import Cardano.Db (PoolMetaHash (..), PoolUrl (..), VoteMetaHash (..), VoteUrl (..))
58
import qualified Cardano.Db as DB

cardano-db-sync/src/Cardano/DbSync.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ runSyncNode metricsSetters trce iomgr dbConnSetting runDelayedMigrationFnc syncN
241241
threadChannels <- liftIO newThreadChannels
242242
liftIO $
243243
race_
244-
(runDbThread syncEnv metricsSetters threadChannels) -- Main App thread
244+
-- We split the main thread into two parts to allow for graceful shutdown of the main App db thread.
245+
(runDbThread syncEnv metricsSetters threadChannels)
245246
( mapConcurrently_
246247
id
247-
[ -- Non-critical threads
248-
runSyncNodeClient metricsSetters syncEnv iomgr trce threadChannels (enpSocketPath syncNodeParams)
248+
[ runSyncNodeClient metricsSetters syncEnv iomgr trce threadChannels (enpSocketPath syncNodeParams)
249249
, runFetchOffChainPoolThread syncEnv syncNodeConfigFromFile
250250
, runFetchOffChainVoteThread syncEnv syncNodeConfigFromFile
251251
, runLedgerStateWriteThread (getTrace syncEnv) (envLedgerEnv syncEnv)

cardano-db-sync/src/Cardano/DbSync/Api.hs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ module Cardano.DbSync.Api (
5050
where
5151

5252
import Control.Concurrent.Class.MonadSTM.Strict (
53+
StrictTVar,
5354
newTBQueueIO,
5455
newTVarIO,
5556
readTVar,
5657
readTVarIO,
57-
writeTVar, StrictTVar,
58+
writeTVar,
5859
)
5960
import Control.Monad.Trans.Maybe (MaybeT (..))
6061
import qualified Data.Strict.Maybe as Strict
@@ -79,7 +80,7 @@ import qualified Ouroboros.Network.Point as Point
7980

8081
import qualified Cardano.Db as DB
8182
import Cardano.DbSync.Api.Types
82-
import Cardano.DbSync.Cache.Types (CacheCapacity (..), newEmptyCache, useNoCache, initCacheStatistics)
83+
import Cardano.DbSync.Cache.Types (CacheCapacity (..), initCacheStatistics, newEmptyCache, useNoCache)
8384
import Cardano.DbSync.Config.Cardano
8485
import Cardano.DbSync.Config.Shelley
8586
import Cardano.DbSync.Config.Types
@@ -445,21 +446,24 @@ mkSyncEnv trce dbEnv syncOptions protoInfo nw nwMagic systemStart syncNodeConfig
445446
initEpochStatistics :: MonadIO m => m (StrictTVar IO EpochStatistics)
446447
initEpochStatistics = do
447448
curTime <- liftIO getCurrentTime
448-
liftIO $ newTVarIO $ EpochStatistics
449-
{ elsStartTime = curTime
450-
, elsCaches = initCacheStatistics
451-
, elsUnicodeNull = Map.empty
452-
}
449+
liftIO $
450+
newTVarIO $
451+
EpochStatistics
452+
{ elsStartTime = curTime
453+
, elsCaches = initCacheStatistics
454+
, elsUnicodeNull = Map.empty
455+
}
453456

454457
resetEpochStatistics :: MonadIO m => SyncEnv -> m ()
455458
resetEpochStatistics syncEnv = liftIO $ do
456-
curTime <- getCurrentTime
457-
let newEpochStatsValue = EpochStatistics
458-
{ elsStartTime = curTime
459-
, elsCaches = initCacheStatistics
460-
, elsUnicodeNull = Map.empty
461-
}
462-
atomically $ writeTVar (envEpochStatistics syncEnv) newEpochStatsValue
459+
curTime <- getCurrentTime
460+
let newEpochStatsValue =
461+
EpochStatistics
462+
{ elsStartTime = curTime
463+
, elsCaches = initCacheStatistics
464+
, elsUnicodeNull = Map.empty
465+
}
466+
atomically $ writeTVar (envEpochStatistics syncEnv) newEpochStatsValue
463467

464468
-- | 'True' is for in memory points and 'False' for on disk
465469
getLatestPoints :: SyncEnv -> IO [(CardanoPoint, Bool)]

cardano-db-sync/src/Cardano/DbSync/Api/Types.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE GADTs #-}
2+
{-# LANGUAGE OverloadedStrings #-}
23
{-# LANGUAGE ScopedTypeVariables #-}
34
{-# LANGUAGE NoImplicitPrelude #-}
4-
{-# LANGUAGE OverloadedStrings #-}
55

66
module Cardano.DbSync.Api.Types (
77
SyncEnv (..),
@@ -11,24 +11,24 @@ module Cardano.DbSync.Api.Types (
1111
RunMigration,
1212
ConsistentLevel (..),
1313
CurrentEpochNo (..),
14-
UnicodeNullSource(..),
14+
UnicodeNullSource (..),
1515
EpochStatistics (..),
1616
formatUnicodeNullSource,
1717
) where
1818

1919
import Control.Concurrent.Class.MonadSTM.Strict (StrictTVar)
2020
import Control.Concurrent.Class.MonadSTM.Strict.TBQueue (StrictTBQueue)
21+
import qualified Data.Map.Strict as Map
2122
import qualified Data.Strict.Maybe as Strict
2223
import Data.Time.Clock (UTCTime)
2324
import Ouroboros.Consensus.BlockchainTime.WallClock.Types (SystemStart (..))
2425
import Ouroboros.Network.Magic (NetworkMagic (..))
25-
import qualified Data.Map.Strict as Map
2626

27-
import Cardano.Prelude (Bool, Eq, IO, Show, Word64, Ord, Text)
27+
import Cardano.Prelude (Bool, Eq, IO, Ord, Show, Text, Word64)
2828
import Cardano.Slotting.Slot (EpochNo (..))
2929

3030
import qualified Cardano.Db as DB
31-
import Cardano.DbSync.Cache.Types (CacheStatus, CacheStatistics)
31+
import Cardano.DbSync.Cache.Types (CacheStatistics, CacheStatus)
3232
import Cardano.DbSync.Config.Types (SyncNodeConfig)
3333
import Cardano.DbSync.Ledger.Types (HasLedgerEnv)
3434
import Cardano.DbSync.LocalStateQuery (NoLedgerEnv)
@@ -112,7 +112,6 @@ data UnicodeNullSource
112112
| PrepareTxMetadata
113113
deriving (Eq, Ord, Show)
114114

115-
116115
formatUnicodeNullSource :: UnicodeNullSource -> Text
117116
formatUnicodeNullSource source = case source of
118117
InsertDatum -> "insertDatum: Column 'value' in table 'datum'"

0 commit comments

Comments
 (0)