-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This table is mainly for sync time performance validation. Different machines are likley to have different results in this table. Closes: #621
- Loading branch information
Showing
9 changed files
with
174 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
module Cardano.DbSync.Era.Cardano.Insert | ||
( insertEpochSyncTime | ||
) where | ||
|
||
import qualified Cardano.Db as Db | ||
|
||
import Cardano.Prelude hiding (STM, atomically) | ||
|
||
import Cardano.Slotting.Slot (EpochNo (..)) | ||
|
||
import Cardano.Sync.Types (SyncState, renderSyncState) | ||
|
||
import Control.Monad.Class.MonadSTM.Strict (MonadSTM, StrictTVar, STM, atomically, readTVar, writeTVar) | ||
import Control.Monad.Trans.Control (MonadBaseControl) | ||
|
||
import Data.Time.Clock (UTCTime) | ||
import qualified Data.Time.Clock as Time | ||
|
||
import Database.Persist.Sql (SqlBackend) | ||
|
||
|
||
insertEpochSyncTime | ||
:: (MonadBaseControl IO m, MonadIO m) | ||
=> EpochNo -> SyncState -> StrictTVar IO (Maybe UTCTime) -> ReaderT SqlBackend m () | ||
insertEpochSyncTime epochNo syncState estvar = do | ||
now <- liftIO $ Time.getCurrentTime | ||
mlast <- liftIO . atomically $ swapTVar estvar (Just now) | ||
let mdiff = maybe Nothing (Just . Time.diffUTCTime now) mlast | ||
void . Db.insertEpochSyncTime $ | ||
Db.EpochSyncTime | ||
{ Db.epochSyncTimeNo = unEpochNo epochNo | ||
, Db.epochSyncTimeSeconds = realToFrac <$> mdiff | ||
, Db.epochSyncTimeState = renderSyncState syncState | ||
} | ||
|
||
|
||
swapTVar :: MonadSTM m => StrictTVar m a -> a -> STM m a | ||
swapTVar tvar !new = do | ||
old <- readTVar tvar | ||
writeTVar tvar new | ||
pure old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- Hand written migration to create the custom types with 'DOMAIN' statements. | ||
|
||
CREATE FUNCTION migrate() RETURNS void AS $$ | ||
|
||
DECLARE | ||
next_version int; | ||
|
||
BEGIN | ||
SELECT stage_one + 1 INTO next_version FROM "schema_version"; | ||
IF next_version = 6 THEN | ||
|
||
-- Would normally put this inside an "EXECUTE" statement, but that does not work for some | ||
-- reason and this does. | ||
CREATE TYPE syncstatetype AS ENUM ('lagging', 'following'); | ||
|
||
UPDATE "schema_version" SET stage_one = next_version; | ||
RAISE NOTICE 'DB has been migrated to stage_one version %', next_version; | ||
END IF; | ||
END; | ||
|
||
$$ LANGUAGE plpgsql; | ||
|
||
SELECT migrate(); | ||
|
||
DROP FUNCTION migrate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- Persistent generated migration. | ||
|
||
CREATE FUNCTION migrate() RETURNS void AS $$ | ||
DECLARE | ||
next_version int ; | ||
BEGIN | ||
SELECT stage_two + 1 INTO next_version FROM schema_version ; | ||
IF next_version = 3 THEN | ||
EXECUTE 'CREATe TABLE "epoch_sync_time"("id" SERIAL8 PRIMARY KEY UNIQUE,"no" INT8 NOT NULL,"seconds" DOUBLE PRECISION NULL,"state" syncstatetype NOT NULL)' ; | ||
EXECUTE 'ALTER TABLE "epoch_sync_time" ADD CONSTRAINT "unique_epoch_sync_time" UNIQUE("no")' ; | ||
-- Hand written SQL statements can be added here. | ||
UPDATE schema_version SET stage_two = next_version ; | ||
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ; | ||
END IF ; | ||
END ; | ||
$$ LANGUAGE plpgsql ; | ||
|
||
SELECT migrate() ; | ||
|
||
DROP FUNCTION migrate() ; |