Cosmos DB更改订阅源触发Azure功能:租约丢失异常



以下Cosmos DB应用程序洞察中记录的异常更改提要触发azure函数:

Microsoft.Azure.Documents.ChangeFeedProcessor.Exceptions.LeaseLostException

[{"严重级别":"错误","路由ID":"0","消息":"租约丢失&"parsedStack":[{"assembly":"Microsoft.Azure.Documents.ChangeFeedProcessor,版本=2.2.6.0,文化=中性,PublicKeyToken=31bf3856a364e35"方法":"Microsoft.Azure.Documents.ChangeFeedProcessor.LleaseManagement.DocumentServiceLeaseStoreManager+d__16.MoveNext"级别":0;行":0},{"assembly":"System.Private.CoreLib,版本=4.0.0.0,区域性=中性,PublicKeyToken=7cec85d7bea7798e"方法":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Sthrow"级别":1;行":0}、{"assembly":"System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e"方法":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess"级别":2;行":0}、{"assembly":"System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e"方法":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification"级别":3;行":0},{"assembly":"Microsoft.Azure.Documents.ChangeFeedProcessor,版本=2.2.6.0,文化=中性,PublicKeyToken=31bf3856a364e35"方法":"Microsoft.Azure.Documents.ChangeFeedProcessor.PartitionManagement.PartitionController+d__9.MoveNext"级别":4;行":0},{"assembly":"System.Private.CoreLib,版本=4.0.0.0,区域性=中性,PublicKeyToken=7cec85d7bea7798e"方法":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Sthrow"级别":5;行":0}、{"assembly":"System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e"方法":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess"级别":6;行":0}、{"assembly":"System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e"方法":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification"级别":7;行":0},{"assembly":"Microsoft.Azure.Documents.ChangeFeedProcessor,版本=2.2.6.0,文化=中性,PublicKeyToken=31bf3856a364e35"方法":"Microsoft.Azure.Documents.ChangeFeedProcessor.HealthMonitoringPartitionControllerDecorator+d_3.MoveNext"级别":8;行":0}],";类型":"Microsoft.Azure.Documents.ChangeFeedProcessor.Exceptions.LeaseLostException"quot;id":"517071〃}

Cosmos DB更改订阅源触发Azure功能:

public static class NotificationChangeFeed
{
[FunctionName(nameof(NotificationChangeFeed))]
public static async Task Run([CosmosDBTrigger(
databaseName: CosmosDBConstants.DataBaseName,
collectionName: CosmosDBConstants.NotificationContainer,
ConnectionStringSetting = CosmosDBConstants.ConnectionStringName,
CreateLeaseCollectionIfNotExists = true,
LeaseCollectionName = CosmosDBConstants.LeaseConainer)]IReadOnlyList<Document> input,
[Inject] ILoggingService loggingService,
[Inject] IEmailProcessor emailProcessor)
{
var logger = new Logger(loggingService);
try
{
if (input != null && input.Count > 0)
{
foreach (Document document in input)
{
string requestBody = document.ToString();
var notification = requestBody.AsPoco<Notification>();
await emailProcessor.HandleEmailAsync(notification, logger);
logger.Info($"Email Notification sent successfully for file name: {document.Id}");
}
}
}
catch (Exception ex)
{
logger.Error($"Unable to process Documents for Email Notification for Files: {input?.Count}", ex,
nameof(NotificationChangeFeed));
throw;
}
}
}

此错误意味着lease is lost, that would typically happen when it is taken by another host. Other cases: communication failure, number of retries reached, lease not found.

  • 处理租赁的首选方法是使用自动租赁Checkpoint实现(如果您正在使用manual checkpointing(
  • 您还可以检查是否存在租赁集合
LeaseLost是一个正常信号,表示当前实例拥有租约,但由于负载平衡(可能出现了另一个实例或实例数量发生了变化(,它被另一个主机占用。这在初始化期间(第一次启动一组实例(或由于实例数量的变化而在重新平衡期间是预期的。

用户不需要做任何事情,因为这是正常生命周期的一部分。租约现在由另一个实例处理,该实例将读取租约作用域所在分区中发生的更改。

最新更新