如何在 gcloud 存储桶中附加超过 33 个文件?

How to append more than 33 files in a gcloud bucket?

我使用以下方法将数据集附加到 gcloud 中的存储桶中:

gsutil compose gs://bucket/obj1 [gs://bucket/obj2 ...] gs://bucket/composite

但是,今天当我尝试附加一些数据时,终端打印错误 CommandException: The compose command accepts at most 33 arguments.

我不知道这个限制。如何在我的存储桶中附加超过 33 个文件?还有其他命令行工具吗?我想避免为看起来相当简单的任务创建虚拟机。

我使用 gsutil help compose 查看了帮助。但这并没有太大帮助。只有一条警告说“请注意,可以限制的组件数量(当前为 32 个) 在单个操作中组合。”但没有关于解决方法的提示。

能不能不递归|批处理?

我没试过这个。

给定任意文件列表 (FILES)

虽然 FILES 中有超过 1 个文件:

  1. FILESgsutil compose 中 n<=33 的第一个 n 放入临时文件
  2. 如果成功,将 FILES 中的 n 个名称替换为 1 个临时文件。
  3. 重复

剩下的文件就是一切。

更新

这个问题激起了我的好奇心,让我有机会提高 bash ;-)

一个粗略的概念验证 bash 脚本,它为任意数量的文件生成 gsutil compose 命令的批次(受限于字符串格式 %04)。

GSUTIL="gsutil compose"
BATCH_SIZE="32"

# These may be the same (or no) bucket
SRC="gs://bucket01/"
DST="gs://bucket02/"

# Generate test LST
FILES=()
for N in $(seq -f "%04g" 1 100); do
    FILES+=("${SRC}/file-${N}")
done

function squish() {
  LST=("$@")
  LEN=${#LST[@]}

  if [ "${LEN}" -le "1" ]; then
    # Empty array; nothing to do
    return 1
  fi

  # Only unique for this configuration; be careful
  COMPOSITE=$(printf "${DST}/composite-%04d" ${LEN})

  if [ "${LEN}" -le "${BATCH_SIZE}" ]; then
    # Batch can be composed with one command
    echo "${GSUTIL} ${LST[@]} ${COMPOSITE}"
    return 1
  fi

  # Compose 1st batch of files
  # NB Provide start:size
  echo "${GSUTIL} ${LST[@]:0:${BATCH_SIZE}} ${COMPOSITE}"

  # Remove batch from LST
  # NB Provide start (to end is implied)
  REM=${LST[@]:${BATCH_SIZE}}

  # Prepend composite from above batch to the next run
  NXT=(${COMPOSITE} ${REM[@]})

  squish "${NXT[@]}"
}

squish "${FILES[@]}"

运行 BATCH_SIZE=3,没有存储桶和 12 个文件产量:

gsutil compose file-0001 file-0002 file-0003 composite-0012
gsutil compose composite-0012 file-0004 file-0005 composite-0010
gsutil compose composite-0010 file-0006 file-0007 composite-0008
gsutil compose composite-0008 file-0008 file-0009 composite-0006
gsutil compose composite-0006 file-0010 file-0011 composite-0004
gsutil compose composite-0004 file-0012 composite-0002

NOTE How composite-0012 is created by the first command but then knitted into the subsequent command.

我会留给你提高吞吐量,方法是不将每个步骤的输出线程化到下一步,将列表中的 gsutil compose 命令并行化,分成批次,然后组合批次。

文档说您只能组合 32 个组件 in a single operation, but there is no limit to the number of components that can make up a composite object

因此,如果要连接的对象超过 32 个,则可以执行多个组合操作,一次组合 32 个对象,直到最终将所有对象组合在一起。