用于处理Azure表并发冲突的通用代码?
我正在考虑对 Azure 存储表进行一些更新。我想正确使用乐观并发机制。似乎您需要执行以下操作:
- 加载要更新的行,可能会重试失败
- 将更新应用于行
- 保存行,可能会重试网络错误
- 如果存在并发冲突,则重新加载数据(可能重试失败)并尝试再次保存(可能重试失败)
是否有一些通用类或代码示例可以处理此问题?我可以将其编码,但我必须想象有人已经发明了这个特殊的轮子。
I'm looking at doing some updates into Azure Storage Tables. I want to use the optimistic concurrency mechanism properly. It seems like you'd need to do something like:
- Load row to update, possibly retrying failures
- Apply updates to row
- Save row, possibly retrying network errors
- If there is a concurrency conflict, reload the data (possibly retrying failures) and attempt to save again (possible retrying failures)
Is there some generic class or code sample that handles this? I can code it up, but I have to imagine someone has already invented this particular wheel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人发明了这个轮子,他们不会说话,所以我自己(重新)发明了它。这是故意非常通用的,更像是一个骨架而不是成品。它基本上就是我上面概述的算法。调用者必须连接委托来执行数据的实际加载、更新和保存。内置了基本的重试逻辑,但我建议用更强大的东西覆盖这些函数。
我相信这适用于表或 BLOB,以及单个实体或批次,尽管我实际上只尝试过单实体表更新。
任何意见、建议、改进等将不胜感激。
If someone invented this wheel they're not talking, so I went off and (re)invented it myself. This is intentionally very generic, more of a skeleton than a finished product. It's basically just the algorithm I outlined above. The caller has to wire in delegates to do the actual loading, updating and saving of the data. There is basic retry logic built in, but I would recommend overriding those functions with something more robust.
I believe this will work with tables or BLOBs, and single entities or batches, though I've only actually tried it with single-entity table updates.
Any comments, suggestions, improvements, etc would be appreciated.