mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
relocate 'ServerReplicas' and 'ResizePoolStrategy' types
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6448 GitOrigin-RevId: 2d317fd004db63e2830dfb8def92acb51bb576a0
This commit is contained in:
parent
3e3ebe9743
commit
1c745959b9
@ -747,6 +747,7 @@ library
|
||||
, Hasura.RQL.Types.ResultCustomization
|
||||
, Hasura.RQL.Types.Roles
|
||||
, Hasura.RQL.Types.Roles.Internal
|
||||
, Hasura.RQL.Types.ResizePool
|
||||
, Hasura.RQL.Types.ScheduledTrigger
|
||||
, Hasura.RQL.Types.SchemaCache
|
||||
, Hasura.RQL.Types.SchemaCache.AggregationPredicates
|
||||
|
@ -113,6 +113,7 @@ import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.Eventing.Backend
|
||||
import Hasura.RQL.Types.Metadata
|
||||
import Hasura.RQL.Types.Network
|
||||
import Hasura.RQL.Types.ResizePool
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.SchemaCache.Build
|
||||
import Hasura.RQL.Types.Source
|
||||
|
@ -12,8 +12,8 @@ import Hasura.Backends.BigQuery.Types qualified as BigQuery
|
||||
import Hasura.Base.Error
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.ResizePool (ServerReplicas)
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.Server.Types (ServerReplicas)
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
instance Backend 'BigQuery where
|
||||
|
@ -16,8 +16,8 @@ import Hasura.Incremental
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
import Hasura.RQL.Types.Backend (Backend (..), ComputedFieldReturnType, SupportedNamingCase (..), XDisable, XEnable)
|
||||
import Hasura.RQL.Types.ResizePool (ServerReplicas)
|
||||
import Hasura.SQL.Backend (BackendType (DataConnector))
|
||||
import Hasura.Server.Types (ServerReplicas)
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
-- | An alias for '()' indicating that a particular associated type has not yet
|
||||
|
@ -43,7 +43,7 @@ import Hasura.Base.Error
|
||||
import Hasura.Incremental (Cacheable (..))
|
||||
import Hasura.Metadata.DTO.Utils (fromEnvCodec)
|
||||
import Hasura.Prelude
|
||||
import Hasura.Server.Types (ResizePoolStrategy (..), ServerReplicas, getServerReplicasInt)
|
||||
import Hasura.RQL.Types.ResizePool (ResizePoolStrategy (..), ServerReplicas, getServerReplicasInt)
|
||||
|
||||
class MonadError QErr m => MonadMSSQLTx m where
|
||||
liftMSSQLTx :: MSTx.TxE QErr a -> m a
|
||||
|
@ -19,8 +19,8 @@ import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.HealthCheck
|
||||
import Hasura.RQL.Types.HealthCheckImplementation (HealthCheckImplementation (..))
|
||||
import Hasura.RQL.Types.ResizePool (ServerReplicas)
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.Server.Types (ServerReplicas)
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
instance Backend 'MSSQL where
|
||||
|
@ -11,8 +11,8 @@ import Hasura.Base.Error
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.DDL.Headers ()
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.ResizePool (ServerReplicas, getServerReplicasInt)
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.Server.Types (ServerReplicas, getServerReplicasInt)
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
instance Backend 'MySQL where
|
||||
|
@ -26,8 +26,8 @@ import Hasura.Backends.Postgres.SQL.Error
|
||||
import Hasura.Base.Error
|
||||
import Hasura.Incremental (Cacheable (..))
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.ResizePool (ResizePoolStrategy (..), ServerReplicas, getServerReplicasInt)
|
||||
import Hasura.SQL.Types (ExtensionsSchema)
|
||||
import Hasura.Server.Types (ResizePoolStrategy (..), ServerReplicas, getServerReplicasInt)
|
||||
|
||||
-- See Note [Existentially Quantified Types]
|
||||
type RunTx =
|
||||
|
@ -24,10 +24,10 @@ import Hasura.Base.ToErrorValue
|
||||
import Hasura.Incremental (Cacheable)
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.HealthCheckImplementation (HealthCheckImplementation)
|
||||
import Hasura.RQL.Types.ResizePool (ServerReplicas)
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.SQL.Tag
|
||||
import Hasura.SQL.Types
|
||||
import Hasura.Server.Types (ServerReplicas)
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
type Representable a = (Show a, Eq a, Hashable a, Cacheable a, NFData a)
|
||||
|
49
server/src-lib/Hasura/RQL/Types/ResizePool.hs
Normal file
49
server/src-lib/Hasura/RQL/Types/ResizePool.hs
Normal file
@ -0,0 +1,49 @@
|
||||
{-# LANGUAGE MagicHash #-}
|
||||
|
||||
-- | Types related to resizing a connection pool
|
||||
--
|
||||
-- Resize connection pools, on-demand, based on underlying server replicas
|
||||
--
|
||||
-- See @'resizeSourcePools' in Hasura.RQL.Types.Backend
|
||||
module Hasura.RQL.Types.ResizePool
|
||||
( ServerReplicas,
|
||||
ResizePoolStrategy (..),
|
||||
getServerReplicasInt,
|
||||
safeServerReplicas,
|
||||
|
||||
-- * exporting for tests
|
||||
unsafeServerReplicas,
|
||||
oneServerReplica,
|
||||
)
|
||||
where
|
||||
|
||||
import GHC.Exts (Int (I#), Word (W#), int2Word#)
|
||||
import Hasura.Prelude
|
||||
|
||||
-- | Number of server instances. A wrapper over @'Word' type, a non-negative integer
|
||||
-- with the same size as @'Int'. Useful for resize a connection pool.
|
||||
newtype ServerReplicas = ServerReplicas {serverReplicaNumber :: Word}
|
||||
deriving (Show, Eq)
|
||||
|
||||
unsafeServerReplicas :: Word -> ServerReplicas
|
||||
unsafeServerReplicas = ServerReplicas
|
||||
|
||||
oneServerReplica :: ServerReplicas
|
||||
oneServerReplica = ServerReplicas 1
|
||||
|
||||
-- | Safely build @'ServerReplicas' from non-negative and non-zero @'Int' value.
|
||||
safeServerReplicas :: Int -> Either Text ServerReplicas
|
||||
safeServerReplicas i@(I# i#)
|
||||
| i <= 0 = Left $ "Expecting a non-zero and non-negative integer for ServerReplicas but got " <> tshow i
|
||||
| otherwise = Right $ ServerReplicas $ W# (int2Word# i#)
|
||||
|
||||
-- | Get server replic count in @'Int'
|
||||
getServerReplicasInt :: ServerReplicas -> Int
|
||||
getServerReplicasInt (ServerReplicas replicaNumber) = fromIntegral replicaNumber
|
||||
|
||||
-- | A strategy for resizing a pool
|
||||
data ResizePoolStrategy
|
||||
= -- | Never resize the pool
|
||||
NeverResizePool
|
||||
| -- | Resize the pool by using provided total maximum connections
|
||||
ResizePool Int
|
@ -1,5 +1,3 @@
|
||||
{-# LANGUAGE MagicHash #-}
|
||||
|
||||
module Hasura.Server.Types
|
||||
( ExperimentalFeature (..),
|
||||
InstanceId (..),
|
||||
@ -17,20 +15,12 @@ module Hasura.Server.Types
|
||||
ServerConfigCtx (..),
|
||||
HasServerConfigCtx (..),
|
||||
getRequestId,
|
||||
ServerReplicas,
|
||||
-- exported only for tests
|
||||
unsafeServerReplicas,
|
||||
oneServerReplica,
|
||||
getServerReplicasInt,
|
||||
safeServerReplicas,
|
||||
ResizePoolStrategy (..),
|
||||
)
|
||||
where
|
||||
|
||||
import Data.Aeson
|
||||
import Data.HashSet qualified as Set
|
||||
import Database.PG.Query qualified as PG
|
||||
import GHC.Exts (Int (I#), Word (W#), int2Word#)
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Options qualified as Options
|
||||
import Hasura.Prelude
|
||||
@ -157,31 +147,3 @@ instance HasServerConfigCtx m => HasServerConfigCtx (ExceptT e m) where
|
||||
|
||||
instance HasServerConfigCtx m => HasServerConfigCtx (StateT s m) where
|
||||
askServerConfigCtx = lift askServerConfigCtx
|
||||
|
||||
-- | Number of server instances. A wrapper over @'Word' type, a non-negative integer
|
||||
-- with the same size as @'Int'.
|
||||
newtype ServerReplicas = ServerReplicas {serverReplicaNumber :: Word}
|
||||
deriving (Show, Eq)
|
||||
|
||||
unsafeServerReplicas :: Word -> ServerReplicas
|
||||
unsafeServerReplicas = ServerReplicas
|
||||
|
||||
oneServerReplica :: ServerReplicas
|
||||
oneServerReplica = ServerReplicas 1
|
||||
|
||||
-- | Safely build @'ServerReplicas' from non-negative and non-zero @'Int' value.
|
||||
safeServerReplicas :: Int -> Either Text ServerReplicas
|
||||
safeServerReplicas i@(I# i#)
|
||||
| i <= 0 = Left $ "Expecting a non-zero and non-negative integer for ServerReplicas but got " <> tshow i
|
||||
| otherwise = Right $ ServerReplicas $ W# (int2Word# i#)
|
||||
|
||||
-- | Get server replic count in @'Int'
|
||||
getServerReplicasInt :: ServerReplicas -> Int
|
||||
getServerReplicasInt (ServerReplicas replicaNumber) = fromIntegral replicaNumber
|
||||
|
||||
-- | A strategy for resizing a pool
|
||||
data ResizePoolStrategy
|
||||
= -- | Never resize the pool
|
||||
NeverResizePool
|
||||
| -- | Resize the pool by using provided total maximum connections setting value
|
||||
ResizePool Int
|
||||
|
@ -17,9 +17,9 @@ import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.Common (defaultSource)
|
||||
import Hasura.RQL.Types.EventTrigger
|
||||
import Hasura.RQL.Types.ResizePool
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.Server.Init (considerEnv, databaseUrlOption, runWithEnv, _envVar)
|
||||
import Hasura.Server.Types
|
||||
import System.Cron (everyMinute)
|
||||
import System.Environment (getEnvironment)
|
||||
import System.Exit (exitFailure)
|
||||
|
@ -36,11 +36,12 @@ import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.ResizePool (ResizePoolStrategy (..))
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.Server.Init (considerEnv, databaseUrlOption, runWithEnv, _envVar)
|
||||
import Hasura.Server.Metrics (createServerMetrics)
|
||||
import Hasura.Server.Prometheus (makeDummyPrometheusMetrics)
|
||||
import Hasura.Server.Types (RequestId (..), ResizePoolStrategy (..))
|
||||
import Hasura.Server.Types (RequestId (..))
|
||||
import Hasura.Session (RoleName, mkRoleName)
|
||||
import Language.GraphQL.Draft.Syntax.QQ qualified as G
|
||||
import ListT qualified
|
||||
|
@ -29,6 +29,7 @@ import Hasura.Prelude
|
||||
import Hasura.RQL.DDL.Schema.Cache
|
||||
import Hasura.RQL.DDL.Schema.Cache.Common
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.ResizePool
|
||||
import Hasura.RQL.Types.SchemaCache.Build
|
||||
import Hasura.Server.Init
|
||||
import Hasura.Server.Migrate
|
||||
|
Loading…
Reference in New Issue
Block a user