Skip to main content Link Search Menu Expand Document (external link)

Sharding overview

Added in v1.0.0


Table of contents


context

Tag

Signature

export declare const Tag: Context.Tag<Sharding, Sharding>

Added in v1.0.0

layers

live

Signature

export declare const live: any

Added in v1.0.0

models

Sharding (interface)

Signature

export interface Sharding {
  readonly [ShardingTypeId]: ShardingTypeId
  readonly register: Effect.Effect<void>
  readonly unregister: Effect.Effect<void>
  readonly messenger: <Msg extends Message.Message.Any>(entityType: RecipentType.EntityType<Msg>) => Messenger<Msg>
  readonly broadcaster: <Msg extends Message.Message.Any>(topicType: RecipentType.TopicType<Msg>) => Broadcaster<Msg>
  readonly isEntityOnLocalShards: (recipientAddress: RecipientAddress.RecipientAddress) => Effect.Effect<boolean>
  readonly isShuttingDown: Effect.Effect<boolean>

  readonly registerScoped: Effect.Effect<void, never, Scope.Scope>
  readonly registerEntity: <Msg extends Message.Message.Any>(
    entityType: RecipentType.EntityType<Msg>
  ) => <R>(
    behaviour: RecipientBehaviour.RecipientBehaviour<Msg, R>,
    options?: RecipientBehaviour.EntityBehaviourOptions
  ) => Effect.Effect<void, never, Exclude<R, RecipientBehaviourContext.RecipientBehaviourContext>>
  readonly registerTopic: <Msg extends Message.Message.Any>(
    topicType: RecipentType.TopicType<Msg>
  ) => <R>(
    behaviour: RecipientBehaviour.RecipientBehaviour<Msg, R>,
    options?: RecipientBehaviour.EntityBehaviourOptions
  ) => Effect.Effect<void, never, Exclude<R, RecipientBehaviourContext.RecipientBehaviourContext>>
  readonly getShardingRegistrationEvents: Stream.Stream<ShardingRegistrationEvent.ShardingRegistrationEvent>
  readonly registerSingleton: <R>(name: string, run: Effect.Effect<void, never, R>) => Effect.Effect<void, never, R>
  readonly assign: (shards: HashSet.HashSet<ShardId.ShardId>) => Effect.Effect<void>
  readonly unassign: (shards: HashSet.HashSet<ShardId.ShardId>) => Effect.Effect<void>
  readonly sendMessageToLocalEntityManagerWithoutRetries: (
    message: SerializedEnvelope.SerializedEnvelope
  ) => Effect.Effect<
    MessageState.MessageState<SerializedMessage.SerializedMessage>,
    ShardingException.ShardingException
  >
  readonly getPods: Effect.Effect<HashSet.HashSet<PodAddress.PodAddress>>
  readonly getAssignedShardIds: Effect.Effect<HashSet.HashSet<ShardId.ShardId>>
  /** @internal */
  readonly refreshAssignments: Effect.Effect<void, never, Scope.Scope>
  /** @internal */
  readonly getShardId: (recipientAddress: RecipientAddress.RecipientAddress) => ShardId.ShardId
}

Added in v1.0.0

symbols

ShardingTypeId

Signature

export declare const ShardingTypeId: typeof ShardingTypeId

Added in v1.0.0

ShardingTypeId (type alias)

Signature

export type ShardingTypeId = typeof ShardingTypeId

Added in v1.0.0

utils

broadcaster

Get an object that allows broadcasting messages to a given topic type. You can provide a custom send timeout to override the one globally defined.

Signature

export declare const broadcaster: <Msg extends Message.Message.Any>(
  topicType: RecipentType.TopicType<Msg>
) => Effect.Effect<Broadcaster<Msg>, never, Sharding>

Added in v1.0.0

getAssignedShardIds

Gets the list of shardIds assigned to the current Pod

Signature

export declare const getAssignedShardIds: Effect.Effect<HashSet.HashSet<ShardId.ShardId>, never, Sharding>

Added in v1.0.0

getPods

Get the list of pods currently registered to the Shard Manager

Signature

export declare const getPods: Effect.Effect<HashSet.HashSet<PodAddress.PodAddress>, never, Sharding>

Added in v1.0.0

messenger

Get an object that allows sending messages to a given entity type. You can provide a custom send timeout to override the one globally defined.

Signature

export declare const messenger: <Msg extends Message.Message.Any>(
  entityType: RecipentType.EntityType<Msg>
) => Effect.Effect<Messenger<Msg>, never, Sharding>

Added in v1.0.0

register

Notify the shard manager that shards can now be assigned to this pod.

Signature

export declare const register: Effect.Effect<void, never, Sharding>

Added in v1.0.0

registerEntity

Register a new entity type, allowing pods to send messages to entities of this type.

Signature

export declare const registerEntity: <Msg extends Message.Message.Any>(
  entityType: RecipentType.EntityType<Msg>
) => <R>(
  behavior: RecipientBehaviour.RecipientBehaviour<Msg, R>,
  options?: RecipientBehaviour.EntityBehaviourOptions | undefined
) => Effect.Effect<void, never, Sharding | Exclude<R, RecipientBehaviourContext.RecipientBehaviourContext>>

Added in v1.0.0

registerScoped

Same as register, but will automatically call unregister when the Scope is terminated.

Signature

export declare const registerScoped: Effect.Effect<void, never, any>

Added in v1.0.0

registerSingleton

Start a computation that is guaranteed to run only on a single pod. Each pod should call registerSingleton but only a single pod will actually run it at any given time.

Signature

export declare const registerSingleton: <R>(
  name: string,
  run: Effect.Effect<void, never, R>
) => Effect.Effect<void, never, Sharding | R>

Added in v1.0.0

registerTopic

Register a new topic type, allowing pods to broadcast messages to subscribers.

Signature

export declare const registerTopic: <Msg extends Message.Message.Any>(
  topicType: RecipentType.TopicType<Msg>
) => <R>(
  behavior: RecipientBehaviour.RecipientBehaviour<Msg, R>,
  options?: RecipientBehaviour.EntityBehaviourOptions | undefined
) => Effect.Effect<void, never, Sharding | Exclude<R, RecipientBehaviourContext.RecipientBehaviourContext>>

Added in v1.0.0

sendMessageToLocalEntityManagerWithoutRetries

Sends a raw message to the local entity manager without performing reties. Those are up to the caller.

Signature

export declare const sendMessageToLocalEntityManagerWithoutRetries: (
  message: SerializedEnvelope.SerializedEnvelope
) => Effect.Effect<
  MessageState.MessageState<SerializedMessage.SerializedMessage>,
  ShardingException.ShardingException,
  Sharding
>

Added in v1.0.0

unregister

Notify the shard manager that shards must be unassigned from this pod.

Signature

export declare const unregister: Effect.Effect<void, never, Sharding>

Added in v1.0.0