Azure Blob存储的事务访问 [英] Transactional Access of Azure Blob Storage

查看:67
本文介绍了Azure Blob存储的事务访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件存储在Azure Blob存储中.到目前为止,一切都很好.我还想存储有关文件的其他元数据.为此,我使用了Azure SQL数据库(因此我可以轻松查询blob存储中的文件).

I would like to store files in Azure Blob Storage. So far so good. I also would like to store addtional meta-data about the file; for that I use a Azure SQL Database (so I can easily query for files on the blob storage).

因此,当我向存储中添加新文件时,我想确保已成功写入Blob和元数据.因此,想到使用交易上下文之类的东西.

So when I add a new file to the store I would like to make sure, that the blob as well as the meta-data was successfully written. So using something like a transaction-context comes to my mind.

有什么方法可以使用blob存储以及sql存储来创建这样的事务上下文吗?

Is there any way, to create such a transaction-context using blob storage as well as sql storage?

推荐答案

据我所知,没有内置的功能可以做到这一点.您将需要自己进行管理.最简单的方案是先保存您的Blob,然后添加数据库记录.由于数据库是满足您需求的索引,因此在保存数据库记录之前,Blob对于您的代码基本上是不可见的.

There is nothing built-in that will do this as far as I know; you will need to manage this yourself. The simplest scenario is to save your blob first, then add your database record. Since the database serves as an index for your needs, the Blob is essentially invisible to your code until the database records gets saved.

一个更复杂的选择是实现自己的提交逻辑.您将处理数据库插入(例如,将记录上的标志设置为0),保存Blob,如果成功,则将数据库中的标志设置为1.

A more involved option is to implement your own commit logic. You would handle a database insert (with a flag on the record set to 0 for example), save the Blob, and if successful set the flag in the database to 1.

您也可以将元数据保存在Azure表中,但是如果您有很多记录,则在Azure表中搜索会大大减慢速度.在大多数情况下,在SQL数据库中搜索会更快.

You could also save the metadata in Azure Tables, although searching in Azure Tables can slow down significantly if you have lots of records. Searching in SQL Database will be faster most of the time.

您选择哪种方法取决于您的目标,但我认为第一种选择是最简单的.

Which approach you choose depends on your objectives, but I think the first option is the simplest.

这篇关于Azure Blob存储的事务访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