我们如何处理对 Azure 搜索文档的并发写入?
使用案例和问题
- 进行一次网络调用以将搜索中的文档提取到内存中,
- 然后更改内存中的该文档,
- 最后进行第二次网络调用以更新搜索中的该文档。
如果文档自步骤 (1) 以来发生了更改,我们如何保证步骤 (3) 失败。
在请求标头中使用 ETag 似乎是理想的选择。我们找到了关于对非文档资源(例如索引字段)执行此操作的文档,但我们发现对文档资源执行此操作的文档很少。
我们的研究
.NET v11
SearchClient
提供了用于更新和合并操作的 .NET 方法,但没有在这些方法的 XML 注释中明确提及并发性。在 v11
SearchClient
的源代码中,上传和合并操作都会调用IndexDocumentsInternal
。该方法没有显式使用 ETag(并且最终调用 REST API)。REST API 标头文档提到 ETags,它支持索引器、索引和数据源,但不支持文档。
REST API 响应文档 包括 409;但是,文档没有提供有关何时返回此响应的大量信息。 409 意味着在尝试索引文档时检测到版本冲突。当您尝试同时多次索引同一文档时,可能会发生这种情况。
此相关 SO 项目没有回答我们的问题:Azure 搜索是否提供 Etag 来管理添加、更新或删除文档的并发性?
Use Case and Question
- making one network call to fetch a document from search into memory,
- then changing that document in memory, and
- finally making a second network call to update that document in search.
How can we guarantee that step (3) fails if the document has changed since step (1).
Using an ETag in the request header seems ideal. We found docs on doing that for non-document resources (e.g., index fields), but we found scant documentation on doing that with document resources.
Our Research
The .NET v11
SearchClient
provides .NET methods for the update and the merge operations, but does not explicitly mention concurrency in the XML comments of those methods.In the source code for the v11
SearchClient
, both the upload and merge operations call intoIndexDocumentsInternal
. That method has no explicit ETag usage (and it ends up calling into the REST API).The REST API headers documentation says of ETags that it supports indexers, indexes, and data sources, but not documents.
The REST API response documentation includes a 409; however, the docs do not give a lot of information on when this response would be returned. The 409 means that a, version conflict was detected when attempting to index a document. This can happen when you're trying to index the same document more than once concurrently.
This related SO item does not answer our question: Does Azure Search Provides Etags for managing concurrency for Add, Update or Delete Documents?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论