doujiacai4986
2018-01-04 22:18
浏览 115
已采纳

Azure Blob首先写入

This official example for writing blob blocks has a step where it checks which blocks have not been committed:

    fmt.Println("Get uncommitted blocks list...")
    list, err := b.GetBlockList(storage.BlockListTypeUncommitted, nil)
    if err != nil {
        return fmt.Errorf("get block list failed: %v", err)
    }
    uncommittedBlocksList := make([]storage.Block, len(list.UncommittedBlocks))
    for i := range list.UncommittedBlocks {
        uncommittedBlocksList[i].ID = list.UncommittedBlocks[i].Name
        uncommittedBlocksList[i].Status = storage.BlockStatusUncommitted
    }

If I'm creating a blob (with multiple blocks) that definitely doesn't yet exist. Is there any problem with skipping that code?

The code would be something like:

    b := cnt.GetBlobReference(blockBlobName)
    err := b.CreateBlockBlob(nil)

    blockID := "00000"
    data := randomData(1984)
    err = b.PutBlock(blockID, data, nil)

    blockID2 := "00001"
    data2 := randomData(6542)
    err = b.PutBlock(blockID2, data2, nil)

    var uncommittedBlocksList []storage.Block
    uncommittedBlocksList = append(uncommittedBlocksList, 
        Block{
           ID:"00000"
           Status:BlockStatusUncommitted,
        },
        Block{
           ID:"00001"
           Status:BlockStatusUncommitted,
        },
    )
    err = b.PutBlockList(uncommittedBlocksList, nil)

图片转代码服务由CSDN问答提供 功能建议

官方示例用于编写Blob块,该步骤可检查尚未提交的块:

  fmt.Println(“获取未提交的块列表...”)
列表,错误:= b.GetBlockList(storage.BlockListTypeUncommitted,nil)
如果错误!= nil {
返回 fmt.Errorf(“获取阻止列表失败:%v”,err)
} 
 uncommittedBlocksList:= make([] storage.Block,len(list.UncommittedBlocks))
 for i:=范围列表。UncommittedBlocks{  
 uncommittedBlocksList [i] .ID = list.UncommittedBlocks [i] .Name 
 uncommittedBlocksList [i] .Status = storage.BlockStatusUncommitted 
} 
   
 
 

如果 我正在创建一个绝对不存在的Blob(具有多个块)。

代码有什么问题?

  b:= cnt.GetBlobReference(blockBlobName)  
错误:= b.CreateBlockBlob(nil)
 
 blockID:=“ 00000” 
数据:= randomData(1984)
错误= b.PutBlock(blockID,data,nil)
 
 blockID2:  =“ 00001” 
 data2:= randomData(6542)
 err = b.PutBlock(blockID2,data2,nil)
 
 var uncommittedBlocksList [] storage.Block 
 uncommittedBlocksList = append(uncommittedBlocksList,
 Block {  
 ID:“ 00000” 
状态:BlockStatusUncommitted,
},
阻止{
 ID:“ 00001” 
状态:BlockStatusUncommitted,
},
} 
 err = b.PutBlockList(uncommittedBlocksList  ,nil)
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxuanwei1980 2018-01-05 02:44
    已采纳

    If I'm creating a blob (with multiple blocks) that definitely doesn't yet exist. Is there any problem with skipping that code?

    Absolutely not. You can certainly skip the code for fetching uncommitted block list. This scenario for fetching uncommitted list is useful when you tried to upload a blob and it failed in between and you want to resume the upload from the last failed block. By skipping this code, you are essentially telling Azure Storage to discard any other uncommitted blocks and use the blocks specified in the block list to create the blob.

    打赏 评论

相关推荐 更多相似问题