Azure / service-fabric-rs

Service Fabric Rust
MIT License
6 stars 7 forks source link

Feature: Handle Cancel for IFabricAsyncOpertionContext #46

Closed youyuanwu closed 2 months ago

youyuanwu commented 4 months ago

In SF com api, cancellation is handled by IFabricAsyncOperationContext: https://github.com/Azure/service-fabric-rs/blob/acb9afc3fbf211803874480714e3a3f9f001efda/crates/libs/com/src/ServiceFabric/FabricCommon.rs#L216

The rust style wrapping of various SF com apis ignores this cancellation, and informs SF that the operation is not cancellable. Various Abort signals may also relate to cancellation.

In csharp api looks like this:

public System.Threading.Tasks.Task<System.Fabric.Query.NodeList> GetNodeListAsync (string nodeNameFilter, 
System.Fabric.Query.NodeStatusFilter nodeStatusFilter, string continuationToken, TimeSpan timeout, 
System.Threading.CancellationToken cancellationToken);

Where CancellationToken cancellationToken can trigger SF c++ to cancel the operation. In SF -> csharp code as well, CancellationToken is passed to tell csharp code to cancel.

For Rust, a similar api can be modeled follwoing csharp: Current Rust -> SF api:

    pub async fn get_node_list(
        &self,
        desc: &NodeQueryDescription,
        timeout: Duration,
    ) -> windows_core::Result<NodeList>

Proposed client api: Rust code can call token cancel to cancel SF operation.

    pub async fn get_node_list(
        &self,
        desc: &NodeQueryDescription,
        timeout: Duration,
        cancelation_token:  tokio_util::sync::CancellationToken
    ) -> windows_core::Result<NodeList>

Current sf->rust api

    async fn open(
        &self,
        openmode: OpenMode,
        partition: &StatefulServicePartition,
    ) -> windows::core::Result<impl PrimaryReplicator>;

Proposed sf -> rust api

    async fn open(
        &self,
        openmode: OpenMode,
        partition: &StatefulServicePartition,
        cancelation_token:  tokio_util::sync::CancellationToken
    ) -> windows::core::Result<impl PrimaryReplicator>;

When writing rust app, one can check if sf cancels the operation from cancelation_token.

youyuanwu commented 2 months ago

Completed in #65