actors

package
v1.12.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2023 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Copyright 2023 The Dapr Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const InternalActorTypePrefix = "dapr.internal."

Variables

View Source
var (
	ErrIncompatibleStateStore        = errors.New("actor state store does not exist, or does not support transactions which are required to save state - please see https://docs.dapr.io/operations/components/setup-state-store/supported-state-stores/")
	ErrReminderOpActorNotHosted      = errors.New("operations on actor reminders are only possible on hosted actor types")
	ErrTransactionsTooManyOperations = errors.New("the transaction contains more operations than supported by the state store")
	ErrReminderCanceled              = internal.ErrReminderCanceled
)
View Source
var ErrActorDisposed = errors.New("actor is already disposed")

ErrActorDisposed is the error when runtime tries to hold the lock of the disposed actor.

View Source
var ErrMaxStackDepthExceeded = errors.New("maximum stack depth exceeded")

Functions

func DecodeInternalActorData added in v1.10.0

func DecodeInternalActorData(data io.Reader, e any) error

DecodeInternalActorData decodes encoding/gob data and stores the result in e.

func DecodeInternalActorReminderData added in v1.10.0

func DecodeInternalActorReminderData(data []byte, e any) error

DecodeInternalActorReminderData decodes internal actor reminder data payloads and stores the result in e.

func EncodeInternalActorData added in v1.10.0

func EncodeInternalActorData(result any) ([]byte, error)

EncodeInternalActorData encodes result using the encoding/gob format.

func NewHostedActors added in v1.12.0

func NewHostedActors(actorTypes []string) hostedActors

NewHostedActors creates a new hostedActors from a slice of actor types.

func ValidateHostEnvironment added in v0.11.2

func ValidateHostEnvironment(mTLSEnabled bool, mode modes.DaprMode, namespace string) error

ValidateHostEnvironment validates that actors can be initialized properly given a set of parameters And the mode the runtime is operating in.

Types

type ActorHostedRequest

type ActorHostedRequest struct {
	ActorID   string `json:"actorId"`
	ActorType string `json:"actorType"`
}

ActorHostedRequest is the request object for checking if an actor is hosted on this instance.

type ActorLock added in v1.2.0

type ActorLock struct {
	// contains filtered or unexported fields
}

func NewActorLock added in v1.2.0

func NewActorLock(maxStackDepth int32) *ActorLock

func (*ActorLock) Lock added in v1.2.0

func (a *ActorLock) Lock(requestID *string) error

func (*ActorLock) Unlock added in v1.2.0

func (a *ActorLock) Unlock()

type ActorRuntime added in v1.12.0

type ActorRuntime interface {
	Actors
	io.Closer
	Init(context.Context) error
	IsActorHosted(ctx context.Context, req *ActorHostedRequest) bool
	GetActiveActorsCount(ctx context.Context) []*runtimev1pb.ActiveActorsCount
	RegisterInternalActor(ctx context.Context, actorType string, actor InternalActor, actorIdleTimeout time.Duration) error
}

ActorRuntime is the main runtime for the actors subsystem.

func NewActors

func NewActors(opts ActorsOpts) ActorRuntime

NewActors create a new actors runtime with given config.

type Actors

type Actors interface {
	// Call an actor.
	Call(ctx context.Context, req *invokev1.InvokeMethodRequest) (*invokev1.InvokeMethodResponse, error)
	// GetState retrieves actor state.
	GetState(ctx context.Context, req *GetStateRequest) (*StateResponse, error)
	// GetBulkState retrieves actor state in bulk.
	GetBulkState(ctx context.Context, req *GetBulkStateRequest) (BulkStateResponse, error)
	// TransactionalStateOperation performs a transactional state operation with the actor state store.
	TransactionalStateOperation(ctx context.Context, req *TransactionalRequest) error
	// GetReminder retrieves an actor reminder.
	GetReminder(ctx context.Context, req *GetReminderRequest) (*internal.Reminder, error)
	// CreateReminder creates an actor reminder.
	CreateReminder(ctx context.Context, req *CreateReminderRequest) error
	// DeleteReminder deletes an actor reminder.
	DeleteReminder(ctx context.Context, req *DeleteReminderRequest) error
	// RenameReminder renames a reminder.
	// TODO: remove in Dapr 1.13.
	RenameReminder(ctx context.Context, req *RenameReminderRequest) error
	// CreateTimer creates an actor timer.
	CreateTimer(ctx context.Context, req *CreateTimerRequest) error
	// DeleteTimer deletes an actor timer.
	DeleteTimer(ctx context.Context, req *DeleteTimerRequest) error
}

