VolatileActorStateProvider Class

定义

ActorStateProvider implementation for Volatile persistence i.e Actor state is kept in-memory only.

public class VolatileActorStateProvider implements ActorStateProvider,StateProvider
继承
java.lang.Object
VolatileActorStateProvider

构造函数

VolatileActorStateProvider()

Creates an instance of VolatileActorStateProvider.

VolatileActorStateProvider(ReplicatorSettings replicatorSettings)

Creates an instance of VolatileActorStateProvider with specified replicator settings.

方法

abort()

Forcefully abort the state provider replica.

Remarks:This generally occurs when a permanent fault is detected on the node, or when Service Fabric cannot reliably manage the replica's life-cycle due to internal failures.

actorActivatedAsync(ActorId actorId, CancellationToken cancellationToken)

This method is invoked as part of the activation process of the actor with the specified Id.

backupAsync(BackupOption option, Duration timeout, CancellationToken cancellationToken, BiFunction<BackupInfo, CancellationToken, CompletableFuture<Boolean>> backupCallback)

Performs a full backup of state managed by this actor state provider

Remarks:Backup/restore is not supported by VolatileActorStateProvider.

backupAsync(BiFunction<BackupInfo, CancellationToken, CompletableFuture<Boolean>> backupCallback)

Performs a full backup of state managed by this actor state provider

Remarks:Backup/restore is not supported by VolatileActorStateProvider.

changeRoleAsync(ReplicaRole newRole, CancellationToken cancellationToken)

Notify the state provider replica that its role is changing, for example to Primary or Secondary.

closeAsync(CancellationToken cancellationToken)

Gracefully close the state provider replica.

Remarks:This generally occurs when the replica's code is being upgrade, the replica is being moved due to load balancing, or a transient fault is detected.

containsStateAsync(ActorId actorId, String stateName, CancellationToken cancellationToken)

Checks whether actor state provider contains an actor state with specified state name.

currentReplicaRole()
deleteReminderAsync(ActorId actorId, String reminderName, CancellationToken cancellationToken)

Deletes the specified actor reminder if it exists.

deleteRemindersAsync(Map<ActorId, Collection<String>> reminderNames, CancellationToken cancellationToken)

Deletes the specified set of reminders

enumerateStateNamesAsync(ActorId actorId, CancellationToken cancellationToken)

Creates an enumerable of all the state names associated with specified actor.

Remarks:The enumerator returned from actor state provider is safe to use concurrently with reads and writes to the state provider. It represents a snapshot consistent view of the state provider.

getActorsAsync(int itemsCount, ContinuationToken continuationToken, CancellationToken cancellationToken)

Gets ActorIds from the State Provider.

Remarks: The

getCopyContext()

Obtains context on a Secondary replica after it is created and opened to send context to the Primary replica.

Remarks:The Primary replica analyzes the context and sends back state via StateProvider#getCopyState(SequenceNumber, OperationDataStream). StateProvider#getCopyContext() is called on newly created, idle Secondary replicas and provides a mechanism to asynchronously establish a bidirectional conversation with the Primary replica. The Secondary replica sends OperationData objects with which the Primary replica can determine the progress of collecting context on the Secondary replica. The Primary replica responds by sending the required state back. See StateProvider#getCopyState(SequenceNumber, OperationDataStream) at the Primary replica for the other half of the exchange. For in-memory services, the StateProvider#getCopyContext() method is not called, as the state of the Secondary replicas is known (they are empty and will require all of the state).

getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext)

Obtains state on a Primary replica that is required to build a Secondary replica.

Remarks:Just as StateProvider#getCopyContext() enables the Secondary replica to send context to the Primary replica via an OperationDataStream, StateProvider#getCopyState(SequenceNumber, OperationDataStream) enables the Primary replica to respond with an OperationDataStream. The stream contains objects that are delivered to the Secondary replica via the StateReplicator#getCopyStream() method of the FabricReplicator class. The objects implement Operation and contain the specified data. When the Primary replica receives this call, it should create and return another OperationDataStream that contains OperationData. OperationData represents the data/state that the Secondary replica

getLastCommittedSequenceNumber()

Obtains the last sequence number that the service has committed.

Remarks:This method is called on a service when it first starts up, in case it has any persistent state, and when data loss is suspected. When a stateful service replica starts up, it has the option to restore any data that might have persisted from previous updates. If it restores some state in this manner, its current progress is the last written sequence number for that data. A volatile service can simply return 0. Note that this method is not called to determine a new primary election during fail-over, because the current committed progress is already known by the FabricReplicator class at that time.

initialize(ActorTypeInformation actorTypeInformation)

Initializes the actor state provider with type information of the actor type associated with it.

