Skip to content

Commit f8fef36

Browse files
authored
Merge pull request #356 from YangSen-qn/list_bucket_optimize
List bucket optimize
2 parents 6f9cc90 + 46eb0bc commit f8fef36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1866
-272
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*.dylib
99
src/test/
1010
src/.qshell
11+
marker.go
12+
marker_test.go
1113

1214
# Folders
1315
_obj
@@ -29,7 +31,6 @@ _cgo_export.*
2931
[568vq].out
3032
report.xml
3133
.qshell
32-
qshell_*
3334
qshell-*
3435
_testmain.go
3536

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 2.9.1
2+
1. 支持通过 $? 获取命令执行状态
3+
2. get / qdownload 下载大文件支持切片下载
4+
3. 优化批量上传
5+
4. batch 并发量自适应
6+
5. listbucket2 支持 v1、支持断点继续列举、支持结果滚动输出
7+
18
# 2.9.0
29
1. 新增 batchforbidden 命令,支持批量修改文件启用/禁用状态,具体参考命令使用说明
310
2. qdownload 命令新增支持自定义文件本地存储路径, 具体参考命令使用说明

cmd/asyncfetch.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func asyncFetchCmdBuilder(cfg *iqshell.Config) *cobra.Command {
1919
cfg.CmdCfg.CmdId = docs.ABFetch
2020
info.BatchInfo.ItemSeparate = "\t" // 此处用户不可定义
2121
info.BatchInfo.EnableStdin = true
22+
info.BatchInfo.OperationCountPerRequest = 1
2223
if len(args) > 0 {
2324
info.Bucket = args[0]
2425
}

cmd/bucket.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ var listBucketCmd2Builder = func(cfg *iqshell.Config) *cobra.Command {
110110
cmd.Flags().StringVarP(&info.Suffixes, "suffixes", "q", "", "list by key suffixes, separated by comma")
111111
cmd.Flags().IntVarP(&info.MaxRetry, "max-retry", "x", -1, "max retries when error occurred")
112112
cmd.Flags().StringVarP(&info.SaveToFile, "out", "o", "", "output file")
113+
cmd.Flags().IntVarP(&info.OutputLimit, "limit", "", -1, "max count of items to output")
114+
cmd.Flags().Int64VarP(&info.OutputFileMaxLines, "output-file-max-lines", "", 0, "maximum number of lines per output file.")
115+
cmd.Flags().Int64VarP(&info.OutputFileMaxSize, "output-file-max-size", "", 0, "maximum size of each output file")
113116
cmd.Flags().StringVarP(&info.StartDate, "start", "s", "", "start date with format yyyy-mm-dd-hh-MM-ss")
114117
cmd.Flags().StringVarP(&info.EndDate, "end", "e", "", "end date with format yyyy-mm-dd-hh-MM-ss")
115118

@@ -120,10 +123,12 @@ var listBucketCmd2Builder = func(cfg *iqshell.Config) *cobra.Command {
120123

121124
cmd.Flags().BoolVarP(&info.AppendMode, "append", "a", false, "result append to file instead of overwriting")
122125
cmd.Flags().BoolVarP(&info.Readable, "readable", "r", false, "present file size with human readable format")
123-
cmd.Flags().IntVarP(&info.Limit, "limit", "", -1, "max count of items to output")
126+
cmd.Flags().StringVarP(&info.ApiVersion, "api-version", "", "v2", "list api version, one of v1 and v2.")
127+
cmd.Flags().IntVarP(&info.ApiLimit, "api-limit", "", 1000, "one enumeration will make multiple requests, and the maximum number of items returned for each request; currently only v1 is supported; in the range 1-1000.")
128+
cmd.Flags().BoolVarP(&info.EnableRecord, "enable-record", "", false, "record the execution status of the listbucket2 command. When the listbucket2 command is executed next time, the marker will be automatically filled and the listbucket2 will continue. Enabling this option will automatically enable append (see the --append option for details). The id of the record is related to the bucket where the file is located, the prefix listed, and the path where the file is saved.")
124129

125-
cmd.Flags().StringVarP(&info.ShowFields, "show-fields", "", "", "The file attributes to be displayed on each line, separated by commas. Optional range: Key, Hash, FileSize, PutTime, MimeType, StorageType, EndUser.")
126130
cmd.Flags().StringVarP(&info.OutputFieldsSep, "output-fields-sep", "", data.DefaultLineSeparate, "Each line needs to display the delimiter of the file information.")
131+
cmd.Flags().StringVarP(&info.ShowFields, "show-fields", "", "", "The file attributes to be displayed on each line, separated by commas. Optional range: Key, Hash, FileSize, PutTime, MimeType, StorageType, EndUser.")
127132

128133
return cmd
129134
}

cmd/root.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"github.com/qiniu/qshell/v2/docs"
56
"github.com/qiniu/qshell/v2/iqshell"
67
"github.com/qiniu/qshell/v2/iqshell/common/config"
78
"github.com/qiniu/qshell/v2/iqshell/common/data"
@@ -47,8 +48,13 @@ var rootCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
4748
Short: "Qiniu commandline tool for managing your bucket and CDN",
4849
Version: version.Version(),
4950
BashCompletionFunction: bash_completion_func,
51+
Run: func(cmd *cobra.Command, args []string) {
52+
cfg.CmdCfg.CmdId = docs.QShellType
53+
docs.ShowCmdDocument(docs.QShellType)
54+
},
5055
}
5156
cmd.PersistentFlags().BoolVarP(&cfg.StdoutColorful, "colorful", "", false, "console colorful mode")
57+
cmd.PersistentFlags().BoolVarP(&cfg.Silence, "silence", "", false, "silence mode, The console only outputs warnings、errors and some important information")
5258
cmd.PersistentFlags().BoolVarP(&cfg.DebugEnable, "debug", "d", false, "debug mode")
5359
// ddebug 开启 client debug
5460
cmd.PersistentFlags().BoolVarP(&cfg.DDebugEnable, "ddebug", "D", false, "deep debug mode")

cmd/rsbatch.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ var batchStatCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
2323
},
2424
}
2525
setBatchCmdInputFileFlags(cmd, &info.BatchInfo)
26-
setBatchCmdWorkCountFlags(cmd, &info.BatchInfo)
26+
setBatchCmdWorkerCountFlags(cmd, &info.BatchInfo)
27+
setBatchCmdMinWorkerCountFlags(cmd, &info.BatchInfo)
28+
setBatchCmdWorkerCountIncreasePeriodFlags(cmd, &info.BatchInfo)
2729
setBatchCmdSuccessExportFileFlags(cmd, &info.BatchInfo)
2830
setBatchCmdFailExportFileFlags(cmd, &info.BatchInfo)
2931
setBatchCmdForceFlags(cmd, &info.BatchInfo)
@@ -47,7 +49,9 @@ var batchForbiddenCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
4749
},
4850
}
4951
setBatchCmdInputFileFlags(cmd, &info.BatchInfo)
50-
setBatchCmdWorkCountFlags(cmd, &info.BatchInfo)
52+
setBatchCmdWorkerCountFlags(cmd, &info.BatchInfo)
53+
setBatchCmdMinWorkerCountFlags(cmd, &info.BatchInfo)
54+
setBatchCmdWorkerCountIncreasePeriodFlags(cmd, &info.BatchInfo)
5155
setBatchCmdSuccessExportFileFlags(cmd, &info.BatchInfo)
5256
setBatchCmdFailExportFileFlags(cmd, &info.BatchInfo)
5357
setBatchCmdForceFlags(cmd, &info.BatchInfo)
@@ -265,7 +269,9 @@ var batchFetchCmdBuilder = func(cfg *iqshell.Config) *cobra.Command {
265269

266270
func setBatchCmdDefaultFlags(cmd *cobra.Command, info *batch.Info) {
267271
setBatchCmdInputFileFlags(cmd, info)
268-
setBatchCmdWorkCountFlags(cmd, info)
272+
setBatchCmdWorkerCountFlags(cmd, info)
273+
setBatchCmdMinWorkerCountFlags(cmd, info)
274+
setBatchCmdWorkerCountIncreasePeriodFlags(cmd, info)
269275
setBatchCmdEnableRecordFlags(cmd, info)
270276
setBatchCmdRecordRedoWhileErrorFlags(cmd, info)
271277
setBatchCmdSuccessExportFileFlags(cmd, info)
@@ -279,8 +285,14 @@ func setBatchCmdInputFileFlags(cmd *cobra.Command, info *batch.Info) {
279285
func setBatchCmdForceFlags(cmd *cobra.Command, info *batch.Info) {
280286
cmd.Flags().BoolVarP(&info.Force, "force", "y", false, "force mode, default false")
281287
}
282-
func setBatchCmdWorkCountFlags(cmd *cobra.Command, info *batch.Info) {
283-
cmd.Flags().IntVarP(&info.WorkerCount, "worker", "c", 1, "worker count. 1 means the number of objects in one operation is 1000 and if configured as 3 , the number of objects in one operation is 3000. This value needs to be consistent with the upper limit of Qiniu’s operation, otherwise unexpected errors will occur. Under normal circumstances you do not need to adjust this value and if you need please carefully.")
288+
func setBatchCmdWorkerCountFlags(cmd *cobra.Command, info *batch.Info) {
289+
cmd.Flags().IntVarP(&info.WorkerCount, "worker", "c", 4, "worker count. 1 means the number of objects in one operation is 250 and if configured as 10 , the number of objects in one operation is 2500. This value needs to be consistent with the upper limit of Qiniu’s operation, otherwise unexpected errors will occur. Under normal circumstances you do not need to adjust this value and if you need please carefully.")
290+
}
291+
func setBatchCmdMinWorkerCountFlags(cmd *cobra.Command, info *batch.Info) {
292+
cmd.Flags().IntVarP(&info.MinWorkerCount, "min-worker", "", 1, "min worker count. 1 means the number of objects in one operation is 1000 and if configured as 3 , the number of objects in one operation is 3000. for more, please refer to worker")
293+
}
294+
func setBatchCmdWorkerCountIncreasePeriodFlags(cmd *cobra.Command, info *batch.Info) {
295+
cmd.Flags().IntVarP(&info.WorkerCountIncreasePeriod, "worker-count-increase-period", "", 60, "worker count increase period. when the worker count is too big, an overrun error will be triggered. In order to alleviate this problem, qshell will automatically reduce the worker count. In order to complete the operation as quickly as possible, qshell will periodically increase the worker count. unit: second")
284296
}
285297
func setBatchCmdItemSeparateFlags(cmd *cobra.Command, info *batch.Info) {
286298
cmd.Flags().StringVarP(&info.ItemSeparate, "sep", "F", "\t", "Separator used for split line fields, default is \\t (tab)")

cmd_test/change_minetype_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ func TestBatchChangeMimeType(t *testing.T) {
9090
"--success-list", successLogPath,
9191
"--failure-list", failLogPath,
9292
"--worker", "4",
93+
"--min-worker", "10",
94+
"--worker-count-increase-period", "50",
9395
"-y")
9496
defer func() {
9597
test.RemoveFile(successLogPath)

cmd_test/change_type_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func TestBatchChangeTypeRecord(t *testing.T) {
170170
"--enable-record",
171171
"--record-redo-while-error",
172172
"--worker", "4",
173+
"--min-worker", "10",
174+
"--worker-count-increase-period", "50",
173175
"-y",
174176
"-d")
175177
if !strings.Contains(result, "because have done and success") {

cmd_test/copy_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func TestBatchCopy(t *testing.T) {
9494
"--failure-list", failLogPath,
9595
"--overwrite",
9696
"--worker", "4",
97+
"--min-worker", "10",
98+
"--worker-count-increase-period", "50",
9799
"-w",
98100
"-y")
99101
defer func() {

cmd_test/delete_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func TestBatchDelete(t *testing.T) {
8383
"--success-list", successLogPath,
8484
"--failure-list", failLogPath,
8585
"--worker", "4",
86+
"--min-worker", "10",
87+
"--worker-count-increase-period", "50",
8688
"-y")
8789
defer func() {
8890
test.RemoveFile(successLogPath)

cmd_test/fetch_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ func TestBatchFetchWithRecord(t *testing.T) {
142142
"--failure-list", failLogPath,
143143
"--enable-record",
144144
"--worker", "4",
145-
"--worker", "1",
146145
"-y",
147146
"-d")
148147
if !strings.Contains(result, "Skip") {

cmd_test/forbidden_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ func TestBatchForbiddenRecord(t *testing.T) {
150150
"--enable-record",
151151
"--record-redo-while-error",
152152
"--worker", "4",
153+
"--min-worker", "10",
154+
"--worker-count-increase-period", "50",
153155
"-y",
154156
"-d")
155157
if !strings.Contains(result, "because have done and success") {

cmd_test/move_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ func TestBatchMove(t *testing.T) {
9898
"--success-list", successLogPath,
9999
"--failure-list", failLogPath,
100100
"--worker", "4",
101+
"--min-worker", "10",
102+
"--worker-count-increase-period", "50",
101103
"-y",
102104
"-w")
103105
defer func() {

cmd_test/qshell_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"github.com/qiniu/qshell/v2/cmd_test/test"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestQShellDocument01(t *testing.T) {
10+
prefix := "# 简介\n`qshell`"
11+
result, _ := test.RunCmdWithError()
12+
if !strings.HasPrefix(result, prefix) {
13+
t.Fatal("document test fail for cmd: qshell")
14+
}
15+
}
16+
17+
func TestQShellDocument02(t *testing.T) {
18+
prefix := "# 简介\n`qshell`"
19+
result, _ := test.RunCmdWithError("--doc")
20+
if !strings.HasPrefix(result, prefix) {
21+
t.Fatal("document test fail for cmd: qshell")
22+
}
23+
}

cmd_test/rename_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ func TestBatchRenameWithRecord(t *testing.T) {
151151
"--enable-record",
152152
"--record-redo-while-error",
153153
"--worker", "4",
154+
"--min-worker", "10",
155+
"--worker-count-increase-period", "50",
154156
"-y",
155157
"-w",
156158
"-d")

cmd_test/restore_archive_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ func TestBatchRestoreArchiveRecord(t *testing.T) {
152152
"--enable-record",
153153
"--record-redo-while-error",
154154
"--worker", "4",
155+
"--min-worker", "10",
156+
"--worker-count-increase-period", "50",
155157
"-y",
156158
"-d")
157159
if !strings.Contains(result, "because have done and success") {

cmd_test/status_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func TestBatchStatus(t *testing.T) {
8282
"--success-list", successLogPath,
8383
"--failure-list", failLogPath,
8484
"--worker", "4",
85+
"--min-worker", "10",
86+
"--worker-count-increase-period", "50",
8587
"-y")
8688
defer func() {
8789
test.RemoveFile(successLogPath)

docs/batchchgm.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ qshell batchchgm -h
2424
- -s/--success-list:该选项指定一个文件,qshell 会把操作成功的文件行导入到该文件;默认不导出。【可选】
2525
- -e/--failure-list:该选项指定一个文件,qshell 会把操作失败的文件行加上错误状态码,错误的原因导入该文件;默认不导出。【可选】
2626
- -F/--sep:该选项可以自定义每行输入内容中字段之间的分隔符(文件输入或标准输入,参考 -i 选项说明);默认为 tab 制表符。【可选】
27-
- -c/--worker:该选项可以定义 Batch 任务并发数;1 路并发单次操作对象数为 1000 ,如果配置为 2 并发,则 2 路并发单次操作对象数为 2000,此值需要和七牛对您的操作上限相吻合,否则会出现非预期错误,正常情况不需要调节此值,如果需要请谨慎调节;默认为 1。【可选】
27+
- -c/--worker:该选项可以定义 Batch 任务并发数;1 路并发单次操作对象数为 250 ,如果配置为 10 并发,则 10 路并发单次操作对象数为 2500,此值需要和七牛对您的操作上限相吻合,否则会出现非预期错误,正常情况不需要调节此值,如果需要请谨慎调节;默认为 4。【可选】
28+
- --min-worker:最小 Batch 任务并发数;当并发设置过高时,会触发超限错误,为了缓解此问题,qshell 会自动减小并发度,此值为减小的最低值。默认:1【可选】
29+
- --worker-count-increase-period:为了尽可能快的完成操作 qshell 会周期性尝试增加并发度,此值为尝试增加并发数的周期,单位:秒,最小 10,默认 60。【可选】
2830
- --enable-record:记录任务执行状态,当下次执行命令时会检测任务执行的状态并跳过已执行的任务。 【可选】
2931
- --record-redo-while-error:依赖于 --enable-record,当检测任务状态时(命令重新执行时,所有任务会从头到尾重新执行;任务执行前会先检测当前任务是否已经执行),如果任务已执行且失败,则再执行一次;默认此选项不生效,当任务执行失败不重新执行。 【可选】
3032

docs/batchchtype.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ qshell batchchtype -h
2626
- -s/--success-list:该选项指定一个文件,qshell 会把操作成功的文件行导入到该文件;默认不导出。【可选】
2727
- -e/--failure-list:该选项指定一个文件, qshell 会把操作失败的文件行加上错误状态码,错误的原因导入该文件;默认不导出。【可选】
2828
- -F/--sep:该选项可以自定义每行输入内容中字段之间的分隔符(文件输入或标准输入,参考 -i 选项说明);默认为 tab 制表符。【可选】
29-
- -c/--worker:该选项可以定义 Batch 任务并发数;1 路并发单次操作对象数为 1000 ,如果配置为 2 并发,则 2 路并发单次操作对象数为 2000,此值需要和七牛对您的操作上限相吻合,否则会出现非预期错误,正常情况不需要调节此值,如果需要请谨慎调节;默认为 1。【可选】
29+
- -c/--worker:该选项可以定义 Batch 任务并发数;1 路并发单次操作对象数为 250 ,如果配置为 10 并发,则 10 路并发单次操作对象数为 2500,此值需要和七牛对您的操作上限相吻合,否则会出现非预期错误,正常情况不需要调节此值,如果需要请谨慎调节;默认为 4。【可选】
30+
- --min-worker:最小 Batch 任务并发数;当并发设置过高时,会触发超限错误,为了缓解此问题,qshell 会自动减小并发度,此值为减小的最低值。默认:1【可选】
31+
- --worker-count-increase-period:为了尽可能快的完成操作 qshell 会周期性尝试增加并发度,此值为尝试增加并发数的周期,单位:秒,最小 10,默认 60。【可选】
3032
- --enable-record:记录任务执行状态,当下次执行命令时会检测任务执行的状态并跳过已执行的任务。 【可选】
3133
- --record-redo-while-error:依赖于 --enable-record,当检测任务状态时(命令重新执行时,所有任务会从头到尾重新执行;任务执行前会先检测当前任务是否已经执行),如果任务已执行且失败,则再执行一次;默认此选项不生效,当任务执行失败不重新执行。 【可选】
3234

docs/batchcopy.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ qshell batchcopy -h
3434
- -s/--success-list:该选项指定一个文件,qshell 会把操作成功的文件行导入到该文件;默认不导出。【可选】
3535
- -e/--failure-list:该选项指定一个文件, qshell 会把操作失败的文件行加上错误状态码,错误的原因导入该文件;默认不导出。【可选】
3636
- -F/--sep:该选项可以自定义每行输入内容中字段之间的分隔符(文件输入或标准输入,参考 -i 选项说明);默认为 tab 制表符。【可选】】
37-
- -c/--worker:该选项可以定义 Batch 任务并发数;1 路并发单次操作对象数为 1000 ,如果配置为 2 并发,则 2 路并发单次操作对象数为 2000,此值需要和七牛对您的操作上限相吻合,否则会出现非预期错误,正常情况不需要调节此值,如果需要请谨慎调节;默认为 1。【可选】
37+
- -c/--worker:该选项可以定义 Batch 任务并发数;1 路并发单次操作对象数为 250 ,如果配置为 10 并发,则 10 路并发单次操作对象数为 2500,此值需要和七牛对您的操作上限相吻合,否则会出现非预期错误,正常情况不需要调节此值,如果需要请谨慎调节;默认为 4。【可选】
38+
- --min-worker:最小 Batch 任务并发数;当并发设置过高时,会触发超限错误,为了缓解此问题,qshell 会自动减小并发度,此值为减小的最低值。默认:1【可选】
39+
- --worker-count-increase-period:为了尽可能快的完成操作 qshell 会周期性尝试增加并发度,此值为尝试增加并发数的周期,单位:秒,最小 10,默认 60。【可选】
3840
- --overwrite:默认情况下,如果批量重命名的文件列表中存在目标空间已有同名文件的情况,针对该文件的重命名会失败,如果希望能够强制覆盖目标文件,那么可以使用 `--overwrite` 选项。【可选】
3941
- --enable-record:记录任务执行状态,当下次执行命令时会检测任务执行的状态并跳过已执行的任务。 【可选】
4042
- --record-redo-while-error:依赖于 --enable-record,当检测任务状态时(命令重新执行时,所有任务会从头到尾重新执行;任务执行前会先检测当前任务是否已经执行),如果任务已执行且失败,则再执行一次;默认此选项不生效,当任务执行失败不重新执行。 【可选】

0 commit comments

Comments
 (0)