mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
server: insert updated metadata and schema sync notifications in a transaction
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10558 GitOrigin-RevId: e3bb0ef2378162a5fdccc7131a584f4200404afd
This commit is contained in:
parent
8a16671fb1
commit
e6ca36dcb1
@ -812,11 +812,16 @@ instance MonadMetadataStorage AppM where
|
||||
fetchMetadataResourceVersion = runInSeparateTx fetchMetadataResourceVersionFromCatalog
|
||||
fetchMetadata = runInSeparateTx fetchMetadataAndResourceVersionFromCatalog
|
||||
fetchMetadataNotifications a b = runInSeparateTx $ fetchMetadataNotificationsFromCatalog a b
|
||||
setMetadata r = runInSeparateTx . setMetadataInCatalog r
|
||||
notifySchemaCacheSync a b c = runInSeparateTx $ notifySchemaCacheSyncTx a b c
|
||||
|
||||
getCatalogState = runInSeparateTx getCatalogStateTx
|
||||
setCatalogState a b = runInSeparateTx $ setCatalogStateTx a b
|
||||
|
||||
updateMetadataAndNotifySchemaSync instanceId resourceVersion metadata cacheInvalidations =
|
||||
runInSeparateTx $ do
|
||||
newResourceVersion <- setMetadataInCatalog resourceVersion metadata
|
||||
notifySchemaCacheSyncTx newResourceVersion instanceId cacheInvalidations
|
||||
pure newResourceVersion
|
||||
|
||||
-- stored source introspection is not available in this distribution
|
||||
fetchSourceIntrospection _ = pure $ Right Nothing
|
||||
storeSourceIntrospection _ _ = pure $ Right ()
|
||||
|
@ -98,10 +98,17 @@ class (Monad m) => MonadMetadataStorage m where
|
||||
fetchMetadataResourceVersion :: m (Either QErr MetadataResourceVersion)
|
||||
fetchMetadata :: m (Either QErr MetadataWithResourceVersion)
|
||||
fetchMetadataNotifications :: MetadataResourceVersion -> InstanceId -> m (Either QErr [(MetadataResourceVersion, CacheInvalidations)])
|
||||
setMetadata :: MetadataResourceVersion -> Metadata -> m (Either QErr MetadataResourceVersion)
|
||||
notifySchemaCacheSync :: MetadataResourceVersion -> InstanceId -> CacheInvalidations -> m (Either QErr ())
|
||||
|
||||
getCatalogState :: m (Either QErr CatalogState)
|
||||
|
||||
-- This function is used to update the metadata in the metadata storage with schema sync notifications.
|
||||
updateMetadataAndNotifySchemaSync ::
|
||||
InstanceId ->
|
||||
MetadataResourceVersion ->
|
||||
Metadata ->
|
||||
CacheInvalidations ->
|
||||
m (Either QErr MetadataResourceVersion)
|
||||
|
||||
-- the `setCatalogState` function is used by the console and CLI to store its state
|
||||
-- it is disabled when maintenance mode is on
|
||||
setCatalogState :: CatalogStateType -> Value -> m (Either QErr ())
|
||||
@ -157,11 +164,12 @@ instance (MonadMetadataStorage m, MonadTrans t, Monad (t m)) => MonadMetadataSto
|
||||
fetchMetadataResourceVersion = lift fetchMetadataResourceVersion
|
||||
fetchMetadata = lift fetchMetadata
|
||||
fetchMetadataNotifications a b = lift $ fetchMetadataNotifications a b
|
||||
setMetadata r = lift . setMetadata r
|
||||
notifySchemaCacheSync a b c = lift $ notifySchemaCacheSync a b c
|
||||
|
||||
getCatalogState = lift getCatalogState
|
||||
setCatalogState a b = lift $ setCatalogState a b
|
||||
|
||||
updateMetadataAndNotifySchemaSync a b c d = lift $ updateMetadataAndNotifySchemaSync a b c d
|
||||
|
||||
fetchSourceIntrospection = lift . fetchSourceIntrospection
|
||||
storeSourceIntrospection a b = lift $ storeSourceIntrospection a b
|
||||
|
||||
|
@ -158,24 +158,22 @@ runMetadataQuery appContext schemaCache closeWebsocketsOnMetadataChange RQLMetad
|
||||
$ SchemaSyncLog L.LevelInfo TTMetadataApi
|
||||
$ String
|
||||
$ "Attempting to insert new metadata in storage"
|
||||
|
||||
newResourceVersion <-
|
||||
Tracing.newSpan "setMetadata"
|
||||
Tracing.newSpan "updateMetadataAndNotifySchemaSync"
|
||||
$ liftEitherM
|
||||
$ setMetadata (fromMaybe currentResourceVersion _rqlMetadataResourceVersion) modMetadata
|
||||
$ updateMetadataAndNotifySchemaSync appEnvInstanceId (fromMaybe currentResourceVersion _rqlMetadataResourceVersion) modMetadata cacheInvalidations
|
||||
|
||||
L.unLoggerTracing logger
|
||||
$ SchemaSyncLog L.LevelInfo TTMetadataApi
|
||||
$ String
|
||||
$ "Successfully inserted new metadata in storage with resource version: "
|
||||
<> showMetadataResourceVersion newResourceVersion
|
||||
|
||||
-- notify schema cache sync
|
||||
Tracing.newSpan "notifySchemaCacheSync"
|
||||
$ liftEitherM
|
||||
$ notifySchemaCacheSync newResourceVersion appEnvInstanceId cacheInvalidations
|
||||
L.unLoggerTracing logger
|
||||
$ SchemaSyncLog L.LevelInfo TTMetadataApi
|
||||
$ String
|
||||
$ "Inserted schema cache sync notification at resource version:"
|
||||
$ "Inserted schema cache sync notification at resource version: "
|
||||
<> showMetadataResourceVersion newResourceVersion
|
||||
|
||||
-- save sources introspection to stored-introspection DB
|
||||
|
@ -217,17 +217,18 @@ runQuery appContext sc query = do
|
||||
then case appEnvEnableMaintenanceMode of
|
||||
MaintenanceModeDisabled -> do
|
||||
-- set modified metadata in storage
|
||||
newResourceVersion <- liftEitherM $ setMetadata currentResourceVersion updatedMetadata
|
||||
-- notify schema cache sync
|
||||
liftEitherM $ notifySchemaCacheSync newResourceVersion appEnvInstanceId invalidations
|
||||
newResourceVersion <-
|
||||
liftEitherM
|
||||
$ updateMetadataAndNotifySchemaSync appEnvInstanceId currentResourceVersion updatedMetadata invalidations
|
||||
|
||||
-- save sources introspection to stored-introspection DB
|
||||
saveSourcesIntrospection logger sourcesIntrospection newResourceVersion
|
||||
|
||||
(_, modSchemaCache', _, _, _) <-
|
||||
Tracing.newSpan "setMetadataResourceVersionInSchemaCache"
|
||||
$ setMetadataResourceVersionInSchemaCache newResourceVersion
|
||||
& runCacheRWT dynamicConfig modSchemaCache
|
||||
|
||||
-- save sources introspection to stored-introspection DB
|
||||
saveSourcesIntrospection logger sourcesIntrospection newResourceVersion
|
||||
-- run schema registry action
|
||||
for_ schemaRegistryAction $ \action -> do
|
||||
liftIO $ action newResourceVersion (scInconsistentObjs (lastBuiltSchemaCache modSchemaCache')) updatedMetadata
|
||||
|
@ -132,26 +132,21 @@ runQuery appContext schemaCache rqlQuery = do
|
||||
if queryModifiesSchema rqlQuery
|
||||
then case appEnvEnableMaintenanceMode of
|
||||
MaintenanceModeDisabled -> do
|
||||
-- set modified metadata in storage
|
||||
-- set modified metadata in storage and notify schema sync
|
||||
newResourceVersion <-
|
||||
Tracing.newSpan "setMetadata"
|
||||
Tracing.newSpan "updateMetadataAndNotifySchemaSync"
|
||||
$ liftEitherM
|
||||
$ setMetadata currentResourceVersion updatedMetadata
|
||||
$ updateMetadataAndNotifySchemaSync appEnvInstanceId currentResourceVersion updatedMetadata invalidations
|
||||
|
||||
-- notify schema cache sync
|
||||
Tracing.newSpan "notifySchemaCacheSync"
|
||||
$ liftEitherM
|
||||
$ notifySchemaCacheSync newResourceVersion appEnvInstanceId invalidations
|
||||
-- save sources introspection to stored-introspection DB
|
||||
Tracing.newSpan "storeSourcesIntrospection"
|
||||
$ saveSourcesIntrospection (_lsLogger appEnvLoggers) sourcesIntrospection newResourceVersion
|
||||
|
||||
(_, modSchemaCache', _, _, _) <-
|
||||
Tracing.newSpan "setMetadataResourceVersionInSchemaCache"
|
||||
$ setMetadataResourceVersionInSchemaCache newResourceVersion
|
||||
& runCacheRWT dynamicConfig modSchemaCache
|
||||
|
||||
-- save sources introspection to stored-introspection DB
|
||||
Tracing.newSpan "storeSourcesIntrospection"
|
||||
$ saveSourcesIntrospection (_lsLogger appEnvLoggers) sourcesIntrospection newResourceVersion
|
||||
|
||||
-- run schema registry action
|
||||
Tracing.newSpan "runSchemaRegistryAction"
|
||||
$ for_ schemaRegistryAction
|
||||
|
Loading…
Reference in New Issue
Block a user