initialize(StatefulServiceInitializationParameters initializationParameters)

Initialize the state provider replica using the service initialization information.

Remarks:No complex processing should be done during Initialize. Expensive or long-running initialization should be done in OpenAsync.

loadRemindersAsync(CancellationToken cancellationToken)

Loads all the reminders contained in the actor state provider.

loadStateAsync(ActorId actorId, String stateName, CancellationToken cancellationToken)

Loads the actor state associated with the specified state name.

onDataLossAsync(CancellationToken cancellationToken)

Indicates that a write quorum of replicas in this replica set has been lost, and that therefore data loss might have occurred. The replica set consists of a majority of replicas, which includes the Primary replica.

Remarks:When the Service Fabric runtime observes the failure of a quorum of replicas, which includes the Primary replica, it elects a new Primary replica and immediately calls this method on the new Primary replica. A Primary replica that is informed of possible data loss can choose to restore its state from some external data source or can continue to run with the state that it currently has. If the service continues to run with its current state, it should return false from this method, which indicates that no state change has been made. If it has restored or altered its state, such as rolling back incomplete work, it should return true. If true is returned, then the state in other replicas must be assumed to be incorrect. Therefore, the Service Fabric runtime removes the other replicas from the replica set and recreates them.

onSnapshotAsync(Duration currentLogicalTime)
openAsync(ReplicaOpenMode openMode, StatefulServicePartition partition, CancellationToken cancellationToken)

Open the state provider replica for use.

Remarks:Extended state provider initialization tasks can be started at this time.

reminderCallbackCompletedAsync(ActorId actorId, ActorReminder reminder, CancellationToken cancellationToken)

Invoked when a reminder fires and finishes executing its callback Remindable#receiveReminderAsync successfully

removeActorAsync(ActorId actorId, CancellationToken cancellationToken)

Removes all the existing states and reminders associated with specified actor atomically.

restoreAsync(String backupFolderPath)

Restore a backup taken by microsoft.servicefabric.data.StateProviderReplica#backupAsync(BiFunction) or microsoft.servicefabric.data.StateProviderReplica#backupAsync(BackupOption, Duration, CancellationToken, BiFunction)Remarks:Backup/restore is not supported by VolatileActorStateProvider.

restoreAsync(String backupFolderPath, RestorePolicy restorePolicy, Duration timeout, CancellationToken cancellationToken)

Restore a backup taken by microsoft.servicefabric.data.StateProviderReplica#backupAsync(BiFunction) or microsoft.servicefabric.data.StateProviderReplica#backupAsync(BackupOption, Duration, CancellationToken, BiFunction)Remarks:Backup/restore is not supported by VolatileActorStateProvider.

saveReminderAsync(ActorId actorId, ActorReminder reminder, CancellationToken cancellationToken)

Saves the specified actor reminder. If an actor reminder with given name does not exist, it adds the actor reminder otherwise existing actor reminder with same name is updated.

saveStateAsync(ActorId actorId, List<ActorStateChange> stateChanges, CancellationToken cancellationToken)

Saves the specified set of actor state changes atomically.

setOnDataLossCallback(Function<CancellationToken, CompletableFuture<Boolean>> onDataLossAsync)

Function called during suspected data-loss

traceId()
traceType()
transientErrorRetryDelay()
updateEpochAsync(Epoch epoch, SequenceNumber previousEpochLastSequenceNumber, CancellationToken cancellationToken)

Indicates to a replica that the configuration of a replica set has changed due to a change or attempted change to the Primary replica. The change occurs due to failure or load balancing of the previous Primary replica. Epoch changes act as a barrier by segmenting operations into the exact configuration periods in which they were sent by a specific Primary replica.

Remarks:This method is called because the Primary replica of the replica set has changed, or a change was attempted. Secondary replicas receive this method either when they are about to become the new Primary replica, or, if they are not the new Primary replica, they receive it when they attempt to get the first operation from the new Primary replica from the replication stream. Primary replicas might occasionally receive this method if there is an attempt to swap the Primary replica, which fails. The information in the StateProvider#updateEpochAsync(Epoch, SequenceNumber, CancellationToken) method enables the service to maintain a progress vector, which is a list of each epoch that the replica has received, and the maximum LSN that they contained. The progress vector data along with the current applied maximum LSN is useful for a Secondary replica to send during the copy operation to describe how far the operation has progressed. Comparing progress vectors that are received from Secondary replicas during the copy operation enables Primary replicas to determine whether the Secondary replica is up-to-date, what state must be sent to the Secondary replica, and whether the Secondary replica has made false progress. False progress means that an LSN in a previous epoch was greater than the LSN that the Primary replica receives.

适用于