Actors allow calling into virtual actors as well as actor state management.

type ActorsOpts added in v1.10.0

type ActorsOpts struct {
	AppChannel       channel.AppChannel
	GRPCConnectionFn GRPCConnectionFn
	Config           Config
	TracingSpec      configuration.TracingSpec
	Resiliency       resiliency.Provider
	StateStoreName   string
	CompStore        *compstore.ComponentStore
	Security         security.Handler

	// TODO: @joshvanl Remove in Dapr 1.12 when ActorStateTTL is finalized.
	StateTTLEnabled bool

	// MockPlacement is a placement service implementation used for testing
	MockPlacement internal.PlacementService
}

ActorsOpts contains options for NewActors.

type BulkStateResponse added in v1.12.0

type BulkStateResponse map[string][]byte

BulkStateResponse is the response returned from getting an actor state in bulk. It's a map where the key is the key of the state, and the value is the value as byte slice.

type Config

type Config struct {
	internal.Config
}

Config is the actor runtime configuration.

func NewConfig

func NewConfig(opts ConfigOpts) Config

NewConfig returns the actor runtime configuration.

func (*Config) GetDrainOngoingTimeoutForType added in v1.7.0

func (c *Config) GetDrainOngoingTimeoutForType(actorType string) time.Duration

func (*Config) GetDrainRebalancedActorsForType added in v1.7.0

func (c *Config) GetDrainRebalancedActorsForType(actorType string) bool

func (*Config) GetIdleTimeoutForType added in v1.7.0

func (c *Config) GetIdleTimeoutForType(actorType string) time.Duration

func (*Config) GetReentrancyForType added in v1.7.0

func (c *Config) GetReentrancyForType(actorType string) daprAppConfig.ReentrancyConfig

type ConfigOpts added in v1.10.0

type ConfigOpts struct {
	HostAddress        string
	AppID              string
	PlacementAddresses []string
	Port               int
	Namespace          string
	AppConfig          daprAppConfig.ApplicationConfig
	HealthHTTPClient   *http.Client
	HealthEndpoint     string
	AppChannelAddress  string
	PodName            string
}

ConfigOpts contains options for NewConfig.

type CreateReminderRequest

type CreateReminderRequest = internal.CreateReminderRequest

CreateReminderRequest is the request object to create a new reminder.

type CreateTimerRequest

type CreateTimerRequest = internal.CreateTimerRequest

CreateTimerRequest is the request object to create a new timer.

type DeleteReminderRequest

type DeleteReminderRequest = internal.DeleteReminderRequest

DeleteReminderRequest is the request object for deleting a reminder.

type DeleteStateRequest

type DeleteStateRequest struct {
	ActorID   string `json:"actorId"`
	ActorType string `json:"actorType"`
	Key       string `json:"key"`
}

DeleteStateRequest is the request object for deleting an actor state.

type DeleteTimerRequest

type DeleteTimerRequest = internal.DeleteTimerRequest

DeleteTimerRequest is a request object for deleting a timer.

type GRPCConnectionFn added in v1.10.0

type GRPCConnectionFn func(ctx context.Context, address string, id string, namespace string, customOpts ...grpc.DialOption) (*grpc.ClientConn, func(destroy bool), error)

GRPCConnectionFn is the type of the function that returns a gRPC connection

type GetBulkStateRequest added in v1.12.0

type GetBulkStateRequest struct {
	ActorID   string   `json:"actorId"`
	ActorType string   `json:"actorType"`
	Keys      []string `json:"keys"`
}

GetBulkStateRequest is the request object for getting bulk actor state.

func (GetBulkStateRequest) ActorKey added in v1.12.0

func (r GetBulkStateRequest) ActorKey() string

ActorKey returns the key of the actor for this request.

type GetReminderRequest

type GetReminderRequest = internal.GetReminderRequest

GetReminderRequest is the request object to get an existing reminder.

type GetStateRequest

type GetStateRequest struct {
	ActorID   string `json:"actorId"`
	ActorType string `json:"actorType"`
	Key       string `json:"key"`
}

GetStateRequest is the request object for getting actor state.

func (GetStateRequest) ActorKey added in v1.10.5

func (r GetStateRequest) ActorKey() string

ActorKey returns the key of the actor for this request.

type InternalActor added in v1.10.0

