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

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)
  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思