Stateful Function
StatefulFunction(key, function_name, partition, operator_name, operator_state, networking, dns, t_id, request_id, fallback_mode, use_fallback_cache, partitioner, protocol)
¶
Bases: Function
Encapsulates a stateful function in a distributed Styx operator.
This class wraps user-defined functions with access to state, networking, partitioning, and chain coordination. It supports fallback execution and asynchronous remote function chaining.
Initializes a stateful function with execution context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Any
|
The key of the function. |
required |
function_name
|
str
|
Name of the user-defined function. |
required |
partition
|
int
|
Partition ID where this function will execute. |
required |
operator_name
|
str
|
Name of the operator this function belongs to. |
required |
operator_state
|
BaseOperatorState
|
The state backend to use. |
required |
networking
|
NetworkingManager
|
Handles communication and coordination. |
required |
dns
|
dict
|
Mapping of operator partitions to worker locations. |
required |
t_id
|
int
|
Transaction ID. |
required |
request_id
|
bytes
|
Unique identifier for this function invocation. |
required |
fallback_mode
|
bool
|
Whether to enable fallback (recovery) logic. |
required |
use_fallback_cache
|
bool
|
Whether to use cached fallback results. |
required |
partitioner
|
BasePartitioner
|
The partitioning strategy. |
required |
protocol
|
BaseTransactionalProtocol
|
Protocol for function invocation. |
required |
data
property
¶
dict: All state associated with the current operator, and partition.
key
property
¶
The key for this function instance.
call_remote_async(operator_name, function_name, key, params=tuple())
¶
Queues a remote asynchronous function call.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator_name
|
str
|
Name of the target operator. |
required |
function_name
|
Type | str
|
Function type or name to invoke. |
required |
key
|
Any
|
Key for the remote call. |
required |
params
|
tuple
|
Parameters for the remote function call. |
tuple()
|
get()
¶
Retrieves the value from state for the current key.
Returns:
Name | Type | Description |
---|---|---|
object |
Any
|
The current value associated with the key. |
put(value)
¶
Stores a value in the state for the current key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
The value to store. |
required |