graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellNone
LanguageHaskell2010

Hasura.Server.SchemaCacheRef

Synopsis

Documentation

data SchemaCacheRef Source #

A mutable reference to a RebuildableSchemaCache, plus

  • a write lock,
  • update version tracking, and
  • a gauge metric that tracks the metadata version of the SchemaCache.

Constructors

SchemaCacheRef 

Fields

  • _scrLock :: MVar ()

    The idea behind explicit locking here is to

    1. Allow maximum throughput for serving requests (v1graphql) (as each request reads the current schemacache)
    2. We don't want to process more than one request at any point of time which would modify the schema cache as such queries are expensive.

    Another option is to consider removing this lock in place of `_scrCache :: MVar ...` if it's okay or in fact correct to block during schema update in e.g. _wseGCtxMap. Vamshi says: It is theoretically possible to have a situation (in between building new schemacache and before writing it to the IORef) where we serve a request with a stale schemacache but I guess it is an okay trade-off to pay for a higher throughput (I remember doing a bunch of benchmarks to test this hypothesis).

  • _scrCache :: IORef (RebuildableSchemaCache, SchemaCacheVer)
     
  • _scrMetadataVersionGauge :: Gauge

    The gauge metric that tracks the current metadata version.

    Invariant: This gauge must be updated via updateMetadataVersionGauge whenever the _scrCache IORef is updated.

withSchemaCacheUpdate :: (MonadIO m, MonadBaseControl IO m) => SchemaCacheRef -> Logger Hasura -> Maybe (TVar Bool) -> m (a, RebuildableSchemaCache) -> m a Source #

Set the SchemaCacheRef to the RebuildableSchemaCache produced by the given action.

An internal lock ensures that at most one update to the SchemaCacheRef may proceed at a time.

getSchemaCache :: SchemaCacheRef -> IO SchemaCache Source #

Utility function. Read the latest SchemaCache from the SchemaCacheRef.

getSchemaCache == fmap (lastBuiltSchemaCache . fst) . readSchemaCacheRef