从 Azure 云表删除时出错 - ResourceNotFound

2023-12-05

我在从天蓝色表中删除对象时遇到间歇性问题。它只影响我大约 1% 的尝试,如果稍后再次进行相同的调用,那么它工作正常,但我很想找出背后的原因!我在谷歌上搜索了一下,发现缺乏关于如何创建非常可靠的删除、插入和更新代码的文档,这令人非常惊讶……这一切似乎有点碰运气,”尝试一下,大多数时候都会有效”

编辑:我正在删除这个问题中最初的文本,并将其替换为全新的文本,以考虑我已经尝试/建议的内容。

Azure 表是否会像 SQL Azure 一样遭受间歇性故障。如果是这样,我会认为“saveChangesWithRetries”会处理这个问题吗?这是错误的吗?

所以...相当简单的代码,在 Azure Web 角色上每分钟被调用大约 250 次。天蓝色表用作消息传递系统的一部分。消息由一个用户插入,由另一个用户下载,成功下载后,这些消息将被标记为已读。

每个用户都有一个未读消息分区和已读消息分区。因此,要将消息标记为“已读”,请将其从未读分区中删除并移动到已读分区中。

在每分钟调用此代码 250 次的情况下,我将在最终的 SaveChangesWithRetries() 中收到 2 到 10 个以下错误。内部异常是:

ResourceNotFound这 指定的资源不存在。 请求ID:652a3e13-3911-4503-8e49-6fec32a3c044 时间:2011-09-28T22:09:39.0795651Z

我不认为单个分区每分钟被访问的次数不会超过几次。

这是我的代码:

    public static void Message_MarkAsRead(int uid)
    {
        try
        {
            storageAccount = CloudStorageAccount.Parse(connectionString);
            tableClient = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials);
            tableClient.RetryPolicy = RetryPolicies.Retry(retryAmount, TimeSpan.FromSeconds(retrySeconds));

            TableServiceContext tableServiceContext = tableClient.GetDataServiceContext();
            tableServiceContext.IgnoreResourceNotFoundException = true;

            //the messageUserJoinerTable let's us join messageId to userFromId and userToId
            //each message is inserted into the tables twice, once into the userFromId partition and also into the userToId partition
            #region get the userToId and userFromId for this message uid
            List<int> userIds = new List<int>();
            var resultsUserIds = from messagesUserJoinerTable in tableServiceContext.CreateQuery<MessageUserJoinerDataEntity>(messageUserJoinerTableName)
                                where messagesUserJoinerTable.PartitionKey == uid.ToString()
                                select messagesUserJoinerTable;

            foreach (MessageUserJoinerDataEntity messageUserJoiner in resultsUserIds)
            {
                userIds.Add(messageUserJoiner.UserId);
            }
            #endregion

            #region then we need to check the partition for each of these users and mark the messages as read
            if (userIds.Count > 0)
            {
                foreach (int userId in userIds)
                {
                    var resultsUnreadMessages = from messagesTable in tableServiceContext.CreateQuery<MessageDataEntity>(messageTableName)
                                                where messagesTable.PartitionKey == CreatePartitionKey(userId, false)
                                                && messagesTable.RowKey == CreateRowKey(uid)
                                                select messagesTable;

                    //there should only ever be one as duplicate partition/rowkey is not allowed
                    MessageDataEntity messageUnread = resultsUnreadMessages.FirstOrDefault();

                    if (messageUnread != null)
                    {
                        bool isUnreadMessageDeleted = false;

                        //shallow copy the message for re-inserting as read
                        MessageDataEntity messageRead = new MessageDataEntity(messageUnread);

                        //delete the message
                        try
                        {
                            tableServiceContext.Detach(messageUnread);
                            tableServiceContext.AttachTo(messageTableName, messageUnread, "*");
                            tableServiceContext.DeleteObject(messageUnread);
                            //this is where the error occurs
                            tableServiceContext.SaveChangesWithRetries();

                            isUnreadMessageDeleted = true;
                        }
                        catch (Exception ex)
                        {
                            MyTrace.Trace("AzureCloudTable_" + Service.versionForTracing + ".Message_MarkAsRead. Error.Stage.1: MessageID:" + uid + ", UserID:" + userId + ". " + ex.Message + ex.StackTrace + ", " + ex.InnerException.Message + ex.InnerException.StackTrace, "Error. MarkAsRead");

                            //check to see if the message we tried to delete has already been deleted
                            //if so, we just consume this error and continue by inserting the read message
                            //else, we throw the exception outwards
                            var resultsUnreadMessagesLastCheck = from messagesTable in tableServiceContext.CreateQuery<MessageDataEntity>(messageTableName)
                                                                 where messagesTable.PartitionKey == CreatePartitionKey(userId, false)
                                                                 && messagesTable.RowKey == CreateRowKey(uid)
                                                                 select messagesTable;

                            //there should only ever be one as duplicate partition/rowkey is not allowed
                            MessageDataEntity messageUnreadLastCheck = resultsUnreadMessages.FirstOrDefault();

                            if (messageUnreadLastCheck != null)
                            {
                                MyTrace.Trace("AzureCloudTable_" + Service.versionForTracing + ".Message_MarkAsRead. Error.Stage.2: MessageID:" + uid + ", UserID:" + userId + ". Message WAS deleted.", "Error. MarkAsRead");

                                //the message IS deleted, so although I don't understand why getting error in the first 
                                //place, the result should be the same
                                throw ex;
                            }
                            else
                            {
                                //the message is NOT deleted, so we may as well give up now as I don't understand
                                //what's going on
                                MyTrace.Trace("AzureCloudTable_" + Service.versionForTracing + ".Message_MarkAsRead. Error.Stage.2: MessageID:" + uid + ", UserID:" + userId + ". Message was NOT deleted.", "Error. MarkAsRead");
                            }
                        }

                        //mark the new message as read
                        if (isUnreadMessageDeleted)
                        {
                            messageRead.PartitionKey = CreatePartitionKey(userId, true);
                            messageRead.IsRead = true;

                            //check if read message already exists in storage, if not, insert
                            var resultsReadMessages = from messagesTable in tableServiceContext.CreateQuery<MessageDataEntity>(messageTableName)
                                                      where messagesTable.PartitionKey == CreatePartitionKey(userId, true)
                                                      && messagesTable.RowKey == CreateRowKey(uid)
                                                      select messagesTable;

                            //do the insert
                            if (resultsReadMessages.FirstOrDefault() == null)
                            {
                                tableServiceContext.AddObject(messageTableName, messageRead);
                                tableServiceContext.SaveChangesWithRetries();
                            }
                        }
                    }
                }
            }
            #endregion
        }
        catch (Exception ex)
        {
            try
            {
                MyTrace.Trace("AzureCloudTable_" + Service.versionForTracing + ".Message_MarkAsRead. Error: " + ex.Message + ex.StackTrace + ", " + ex.InnerException.Message + ex.InnerException.StackTrace, "Error. MarkAsRead");
            }
            catch (Exception)
            {
                MyTrace.Trace("AzureCloudTable_" + Service.versionForTracing + ".Message_MarkAsRead. Error: " + ex.Message + ex.StackTrace, "Error. MarkAsRead");
            }
        }
    }

