title | reviewed | component |
---|---|---|
Service Fabric Persistence Sagas |
2020-11-26 |
ServiceFabricPersistence |
Saga data is stored in reliable dictionaries.
Saga data is stored in JSON format using Json.NET.
Saga data serialization can be configured by providing a custom JsonSerializerSettings instance.
snippet: ServiceFabricPersistenceSagaJsonSerializerSettings
A custom JsonReader instance:
snippet: ServiceFabricPersistenceSagaReaderCreator
Or a custom JsonWriter instance:
snippet: ServiceFabricPersistenceSagaWriterCreator
By default saga data is stored in multiple reliable collections - one per saga data type. Reliable collection names can be changed at the level of saga data type.
snippet: ServiceFabricPersistenceSagaWithCustomCollectionName
The saga data identifier that's used as a key in the reliable dictionary is calculated, amongst others, from the saga data type name. As a result, renaming the saga data class name changes the storage identifier for every saga data instance. This is a problem especially when there are active saga instances stored for a given saga data type. In such scenarios it is necessary to provide a stable saga data type name:
snippet: ServiceFabricPersistenceSagaWithCustomSagaDataName
When simultaneously handling messages, conflicts may occur. Below is a list of examples of exception that may be thrown Saga concurrency explains how these conflicts are handled, and contains guidance for high-load scenarios.
Example exception:
The saga with the correlation id 'Name: {correlationProperty.Name} Value: {correlationProperty.Value}' already exists.
Starting from version 2.2, ServiceFabric persistence uses LockMode.Update
to acquire an exclusive lock when updating or deleting saga data. The saga persister tries to acquire an exclusive lock on the saga data for up to four seconds. If, within this time period, an exclusive lock cannot be acquired, a TimeoutException
is thrown and regular message retry policies are applied.
Example exception:
System.TimeoutException: Timed out waiting for Update lock on key; id=730ed849-8996-420f-9abf-e92a6f09585c@132240668520425409@urn:SagaData/dataStore@132240668616392434, timeout=100ms, txn=132240668619482431, lockResourceNameHash=304025969650383958; oldest txn with lock=132240668619502450 (mode Update)
In versions prior to 2.2, ServiceFabric persistence uses optimistic concurrency control when updating or deleting saga data.
Example exception:
{nameof(SagaPersister)} concurrency violation: saga entity Id[{sagaData.Id}] already saved.
include: saga-concurrency