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

Hasura.GraphQL.Execute.Subscription.Poll.Common

Description

Multiplexed subscription poller threads; see Hasura.GraphQL.Execute.Subscription for details.

Synopsis

Documentation

newtype SubscriberId Source #

Constructors

SubscriberId 

Fields

Instances

Instances details
Eq SubscriberId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Show SubscriberId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Generic SubscriberId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Associated Types

type Rep SubscriberId :: Type -> Type #

Hashable SubscriberId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

ToJSON SubscriberId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Methods

toJSON :: SubscriberId -> Value

toEncoding :: SubscriberId -> Encoding

toJSONList :: [SubscriberId] -> Value

toEncodingList :: [SubscriberId] -> Encoding

type Rep SubscriberId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

type Rep SubscriberId = D1 ('MetaData "SubscriberId" "Hasura.GraphQL.Execute.Subscription.Poll.Common" "graphql-engine-1.0.0-inplace" 'True) (C1 ('MetaCons "SubscriberId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unSubscriberId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UUID)))

newtype SubscriberMetadata Source #

Allows a user of the live query subsystem (currently websocket transport) to attach arbitrary metadata about a subscriber. This information is available as part of Subscriber in CohortExecutionDetails and can be logged by customizing in pollerlog

Constructors

SubscriberMetadata 

Fields

data SubscriptionMetadata Source #

Subscription onChange metadata, used for adding more extra analytics data

data Cohort streamCursorVars Source #

A batched group of Subscribers who are not only listening to the same query but also have identical session and query variables. Each result pushed to a Cohort is forwarded along to each of its Subscribers.

In SQL, each Cohort corresponds to a single row in the laterally-joined _subs table (and therefore a single row in the query result).

See also CohortMap.

Constructors

Cohort 

Fields

  • _cCohortId :: !CohortId

    a unique identifier used to identify the cohort in the generated query

  • _cPreviousResponse :: !(TVar (Maybe ResponseHash))

    a hash of the previous query result, if any, used to determine if we need to push an updated result to the subscribers or not

  • _cExistingSubscribers :: !SubscriberMap

    the subscribers we’ve already pushed a result to; we push new results to them iff the response changes

  • _cNewSubscribers :: !SubscriberMap

    subscribers we haven’t yet pushed any results to; we push results to them regardless if the result changed, then merge them in the map of existing subscribers

  • _cStreamCursorVariables :: !streamCursorVars

    a mutable type which holds the latest value of the subscription stream cursor. In case of live query subscription, this field is ignored by setting streamCursorVars to ()

newtype BatchId Source #

The BatchId is a number based ID to uniquely identify a batch in a single poll and it's used to identify the batch to which a cohort belongs to.

Constructors

BatchId 

Fields

Instances

Instances details
Eq BatchId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Methods

(==) :: BatchId -> BatchId -> Bool #

(/=) :: BatchId -> BatchId -> Bool #

Show BatchId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

ToJSON BatchId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Methods

toJSON :: BatchId -> Value

toEncoding :: BatchId -> Encoding

toJSONList :: [BatchId] -> Value

toEncodingList :: [BatchId] -> Encoding

newtype ResponseHash Source #

A hash used to determine if the result changed without having to keep the entire result in memory. Using a cryptographic hash ensures that a hash collision is almost impossible: with 256 bits, even if a subscription changes once per second for an entire year, the probability of a hash collision is ~4.294417×10-63. See Note [Blake2b faster than SHA-256].

Constructors

ResponseHash 

Fields

type CohortKey = CohortVariables Source #

A key we use to determine if two Subscribers belong in the same Cohort (assuming they already meet the criteria to be in the same Poller). Note the distinction between this and CohortId; the latter is a completely synthetic key used only to identify the cohort in the generated SQL query.

type CohortMap streamCursor = TMap CohortKey (Cohort streamCursor) Source #

This has the invariant, maintained in removeLiveQuery, that it contains no Cohort with zero total (existing + new) subscribers.

dumpCohortMap :: CohortMap streamCursor -> IO Value Source #

data Poller streamCursor Source #

A unique, multiplexed query. Each Poller has its own polling thread that periodically polls Postgres and pushes results to each of its listening Cohorts.

In SQL, an Poller corresponds to a single, multiplexed query, though in practice, Pollers with large numbers of Cohorts are batched into multiple concurrent queries for performance reasons.

Constructors

Poller 

Fields

  • _pCohorts :: !(CohortMap streamCursor)
     
  • _pIOState :: !(TMVar PollerIOState)

    This is in a separate TMVar because it’s important that we are able to construct Poller values in STM --- we need the insertion into the PollerMap to be atomic to ensure that we don’t accidentally create two for the same query due to a race. However, we can’t spawn the worker thread or create the metrics store in STM, so we insert it into the Poller only after we’re certain we won’t create any duplicates.

    This var is "write once", moving monotonically from empty to full. TODO this could probably be tightened up to something like 'STM PollerIOState'

data PollerIOState Source #

Constructors

PollerIOState 

Fields

  • _pThread :: !Thread

    a handle on the poller’s worker thread that can be used to stop it if all its cohorts stop listening

  • _pId :: !PollerId
     

data PollerKey Source #

Constructors

PollerKey 

Fields

Instances

Instances details
Eq PollerKey Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Show PollerKey Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Generic PollerKey Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Associated Types

type Rep PollerKey :: Type -> Type #

Hashable PollerKey Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

ToJSON PollerKey Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Methods

toJSON :: PollerKey -> Value

toEncoding :: PollerKey -> Encoding

toJSONList :: [PollerKey] -> Value

toEncodingList :: [PollerKey] -> Encoding

type Rep PollerKey Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

type Rep PollerKey = D1 ('MetaData "PollerKey" "Hasura.GraphQL.Execute.Subscription.Poll.Common" "graphql-engine-1.0.0-inplace" 'False) (C1 ('MetaCons "PollerKey" 'PrefixI 'True) (S1 ('MetaSel ('Just "_lgSource") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SourceName) :*: (S1 ('MetaSel ('Just "_lgRole") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RoleName) :*: S1 ('MetaSel ('Just "_lgQuery") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text))))

type PollerMap streamCursor = Map PollerKey (Poller streamCursor) Source #

dumpPollerMap :: Bool -> PollerMap streamCursor -> IO Value Source #

newtype PollerId Source #

An ID to track unique Pollers, so that we can gather metrics about each poller

Constructors

PollerId 

Fields

Instances

Instances details
Eq PollerId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Show PollerId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Generic PollerId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Associated Types

type Rep PollerId :: Type -> Type #

Methods

from :: PollerId -> Rep PollerId x #

to :: Rep PollerId x -> PollerId #

ToJSON PollerId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

Methods

toJSON :: PollerId -> Value

toEncoding :: PollerId -> Encoding

toJSONList :: [PollerId] -> Value

toEncodingList :: [PollerId] -> Encoding

type Rep PollerId Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Subscription.Poll.Common

type Rep PollerId = D1 ('MetaData "PollerId" "Hasura.GraphQL.Execute.Subscription.Poll.Common" "graphql-engine-1.0.0-inplace" 'True) (C1 ('MetaCons "PollerId" 'PrefixI 'True) (S1 ('MetaSel ('Just "unPollerId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UUID)))

data CohortExecutionDetails Source #

Execution information related to a cohort on a poll cycle

Constructors

CohortExecutionDetails 

Fields

data BatchExecutionDetails Source #

Execution information related to a single batched execution

Constructors

BatchExecutionDetails 

Fields

batchExecutionDetailMinimal :: BatchExecutionDetails -> Value Source #

see Note [Minimal LiveQuery Poller Log]

data PollDetails Source #

Constructors

PollDetails 

Fields

pollDetailMinimal :: PollDetails -> Value Source #

see Note [Minimal LiveQuery Poller Log]