我不明白当资源作为查询的一部分返回给我,然后我对其进行了 != null 检查时,资源怎么可能不存在。

根据之前的回复,我添加了代码来在尝试中进行额外的检查,以查看该对象是否已被以某种方式删除。尚未删除

我的跟踪在出现错误时返回此信息:

AzureCloudTable_3_0_5.Message_MarkAsRead。错误.阶段 1:消息 ID:146751012,男孩 ID:477296。处理此请求时发生错误。在 Microsoft.WindowsAzure.StorageClient.Tasks.Task1.get_Result() at Microsoft.WindowsAzure.StorageClient.Tasks.Task1.BenderRestfulService_3_0_5.AzureCloudTable.Message_MarkAsRead(Int32 uid) 处的 ExecuteAndWait() ...ResourceNotFound指定的资源不存在。 RequestId:583c59df-fdac-47e4-a03c-7a4bc7d004c9 时间:2011-10-05T16:37:36.7940530Z 在 System.Data.Services.Client.DataServiceContext.SaveResult.d__1e.MoveNext()

AzureCloudTable_3_0_5.Message_MarkAsRead。错误.阶段 2:消息 ID:146751012,男孩 ID:477296。消息未被删除。

我完全困惑了。任何建议都非常感谢!

Steven


此代码是否在多个角色实例或多个应用程序中运行? (也许在您从表中读取实体的时间和尝试删除它的时间之间,另一个进程正在删除该实体。)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 Azure 云表删除时出错 - ResourceNotFound 的相关文章

