[英]Not able to run Cosmos DB Change Feed Trigger Azure Function locally
[英]Cosmos DB Change Feed Trigger Azure Function: Lease Lost Exception
以下異常記錄在 Cosmos DB 更改提要觸發 azure 函數的應用程序洞察中:
Microsoft.Azure.Documents.ChangeFeedProcessor.Exceptions.LeaseLostException
[{"severityLevel":"Error","outerId":"0","message":"租約丟失。","parsedStack":[{"assembly":"Microsoft.Azure.Documents.ChangeFeedProcessor, Version =2.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"Microsoft.Azure.Documents.ChangeFeedProcessor.LeaseManagement.DocumentServiceLeaseStoreManager+d__16.MoveNext","level":0,"line":0},{ "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":1,"line ":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","level ":2,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter .HandleNonSuccessAndDebuggerNotification","level":3,"line":0},{"assembly":"Microsoft.Azure.Doc uments.ChangeFeedProcessor, Version=2.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"Microsoft.Azure.Documents.ChangeFeedProcessor.PartitionManagement.PartitionController+d__9.MoveNext","level":4,"line" :0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level" :5,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Runtime.CompilerServices.TaskAwaiter。 ThrowForNonSuccess","level":6,"line":0},{"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System. Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":7,"line":0},{"assembly":"Microsoft.Azure.Documents.ChangeFeedProcessor, Version=2.2.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ,"method":"Microsoft.Azure.Document s.ChangeFeedProcessor.HealthMonitoringPartitionControllerDecorator+d__3.MoveNext","level":8,"line":0}],"type":"Microsoft.Azure.Documents.ChangeFeedProcessor.Exceptions.LeaseLostException","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.
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 是一個正常信號,表示當前實例擁有租約,但由於負載平衡(可能是另一個實例出現或實例數量發生變化),它被另一台主機占用。 這是在初始化期間(第一次啟動一組實例)或由於實例數量變化而重新平衡期間的預期。
用戶不需要做什么,因為這是正常生命周期的一部分。 租用現在由另一個實例處理,該實例將讀取租用范圍內的分區中發生的更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.