StateProvider Interface

public interface StateProvider

Defines the behavior that a service must implement to interact with the FabricReplicator.

Method Summary

Modifier and Type Method and Description
OperationDataStream 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 getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext) . 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 getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext) at the Primary replica for the other half of the exchange. For in-memory services, the getCopyContext() method is not called, as the state of the Secondary replicas is known (they are empty and will require all of the state).

OperationDataStream getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext)

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

Remarks:Just as getCopyContext() enables the Secondary replica to send context to the Primary replica via an OperationDataStream, getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext) enables the Primary replica to respond with an OperationDataStream. The stream contains objects that are delivered to the Secondary replica via the 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

long getLastCommittedSequenceNumber()

Obtains the last sequence number that the service has committed.

CompletableFuture<Boolean> 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.

CompletableFuture<?> 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:The information in the updateEpochAsync(Epoch epoch, SequenceNumber previousEpochLastSequenceNumber, CancellationToken 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 the state of the replica. 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 a secondary replica reports an LSN in a previous epoch was greater than the LSN that the Primary replica has in its progress vector.

Method Details

getCopyContext

public OperationDataStream 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 getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext) . 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 getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext) at the Primary replica for the other half of the exchange. For in-memory services, the getCopyContext() method is not called, as the state of the Secondary replicas is known (they are empty and will require all of the state).

Returns:

getCopyState

public OperationDataStream getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext)

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

Remarks:Just as getCopyContext() enables the Secondary replica to send context to the Primary replica via an OperationDataStream, getCopyState(SequenceNumber upToSequenceNumber, OperationDataStream copyContext) enables the Primary replica to respond with an OperationDataStream. The stream contains objects that are delivered to the Secondary replica via the 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

Parameters:

upToSequenceNumber - The maximum last sequence number (LSN) that should be placed in the copy stream via the getCopyStream() method. LSNs greater than this number are delivered to the Secondary replica as a part of the replication stream via the getReplicationStream() method.
copyContext - An OperationDataStream that contains the OperationData objects that are created by the Secondary replica. requires to catch up to the provided

Returns:

getLastCommittedSequenceNumber

public long getLastCommittedSequenceNumber()

Obtains the last sequence number that the service has committed.

Returns:

Returns long.

onDataLossAsync

public CompletableFuture 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.

Parameters:

cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

Returns CompletableFuture of type java.lang.Boolean, that indicates whether the state provider as part of processing this notification has changed its state

updateEpochAsync

public CompletableFuture 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:The information in the updateEpochAsync(Epoch epoch, SequenceNumber previousEpochLastSequenceNumber, CancellationToken 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 the state of the replica. 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 a secondary replica reports an LSN in a previous epoch was greater than the LSN that the Primary replica has in its progress vector.

Parameters:

epoch - The new Epoch.
previousEpochLastSequenceNumber - The maximum sequence number (LSN) in the previous epoch.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

Returns CompletableFuture.

Applies to