随机推荐

  • 需要帮助使用泰勒级数逼近Python中的正弦函数

    我对 Python 很陌生 我正在尝试使用近似正弦函数this series 我的代码如下所示 import math def sin x n sine 0 for i in range n sign 1 i sine sine x 2 0
  • 测试一个数字是否是斐波那契数

    我知道如何制作斐波那契数列 但我不知道如何测试给定的数字是否属于斐波那契数列 我想到的一种方法是生成斐波那契数列 数字到该数字并查看它是否属于该数组 但必须有另一种更简单 更快的方法 有任何想法吗 一个非常好的测试是 N 是斐波那契数当且仅
  • 如何使用命令提示符连接到 mysql 服务器:错误

    我正在使用以下命令使用命令提示符连接到数据库 mysql mysql h localhost u test ptest test 但我收到以下错误 ERROR 1064 42000 You have an error in your SQL
  • Laravel 资源中的附加数据

    我使用控制器中的 Laravel 资源 data Project limit 100 gt get return response gt json ProjectResource collection data 我喜欢将附加信息传递给 Pr
  • Android:检查活动是否被系统从服务中销毁

    我有一项服务监听来自服务器的一些事件 服务有 START STICKY 标志 当它被操作系统杀死时 该标志使他重新启动 当服务收到事件时 我有两种情况 首先 如果活动没有被终止 我需要将结果发送到本地广播接收器并更新 UI 其次 如果它被操
  • 添加表单操作[关闭]

    Closed 这个问题需要细节或清晰度 目前不接受答案 当我提交时我试图再次转到index php page servers 但是当我提交表单时重定向是index php 但实际上是index php page servers 我该如何解决
  • Chrome 扩展:检测 Google 文档中的按键

    嘿 我和我的朋友们刚接触 javascript 并且遇到了一些代码问题 目前 我们正在尝试制作一个 Chrome 扩展 通过检测击键来检测用户何时以及对特定 google 文档进行了多少操作 我们当前的方法涉及创建一个 按键 事件监听器 我
  • Codeigniter SMTP 无法连接

    我正在使用 Codeigniter 3 并且我的网站上有一个简单的联系表 此联系表单在我的本地主机 XAMPP 环境中完美运行 但在我的共享 Web 托管 BT 上却不起作用 我无法弄清楚问题是什么 我一直在与他们的支持人员联系 显然 如果
  • site_url() 在 codeigniter 框架中无法正常工作

    以下代码对于 Codeigniter 框架无法正常工作 这是我的观点 a href gt Back to Main a 您应该在控制器构造方法或像这样调用视图的函数中加载 url helper this gt load gt helper
  • 在 AngularJS 中的页面之间共享数据返回空

    通常 我编写 SPA 并且通过服务在控制器之间共享数据很简单 我没有使用 SPA 格式 没有使用 ng view 并尝试在页面之间共享数据 但在加载第二个页面 以获取数据 时它是空的 第 1 页 索引 html div div
  • fastapi (starlette) RedirectResponse 重定向到 post 而不是 get 方法

    返回 RedirectResponse 对象后 我遇到了奇怪的重定向行为 事件 py router APIRouter router post create response model EventBase async def event
  • Android 更改小部件背景图片

    在过去的两天里 我一直在努力改变我的小部件的背景 基于一些 if 语句 现在删除 只是想从类中更改小部件背景 下面是我的源代码 不过 怎么了 我之前已经更改了图像 例如背景 但无法让它适用于我的小部件 谢谢 顺便说一句 这是我最近的尝试 W
  • 如何根据产品类别在 WooCommerce 添加到购物车按钮下方添加文本

    我尝试在某些类别的产品页面上的 WooCommerce 添加到购物车按钮下方添加一个 div 我在这里有点不知所措 这段代码没有破坏任何东西 但文本没有显示 我试过了 woocommerce div product form cart af
  • (flask)-sqlalchemy查询,必须导入所有模型

    我对 Flask 和 Flask SQLAlchemy 有一个问题 对于任何查询 我都需要导入所有相关模型 现在我的 auth views py 看起来像这样 编程的前几行所以只是一个测试视图 from flask import jsoni
  • 如何使用 jQuery 动态添加组合框

    我有这个正在创建的工作代码one组合框 你可以在这里看到它的工作原理 jsfiddle body on change combo function var selectedValue this val if this find option
  • 使用 django-allauth 注册后阻止用户登录

    我正在为我的 django 应用程序使用 django allauth 默认情况下 当用户成功注册时 他们会自动登录 如何覆盖默认行为并阻止用户在成功注册后登录 用户注册后 必须将他 她重定向到登录页面 我已禁用电子邮件验证 谢谢 sett
  • 合并大量 data.frames [重复]

    这个问题在这里已经有答案了 可能的重复 同时合并列表中的多个数据框 example data frames df1 data frame id c 1 73 2 10 43 v1 c 1 2 3 4 5 br df2 data frame
  • 检查 kubectl 版本时出现“身份验证为:您所在的匿名组”错误

    我正在尝试在我的计算机中设置 kubectl 工具来远程管理 Kubernetes 集群并使用 Helm 我正在 Ubuntu 16 04 机器上尝试 我通过以下链接关注官方 Kubernetes 文档 https kubernetes i
  • 将日历设置为下周四

    我正在 Android 中开发一个应用程序 该应用程序的服务必须在每周四和周日 22 00 执行 我真正需要的是将日历设置为该日期和时间 但是 我不确定该怎么做 Calendar calendar Calendar getInstance
  • 从 Azure 云表删除时出错 - ResourceNotFound

    我在从天蓝色表中删除对象时遇到间歇性问题 它只影响我大约 1 的尝试 如果稍后再次进行相同的调用 那么它工作正常 但我很想找出背后的原因 我在谷歌上搜索了一下 发现缺乏关于如何创建非常可靠的删除 插入和更新代码的文档 这令人非常惊讶 这一切