如何延迟 Service Fabric 运行时自动升级

How to delay Service Fabric runtime automatic upgrades

我们的团队最近发生了一起事件,因为我们的无状态服务被重新启动以进行 Azure 运行时自动更新。其中一项服务在被强制关闭时正在处理任务。这些任务可能需要长达 4 个小时。

有没有办法通过代码或者配置让Azure知道我们的服务很忙,不能像这次那样关闭?

换句话说,我们如何让 Azure 知道我们的服务何时准备好进行服务结构运行时升级?

那么首先,你为什么不切换到手动升级模式?

其次,在 运行 长作业的情况下,您仍然必须考虑节点可能会失败,服务实例可能会移动或更改角色。如果您没有很好地处理关机通知,所有这些类型的事件都会终止您的长期 运行 工作。

Service Fabric 使用传递给 RunAsync 的 CancellationToken 向服务发出将关闭等信号。以下取from the docs:

Service Fabric changes the Primary of a stateful service for a variety of reasons. The most common are cluster rebalancing and application upgrade. During these operations (as well as during normal service shutdown, like you'd see if the service was deleted), it is important that the service respect the CancellationToken.

Services that do not handle cancellation cleanly can experience several issues. These operations are slow because Service Fabric waits for the services to stop gracefully.

this 对 RunAsync 方法说的相同但更短一些:

Make sure cancellationToken passed to RunAsync(CancellationToken) is honored and once it has been signaled, RunAsync(CancellationToken) exits gracefully as soon as possible.

在您的情况下,您应该对取消的 CancellationToken 采取行动。您应该以某种方式存储当前作业的状态,以便下次调用 RunAsync 时可以恢复它。

如果它确实是一项无法以任何方式中断和恢复的长期 运行 作业,您应该考虑在 Reliable Service 之外完成这项工作,例如 Web 作业或其他。或者接受一些工作可能会丢失。

换句话说,您不能告诉 Service Fabric 等待关闭您的服务。它也会破坏集群的平衡和可靠性。

https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-cluster-capacity#the-durability-characteristics-of-the-cluster

持久层权限允许 Service Fabric 暂停任何 VM 级别的基础结构请求(例如 VM 重启、VM 重新映像或 VM 迁移)

青铜级 - 无特权。这是默认值。 白银 - 每个 UD 可以暂停基础结构作业 10 分钟。 Gold - 每个 UD 可以暂停基础设施作业 2 小时。 Gold 耐久性只能在全节点 VM skus 上启用,例如 D15_V2、G5 等

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.servicefabric.models.nodetypedescription.durabilitylevel?view=azure-dotnet