type InternalActor interface {
	SetActorRuntime(actorsRuntime Actors)
	InvokeMethod(ctx context.Context, actorID string, methodName string, data []byte) (any, error)
	DeactivateActor(ctx context.Context, actorID string) error
	// InvokeReminder invokes reminder logic for an internal actor.
	// Note that the DecodeInternalActorReminderData function should be used to decode the [data] parameter.
	InvokeReminder(ctx context.Context, actorID string, reminderName string, data []byte, dueTime string, period string) error
	InvokeTimer(ctx context.Context, actorID string, timerName string, params []byte) error
}

InternalActor represents the interface for invoking an "internal" actor (one which is built into daprd directly).

type OperationType

type OperationType string

OperationType describes a CRUD operation performed against a state store.

const (
	// Upsert is an update or create operation.
	Upsert OperationType = "upsert"
	// Delete is a delete operation.
	Delete OperationType = "delete"
)

type ReminderResponse

type ReminderResponse struct {
	Data    any    `json:"data"`
	DueTime string `json:"dueTime"`
	Period  string `json:"period"`
}

ReminderResponse is the payload that is sent to an Actor SDK API for execution.

func (*ReminderResponse) MarshalJSON added in v1.10.6

func (r *ReminderResponse) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaler that encodes the data as JSON. Actor SDKs expect "data" to be a base64-encoded message with the JSON representation of the data, so this makes sure that happens. This method implements the json.Marshaler interface.

type RenameReminderRequest added in v1.6.0

type RenameReminderRequest = internal.RenameReminderRequest

RenameReminderRequest is the request object for rename a reminder.

type SaveStateRequest

type SaveStateRequest struct {
	ActorID   string `json:"actorId"`
	ActorType string `json:"actorType"`
	Key       string `json:"key"`
	Value     any    `json:"value"`
}

SaveStateRequest is the request object for saving an actor state.

type StateOperationOpts added in v1.10.5

type StateOperationOpts struct {
	Metadata    map[string]string
	ContentType *string

	// TODO: @joshvanl Remove in Dapr 1.12 when ActorStateTTL is finalized.
	StateTTLEnabled bool
}

Options for the StateOperation method

type StateResponse

type StateResponse struct {
	Data     []byte            `json:"data"`
	Metadata map[string]string `json:"metadata"`
}

StateResponse is the response returned from getting an actor state.

type TimerResponse

type TimerResponse struct {
	Callback string `json:"callback"`
	Data     any    `json:"data"`
	DueTime  string `json:"dueTime"`
	Period   string `json:"period"`
}

TimerResponse is the response object send to an Actor SDK API when a timer fires.

func (*TimerResponse) MarshalJSON added in v1.10.6

func (t *TimerResponse) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaler that encodes the data as JSON. Actor SDKs expect "data" to be a base64-encoded message with the JSON representation of the data, so this makes sure that happens. This method implements the json.Marshaler interface.

type TransactionalDelete

type TransactionalDelete struct {
	Key  string  `json:"key"`
	ETag *string `json:"etag,omitempty"`
}

TransactionalDelete defined a delete operation.

func (TransactionalDelete) StateOperation added in v1.10.5

func (t TransactionalDelete) StateOperation(baseKey string, opts StateOperationOpts) (op state.TransactionalStateOperation, err error)

StateOperation returns the state.TransactionalStateOperation object.

type TransactionalOperation

type TransactionalOperation struct {
	Operation OperationType `json:"operation"`
	Request   any           `json:"request"`
}

TransactionalOperation is the request object for a state operation participating in a transaction.

func (TransactionalOperation) StateOperation added in v1.10.5

func (t TransactionalOperation) StateOperation(baseKey string, opts StateOperationOpts) (op state.TransactionalStateOperation, err error)

StateOperation returns the state.TransactionalStateOperation object.

type TransactionalRequest

type TransactionalRequest struct {
	Operations []TransactionalOperation `json:"operations"`
	ActorType  string
	ActorID    string
}

TransactionalRequest describes a set of stateful operations for a given actor that are performed in a transactional manner.

func (TransactionalRequest) ActorKey added in v1.10.5

func (r TransactionalRequest) ActorKey() string

ActorKey returns the key of the actor for this request.

type TransactionalUpsert

type TransactionalUpsert struct {
	Key      string            `json:"key"`
	Value    any               `json:"value"`
	ETag     *string           `json:"etag,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

TransactionalUpsert defines a key/value pair for an upsert operation.

func (TransactionalUpsert) StateOperation added in v1.10.5

func (t TransactionalUpsert) StateOperation(baseKey string, opts StateOperationOpts) (op state.TransactionalStateOperation, err error)

StateOperation returns the state.TransactionalStateOperation object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL