您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

了解块 blob、追加 blob 和页 blobUnderstanding block blobs, append blobs, and page blobs

存储服务提供三种类型的 blob:块 blob追加 blob页 blobThe storage service offers three types of blobs, block blobs, append blobs, and page blobs. 创建 Blob 时将指定 Blob 类型。You specify the blob type when you create the blob. 创建 blob 后,将无法更改其类型,并且只能使用适用于该 blob 类型的操作(,将块或块的列表写入块 blob,将块追加到追加 blob,然后将页写入页 blob)来更新该 blob。Once the blob has been created, its type cannot be changed, and it can be updated only by using operations appropriate for that blob type, i.e., writing a block or list of blocks to a block blob, appending blocks to a append blob, and writing pages to a page blob.

所有 Blob 都将立即反映提交的更改。All blobs reflect committed changes immediately. 每个版本的 Blob 均具有一个名为“ETag”** 的唯一标记,可以将该标记与访问条件配合使用以确保你仅更改 Blob 的特定实例。Each version of the blob has a unique tag, called an ETag, that you can use with access conditions to assure you only change a specific instance of the blob.

可租用任何 Blob 来进行独占的写入访问。Any blob can be leased for exclusive write access. 在租用 Blob 时,仅包含当前租用 ID 的调用可修改 Blob 或(针对块 Blob)其块。When a blob is leased, only calls that include the current lease ID can modify the blob or (for block blobs) its blocks.

可在快照中重复任何 Blob。Any blob can be duplicated in a snapshot. 有关快照的信息,请参阅创建 Blob 的快照For information about snapshots, see Creating a Snapshot of a Blob.

备注

Azure 存储模拟器中的 blob 的最大大小限制为 2 GiB。Blobs in the Azure storage emulator are limited to a maximum size of 2 GiB.

关于块 blobAbout block blobs

块 blob 经过优化,可高效地上传大量数据。Block blobs are optimized for uploading large amounts of data efficiently. 块 Blob 由多个块构成,其中每个块均由一个块 ID 标识。Block blobs are comprised of blocks, each of which is identified by a block ID. 块 blob 最多可包含50000块。A block blob can include up to 50,000 blocks. 块 blob 中的每个块可以有不同的大小,最大大小为所使用的服务版本所允许的最大大小。Each block in a block blob can be a different size, up to the maximum size permitted for the service version in use. 若要创建或修改块 blob,请通过Put 块操作写入一组块,然后将块提交到带有Put 块列表操作的 blob。To create or modify a block blob, write a set of blocks via the Put Block operation and then commit the blocks to a blob with the Put Block List operation.

小于特定大小(由服务版本确定)的 blob 可以通过Put Blob通过单个写入操作全部上传。Blobs that are less than a certain size (determined by service version) can be uploaded in their entirety with a single write operation via Put Blob.

下表描述了服务版本允许的最大块大小和 blob 大小。The following table describes the maximum block and blob sizes permitted by service version.

服务版本Service version 最大块大小(通过 Put 块)Maximum block size (via Put Block) 最大 blob 大小(通过 Put 块列表)Maximum blob size (via Put Block List) 通过单个写入操作的最大 blob 大小(通过 Put Blob)Maximum blob size via single write operation (via Put Blob)
版本2019-12-12 及更高版本Version 2019-12-12 and later 4000 MiB (预览版)4000 MiB (preview) 大约 190.7 TiB (4000 MiB X 50000 块)(预览版)Approximately 190.7 TiB (4000 MiB X 50,000 blocks) (preview) 5000 MiB (预览版)5000 MiB (preview)
版本2016-05-31 到版本2019-07-07Version 2016-05-31 through version 2019-07-07 100 MiB100 MiB 大约 4.75 TiB (100 MiB X 50000 块)Approximately 4.75 TiB (100 MiB X 50,000 blocks) 256 MiB256 MiB
2016-05-31 之前的版本Versions prior to 2016-05-31 4 MiB4 MiB 大约 195 GiB (4 MiB X 50000 块)Approximately 195 GiB (4 MiB X 50,000 blocks) 64 MiB64 MiB

使用BlobRequestOptions对象的SingleBlobUploadThresholdInBytes属性,存储客户端默认为 128 MiB 最大单个 blob 上载,可在适用于 .net 的 Azure 存储客户端库中进行设置。Storage clients default to a 128 MiB maximum single blob upload, settable in the Azure Storage client library for .NET version 11 by using the SingleBlobUploadThresholdInBytes property of the BlobRequestOptions object. 当块 Blob 上载大于此属性中的值时,存储客户端会将文件分为多个块。When a block blob upload is larger than the value in this property, storage clients break the file into blocks. 您可以使用BlobRequestOptions对象的ParallelOperationThreadCount属性,根据每个请求对使用的线程数进行并行上传。You can set the number of threads used to upload the blocks in parallel on a per-request basis using the ParallelOperationThreadCount property of the BlobRequestOptions object.

当您将一个块上载到存储帐户中的 Blob 时,该块将与指定的块 Blob 关联,但它不会成为 Blob 的一部分,直到您提交包含新块的 ID 的块列表。When you upload a block to a blob in your storage account, it is associated with the specified block blob, but it does not become part of the blob until you commit a list of blocks that includes the new block's ID. 在明确提交或丢弃新块之前,这些块将保持未提交状态。New blocks remain in an uncommitted state until they are specifically committed or discarded. 最多可以有100000个未提交的块。There can be a maximum of 100,000 uncommitted blocks. 编写块不会更新现有 Blob 的上次修改时间。Writing a block does not update the last modified time of an existing blob.

块 Blob 包含一些功能,可帮助你通过网络管理大型文件。Block blobs include features that help you manage large files over networks. 利用块 Blob,你可以并行方式上载多个块以减少上载时间。With a block blob, you can upload multiple blocks in parallel to decrease upload time. 每个块均可包含一个 MD5 哈希来验证传输,因此你可以跟踪上载进度并根据需要重新发送块。Each block can include an MD5 hash to verify the transfer, so you can track upload progress and re-send blocks as needed. 可以按任意顺序上载块,并确定这些块在最终块列表提交步骤中的顺序。You can upload blocks in any order, and determine their sequence in the final block list commitment step. 您也可以上载新块来替换具有相同的块 ID 的现有未提交块。You can also upload a new block to replace an existing uncommitted block of the same block ID. 在这些块被丢弃之前,您有一周的时间将它们提交到 Blob。You have one week to commit blocks to a blob before they are discarded. 此外,如果在执行块列表提交操作时未包含这些块,则它们也将被丢弃。All uncommitted blocks are also discarded when a block list commitment operation occurs but does not include them.

可以通过插入、替换或删除现有块来修改现有块 Blob。You can modify an existing block blob by inserting, replacing, or deleting existing blocks. 在上载已发生更改的一个或多个块后,可以使用单个提交操作将要保留的现有块与新块一起提交来提交新版本的 Blob。After uploading the block or blocks that have changed, you can commit a new version of the blob by committing the new blocks with the existing blocks you want to keep using a single commit operation. 若要在已提交的 Blob 的两个不同的位置插入同一字节范围,则可在相同的提交操作中的两个位置提交相同的块。To insert the same range of bytes in two different locations of the committed blob, you can commit the same block in two places within the same commit operation. 对于任何提交操作,如果未找到任何块,则整个提交操作将失败并出现错误,而且不会修改 Blob。For any commit operation, if any block is not found, the entire commitment operation fails with an error, and the blob is not modified. 任何块承诺都将覆盖 blob 的现有属性和元数据,并丢弃所有未提交的块。Any block commitment overwrites the blob's existing properties and metadata, and discards all uncommitted blocks.

块 ID 是 Blob 中具有相等长度的字符串。Block IDs are strings of equal length within a blob. 块客户端代码通常使用 Base-64 编码来将字符串规范为相等长度。Block client code usually uses base-64 encoding to normalize strings into equal lengths. 在使用 Base-64 编码时,预先编码的字符串必须小于或等于 64 个字节。When using base-64 encoding, the pre-encoded string must be 64 bytes or less. 块 ID 值可在不同的 Blob 中重复。Block ID values can be duplicated in different blobs.

如果为不存在的 Blob 编写块,则将创建一个长度为 0 字节的新块 Blob。If you write a block for a blob that does not exist, a new block blob is created, with a length of zero bytes. 此 Blob 将出现在包含未提交的 Blob 的 Blob 列表中。This blob will appear in blob lists that include uncommitted blobs. 如果未将任何块提交到此 blob,则将在上一次成功上传后的一周内丢弃它及其未提交的块。If you don't commit any block to this blob, it and its uncommitted blocks will be discarded one week after the last successful block upload. 此外,在使用单个步骤(而不是两步块上载并提交过程)创建具有相同名称的新 Blob 时,也将丢弃所有未提交的块。All uncommitted blocks are also discarded when a new blob of the same name is created using a single step (rather than the two-step block upload-then-commit process).

关于页 blobAbout page blobs

页 blob 是已针对随机读写操作进行优化的 512 字节的页的集合。Page blobs are a collection of 512-byte pages optimized for random read and write operations. 若要创建页 Blob,请初始化页 Blob 并指定页 Blob 将增长到的最大大小。To create a page blob, you initialize the page blob and specify the maximum size the page blob will grow. 若要添加或更新页 Blob 的内容,你可以通过指定偏移量和对齐 512 字节页边界的范围来编写一个或多个页。To add or update the contents of a page blob, you write a page or pages by specifying an offset and a range that align to 512-byte page boundaries. 对页 blob 的写入可以只覆盖一页、某些页或页 blob 的最大 4 MiB。A write to a page blob can overwrite just one page, some pages, or up to 4 MiB of the page blob. 对页 Blob 进行的写入操作将就地进行并立即提交到 Blob。Writes to page blobs happen in-place and are immediately committed to the blob. 页 blob 的最大大小为 8 TiB。The maximum size for a page blob is 8 TiB.

Azure 虚拟机磁盘由页 blob 支持。Azure virtual machine disks are backed by page blobs. Azure 提供两种类型的持久磁盘存储:高级和标准。Azure offers two types of durable disk storage: premium and standard. 页 blob 的高级存储适用于需要一致的高性能和低延迟的 Azure 虚拟机工作负荷。Premium storage for page blobs is designed for Azure virtual machine workloads that require consistent high performance and low latency. 有关详细信息,请参阅文章为IaaS Vm 选择磁盘类型一文中的高级固态硬盘(SSD) 部分。For detailed information, see the Premium solid-state drives (SSD) section of the article Select a disk type for IaaS VMs. 有关适用于页 blob 的高级存储的可伸缩性目标的信息,请参阅Azure 存储空间可伸缩性和性能目标For information about the scalability targets for premium storage for page blobs, see Azure Storage Scalability and Performance Targets.

关于追加 blobAbout append blobs

追加 blob 由块组成,并已针对追加操作进行了优化。An append blob is comprised of blocks and is optimized for append operations. 修改追加 blob 时,仅通过追加块操作将块添加到 blob 的末尾。When you modify an append blob, blocks are added to the end of the blob only, via the Append Block operation. 不支持更新或删除现有块。Updating or deleting of existing blocks is not supported. 不同于块 blob,追加 blob 不会公开其块 Id。Unlike a block blob, an append blob does not expose its block IDs.

追加 blob 中的每个块可以有不同的大小,最大值为 4 MiB,追加 blob 最多可包含50000块。Each block in an append blob can be a different size, up to a maximum of 4 MiB, and an append blob can include up to 50,000 blocks. 因此,追加 blob 的最大大小会略微超过 195 GiB (4 MiB X 50000 块)。The maximum size of an append blob is therefore slightly more than 195 GiB (4 MiB X 50,000 blocks).

另请参阅See Also