server: Delete unused SchemaCacheVer

`SchemaCacheVer` has been a write-only value for a while. It was introduced by hasura/graphql-engine#1934.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9786
GitOrigin-RevId: aa9d5600d2be347ea0538903b7f41f7ed745fafc
This commit is contained in:
Auke Booij 2023-07-06 17:34:50 +02:00 committed by hasura-bot
parent e7310a1e13
commit fdddac8057
8 changed files with 21 additions and 46 deletions

View File

@ -342,7 +342,6 @@ getResolvedExecPlan ::
SQLGenCtx ->
ReadOnlyMode ->
SchemaCache ->
SchemaCacheVer ->
ET.GraphQLQueryType ->
[HTTP.Header] ->
GQLReqUnparsed ->
@ -358,7 +357,6 @@ getResolvedExecPlan
sqlGenCtx
readOnlyMode
sc
_scVer
queryType
reqHeaders
reqUnparsed

View File

@ -296,7 +296,6 @@ runGQ ::
Env.Environment ->
SQLGenCtx ->
SchemaCache ->
SchemaCacheVer ->
Init.AllowListStatus ->
ReadOnlyMode ->
PrometheusMetrics ->
@ -309,7 +308,7 @@ runGQ ::
E.GraphQLQueryType ->
GQLReqUnparsed ->
m (GQLQueryOperationSuccessLog, HttpResponse (Maybe GQResponse, EncJSON))
runGQ env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics logger agentLicenseKey reqId userInfo ipAddress reqHeaders queryType reqUnparsed = do
runGQ env sqlGenCtx sc enableAL readOnlyMode prometheusMetrics logger agentLicenseKey reqId userInfo ipAddress reqHeaders queryType reqUnparsed = do
let gqlMetrics = pmGraphQLRequestMetrics prometheusMetrics
(totalTime, (response, parameterizedQueryHash, gqlOpType)) <- withElapsedTime $ do
@ -342,7 +341,6 @@ runGQ env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics logger agen
sqlGenCtx
readOnlyMode
sc
scVer
queryType
reqHeaders
reqUnparsed
@ -710,7 +708,6 @@ runGQBatched ::
Env.Environment ->
SQLGenCtx ->
SchemaCache ->
SchemaCacheVer ->
Init.AllowListStatus ->
ReadOnlyMode ->
PrometheusMetrics ->
@ -725,10 +722,10 @@ runGQBatched ::
-- | the batched request with unparsed GraphQL query
GQLBatchedReqs (GQLReq GQLQueryText) ->
m (HttpLogGraphQLInfo, HttpResponse EncJSON)
runGQBatched env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics logger agentLicenseKey reqId responseErrorsConfig userInfo ipAddress reqHdrs queryType query =
runGQBatched env sqlGenCtx sc enableAL readOnlyMode prometheusMetrics logger agentLicenseKey reqId responseErrorsConfig userInfo ipAddress reqHdrs queryType query =
case query of
GQLSingleRequest req -> do
(gqlQueryOperationLog, httpResp) <- runGQ env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics logger agentLicenseKey reqId userInfo ipAddress reqHdrs queryType req
(gqlQueryOperationLog, httpResp) <- runGQ env sqlGenCtx sc enableAL readOnlyMode prometheusMetrics logger agentLicenseKey reqId userInfo ipAddress reqHdrs queryType req
let httpLoggingGQInfo = (CommonHttpLogMetadata L.RequestModeSingle (Just (GQLSingleRequest (GQLQueryOperationSuccess gqlQueryOperationLog))), (PQHSetSingleton (gqolParameterizedQueryHash gqlQueryOperationLog)))
pure (httpLoggingGQInfo, snd <$> httpResp)
GQLBatchedReqs reqs -> do
@ -741,7 +738,7 @@ runGQBatched env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics logg
flip HttpResponse []
. encJFromList
. map (either (encJFromJEncoding . encodeGQErr includeInternal) _hrBody)
responses <- for reqs \req -> fmap (req,) $ try $ (fmap . fmap . fmap) snd $ runGQ env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics logger agentLicenseKey reqId userInfo ipAddress reqHdrs queryType req
responses <- for reqs \req -> fmap (req,) $ try $ (fmap . fmap . fmap) snd $ runGQ env sqlGenCtx sc enableAL readOnlyMode prometheusMetrics logger agentLicenseKey reqId userInfo ipAddress reqHdrs queryType req
let requestsOperationLogs = map fst $ rights $ map snd responses
batchOperationLogs =
map

View File

@ -464,7 +464,7 @@ onStart enabledLogTypes agentLicenseKey serverEnv wsConn shouldCaptureVariables
withComplete $ sendStartErr e
(requestId, reqHdrs) <- liftIO $ getRequestId origReqHdrs
(sc, scVer) <- liftIO $ getSchemaCacheWithVersion appStateRef
sc <- liftIO $ getSchemaCacheWithVersion appStateRef
operationLimit <- askGraphqlOperationLimit requestId userInfo (scApiLimits sc)
let runLimits ::
@ -498,7 +498,6 @@ onStart enabledLogTypes agentLicenseKey serverEnv wsConn shouldCaptureVariables
sqlGenCtx
readOnlyMode
sc
scVer
queryType
reqHdrs
q

View File

@ -2,9 +2,6 @@
module Hasura.RQL.Types.SchemaCache
( SchemaCache (..),
SchemaCacheVer,
initSchemaCacheVer,
incSchemaCacheVer,
TableConfig (..),
emptyTableConfig,
getAllRemoteSchemas,
@ -297,16 +294,6 @@ instance ToJSON CronTriggerInfo where
toJSON = genericToJSON hasuraJSON
toEncoding = genericToEncoding hasuraJSON
newtype SchemaCacheVer = SchemaCacheVer {unSchemaCacheVer :: Word64}
deriving (Show, Eq, Ord, Hashable, ToJSON, FromJSON)
initSchemaCacheVer :: SchemaCacheVer
initSchemaCacheVer = SchemaCacheVer 0
incSchemaCacheVer :: SchemaCacheVer -> SchemaCacheVer
incSchemaCacheVer (SchemaCacheVer prev) =
SchemaCacheVer $ prev + 1
type ActionCache = HashMap.HashMap ActionName ActionInfo -- info of all actions
type InheritedRolesCache = HashMap.HashMap RoleName (HashSet RoleName)

View File

@ -124,7 +124,6 @@ import Web.Spock.Core qualified as Spock
data HandlerCtx = HandlerCtx
{ hcAppContext :: AppContext,
hcSchemaCache :: RebuildableSchemaCache,
hcSchemaCacheVersion :: SchemaCacheVer,
hcUser :: UserInfo,
hcReqHeaders :: [HTTP.Header],
hcRequestId :: RequestId,
@ -350,11 +349,11 @@ mkSpockAction appStateRef qErrEncoder qErrModifier apiHandler = do
authInfo <- onLeft authenticationResp (logErrorAndResp Nothing requestId req (reqBody, Nothing) False origHeaders (ExtraUserInfo Nothing) . qErrModifier)
let (userInfo, _, authHeaders, extraUserInfo) = authInfo
appContext <- liftIO $ getAppContext appStateRef
(schemaCache, schemaCacheVer) <- liftIO $ getRebuildableSchemaCacheWithVersion appStateRef
schemaCache <- liftIO $ getRebuildableSchemaCacheWithVersion appStateRef
pure
( userInfo,
authHeaders,
HandlerCtx appContext schemaCache schemaCacheVer userInfo headers requestId ipAddress appEnvLicenseKeyCache,
HandlerCtx appContext schemaCache userInfo headers requestId ipAddress appEnvLicenseKeyCache,
shouldIncludeInternal (_uiRole userInfo) acResponseInternalErrorsConfig,
extraUserInfo
)
@ -569,11 +568,10 @@ v1Alpha1GQHandler queryType query = do
AppContext {..} <- asks hcAppContext
userInfo <- asks hcUser
schemaCache <- lastBuiltSchemaCache <$> asks hcSchemaCache
schemaCacheVer <- asks hcSchemaCacheVersion
reqHeaders <- asks hcReqHeaders
ipAddress <- asks hcSourceIpAddress
requestId <- asks hcRequestId
GH.runGQBatched acEnvironment acSQLGenCtx schemaCache schemaCacheVer acEnableAllowlist appEnvEnableReadOnlyMode appEnvPrometheusMetrics (_lsLogger appEnvLoggers) appEnvLicenseKeyCache requestId acResponseInternalErrorsConfig userInfo ipAddress reqHeaders queryType query
GH.runGQBatched acEnvironment acSQLGenCtx schemaCache acEnableAllowlist appEnvEnableReadOnlyMode appEnvPrometheusMetrics (_lsLogger appEnvLoggers) appEnvLicenseKeyCache requestId acResponseInternalErrorsConfig userInfo ipAddress reqHeaders queryType query
v1GQHandler ::
( MonadIO m,
@ -917,7 +915,6 @@ httpApp setupHook appStateRef AppEnv {..} consoleType ekgStore closeWebsocketsOn
AppContext {..} <- liftIO $ getAppContext appStateRef
endpoints <- liftIO $ scEndpoints <$> getSchemaCache appStateRef
schemaCache <- lastBuiltSchemaCache <$> asks hcSchemaCache
schemaCacheVer <- asks hcSchemaCacheVersion
requestId <- asks hcRequestId
userInfo <- asks hcUser
reqHeaders <- asks hcReqHeaders
@ -933,7 +930,7 @@ httpApp setupHook appStateRef AppEnv {..} consoleType ekgStore closeWebsocketsOn
Spock.PATCH -> pure EP.PATCH
other -> throw400 BadRequest $ "Method " <> tshow other <> " not supported."
_ -> throw400 BadRequest $ "Nonstandard method not allowed for REST endpoints"
fmap JSONResp <$> runCustomEndpoint acEnvironment acSQLGenCtx schemaCache schemaCacheVer acEnableAllowlist appEnvEnableReadOnlyMode appEnvPrometheusMetrics (_lsLogger appEnvLoggers) appEnvLicenseKeyCache requestId userInfo reqHeaders ipAddress req endpoints
fmap JSONResp <$> runCustomEndpoint acEnvironment acSQLGenCtx schemaCache acEnableAllowlist appEnvEnableReadOnlyMode appEnvPrometheusMetrics (_lsLogger appEnvLoggers) appEnvLicenseKeyCache requestId userInfo reqHeaders ipAddress req endpoints
-- See Issue #291 for discussion around restified feature
Spock.hookRouteAll ("api" <//> "rest" <//> Spock.wildcard) $ \wildcard -> do

View File

@ -79,7 +79,7 @@ data AppStateRef impl = AppStateRef
-- | A mutable reference to '(RebuildableSchemaCache, SchemaCacheVer)' and 'RebuildableAppContext'
data AppState impl = AppState
{ asSchemaCache :: (RebuildableSchemaCache, SchemaCacheVer),
{ asSchemaCache :: RebuildableSchemaCache,
asAppCtx :: RebuildableAppContext impl
}
@ -97,7 +97,7 @@ initialiseAppStateRef ::
m (AppStateRef impl)
initialiseAppStateRef (TLSAllowListRef tlsAllowListRef) metricsConfigRefM serverMetrics rebuildableSchemaCache rebuildableAppCtx = liftIO do
cacheLock <- newMVar ()
let appState = AppState (rebuildableSchemaCache, initSchemaCacheVer) rebuildableAppCtx
let appState = AppState rebuildableSchemaCache rebuildableAppCtx
cacheCell <- newIORef appState
let metadataVersionGauge = smSchemaCacheMetadataResourceVersion serverMetrics
updateMetadataVersionGauge metadataVersionGauge rebuildableSchemaCache
@ -133,15 +133,14 @@ withSchemaCacheReadUpdate ::
m a
withSchemaCacheReadUpdate (AppStateRef lock cacheRef metadataVersionGauge) logger mLogCheckerTVar action =
withMVarMasked lock $ const do
(rebuildableSchemaCache, _) <- asSchemaCache <$> liftIO (readIORef cacheRef)
rebuildableSchemaCache <- asSchemaCache <$> liftIO (readIORef cacheRef)
(!res, !newSC) <- action rebuildableSchemaCache
when (scMetadataResourceVersion (lastBuiltSchemaCache newSC) == MetadataResourceVersion (-1))
$ throw500 "Programming error: attempting to save Schema Cache with incorrect mrv. Please report this to Hasura."
liftIO do
-- update schemacache in IO reference
modifyIORef' cacheRef $ \appState ->
let !newVer = incSchemaCacheVer (snd $ asSchemaCache appState)
in appState {asSchemaCache = (newSC, newVer)}
appState {asSchemaCache = newSC}
-- update metric with new metadata version
updateMetadataVersionGauge metadataVersionGauge newSC
@ -167,7 +166,7 @@ readAppContextRef :: AppStateRef impl -> IO (RebuildableAppContext impl)
readAppContextRef scRef = asAppCtx <$> readIORef (_scrCache scRef)
-- | Read the contents of the 'AppStateRef' to get the latest 'RebuildableSchemaCache' and 'SchemaCacheVer'
getRebuildableSchemaCacheWithVersion :: AppStateRef impl -> IO (RebuildableSchemaCache, SchemaCacheVer)
getRebuildableSchemaCacheWithVersion :: AppStateRef impl -> IO RebuildableSchemaCache
getRebuildableSchemaCacheWithVersion scRef = asSchemaCache <$> readIORef (_scrCache scRef)
--------------------------------------------------------------------------------
@ -224,11 +223,11 @@ readMetricsConfig (MetricsConfigRef ref) = join $ readIORef ref
-- | Read the latest 'SchemaCache' from the 'AppStateRef'.
getSchemaCache :: AppStateRef impl -> IO SchemaCache
getSchemaCache asRef = lastBuiltSchemaCache . fst <$> getRebuildableSchemaCacheWithVersion asRef
getSchemaCache asRef = lastBuiltSchemaCache <$> getRebuildableSchemaCacheWithVersion asRef
-- | Read the latest 'SchemaCache' and its version from the 'AppStateRef'.
getSchemaCacheWithVersion :: AppStateRef impl -> IO (SchemaCache, SchemaCacheVer)
getSchemaCacheWithVersion scRef = fmap (\(sc, ver) -> (lastBuiltSchemaCache sc, ver)) $ getRebuildableSchemaCacheWithVersion scRef
getSchemaCacheWithVersion :: AppStateRef impl -> IO (SchemaCache)
getSchemaCacheWithVersion scRef = fmap lastBuiltSchemaCache $ getRebuildableSchemaCacheWithVersion scRef
-- | Read the latest 'AppContext' from the 'AppStateRef'.
getAppContext :: AppStateRef impl -> IO AppContext
@ -285,8 +284,7 @@ updateAppStateRef (AppStateRef lock cacheRef metadataVersionGauge) logger !newAp
liftIO do
-- update schemacache in IO reference
modifyIORef' cacheRef $ \appState ->
let !newVer = incSchemaCacheVer (snd $ asSchemaCache appState)
in appState {asSchemaCache = (newSC, newVer), asAppCtx = newAppCtx}
appState {asSchemaCache = newSC, asAppCtx = newAppCtx}
-- update metric with new metadata version
updateMetadataVersionGauge metadataVersionGauge newSC

View File

@ -115,7 +115,6 @@ runCustomEndpoint ::
Env.Environment ->
SQLGenCtx ->
SchemaCache ->
SchemaCacheVer ->
Init.AllowListStatus ->
ReadOnlyMode ->
PrometheusMetrics ->
@ -128,7 +127,7 @@ runCustomEndpoint ::
RestRequest EndpointMethod ->
EndpointTrie GQLQueryWithText ->
m (HttpLogGraphQLInfo, HttpResponse EncJSON)
runCustomEndpoint env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics logger agentLicenseKey requestId userInfo reqHeaders ipAddress RestRequest {..} endpoints = do
runCustomEndpoint env sqlGenCtx sc enableAL readOnlyMode prometheusMetrics logger agentLicenseKey requestId userInfo reqHeaders ipAddress RestRequest {..} endpoints = do
-- First match the path to an endpoint.
case matchPath reqMethod (T.split (== '/') reqPath) endpoints of
MatchFound (queryx :: EndpointMetadata GQLQueryWithText) matches ->
@ -158,7 +157,7 @@ runCustomEndpoint env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics
-- with the query string from the schema cache, and pass it
-- through to the /v1/graphql endpoint.
(httpLoggingMetadata, handlerResp) <- do
(gqlOperationLog, resp) <- GH.runGQ env sqlGenCtx sc scVer enableAL readOnlyMode prometheusMetrics logger agentLicenseKey requestId userInfo ipAddress reqHeaders E.QueryHasura (mkPassthroughRequest queryx resolvedVariables)
(gqlOperationLog, resp) <- GH.runGQ env sqlGenCtx sc enableAL readOnlyMode prometheusMetrics logger agentLicenseKey requestId userInfo ipAddress reqHeaders E.QueryHasura (mkPassthroughRequest queryx resolvedVariables)
let httpLoggingGQInfo = (CommonHttpLogMetadata RequestModeNonBatchable Nothing, (PQHSetSingleton (gqolParameterizedQueryHash gqlOperationLog)))
return (httpLoggingGQInfo, fst <$> resp)
case sequence handlerResp of

View File

@ -289,7 +289,7 @@ refreshSchemaCache
respErr <- runExceptT
$ withSchemaCacheUpdate appStateRef logger (Just logTVar)
$ do
rebuildableCache <- liftIO $ fst <$> getRebuildableSchemaCacheWithVersion appStateRef
rebuildableCache <- liftIO $ getRebuildableSchemaCacheWithVersion appStateRef
appContext <- liftIO $ getAppContext appStateRef
let dynamicConfig = buildCacheDynamicConfig appContext
-- the instance which triggered the schema sync event would have stored