support concurrent uploads for 'mc pipe' (#4435)
This commit is contained in:
+2
-1
@@ -11,4 +11,5 @@ stage/
|
||||
mc
|
||||
.run*
|
||||
.idea/
|
||||
mc.RELEASE*
|
||||
mc.RELEASE*
|
||||
mc.gz
|
||||
+15
-14
@@ -1042,20 +1042,21 @@ func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, progre
|
||||
}
|
||||
|
||||
opts := minio.PutObjectOptions{
|
||||
UserMetadata: metadata,
|
||||
UserTags: tagsMap,
|
||||
Progress: progress,
|
||||
ContentType: contentType,
|
||||
CacheControl: cacheControl,
|
||||
ContentDisposition: contentDisposition,
|
||||
ContentEncoding: contentEncoding,
|
||||
ContentLanguage: contentLanguage,
|
||||
StorageClass: strings.ToUpper(putOpts.storageClass),
|
||||
ServerSideEncryption: putOpts.sse,
|
||||
SendContentMd5: putOpts.md5,
|
||||
DisableMultipart: putOpts.disableMultipart,
|
||||
PartSize: putOpts.multipartSize,
|
||||
NumThreads: putOpts.multipartThreads,
|
||||
UserMetadata: metadata,
|
||||
UserTags: tagsMap,
|
||||
Progress: progress,
|
||||
ContentType: contentType,
|
||||
CacheControl: cacheControl,
|
||||
ContentDisposition: contentDisposition,
|
||||
ContentEncoding: contentEncoding,
|
||||
ContentLanguage: contentLanguage,
|
||||
StorageClass: strings.ToUpper(putOpts.storageClass),
|
||||
ServerSideEncryption: putOpts.sse,
|
||||
SendContentMd5: putOpts.md5,
|
||||
DisableMultipart: putOpts.disableMultipart,
|
||||
PartSize: putOpts.multipartSize,
|
||||
NumThreads: putOpts.multipartThreads,
|
||||
ConcurrentStreamParts: putOpts.concurrentStream, // if enabled honors NumThreads for piped() uploads
|
||||
}
|
||||
|
||||
if !retainUntilDate.IsZero() && !retainUntilDate.Equal(timeSentinel) {
|
||||
|
||||
@@ -60,6 +60,7 @@ type PutOptions struct {
|
||||
storageClass string
|
||||
multipartSize uint64
|
||||
multipartThreads uint
|
||||
concurrentStream bool
|
||||
}
|
||||
|
||||
// StatOptions holds options of the HEAD operation
|
||||
|
||||
+49
-7
@@ -18,13 +18,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"syscall"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
func defaultPartSize() string {
|
||||
_, partSize, _, _ := minio.OptimalPartInfo(-1, 0)
|
||||
return humanize.IBytes(uint64(partSize))
|
||||
}
|
||||
|
||||
var pipeFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "encrypt",
|
||||
@@ -42,6 +51,16 @@ var pipeFlags = []cli.Flag{
|
||||
Name: "tags",
|
||||
Usage: "apply one or more tags to the uploaded objects",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "concurrent",
|
||||
Value: 1,
|
||||
Usage: "allow N concurrent uploads [WARNING: will use more memory use it with caution]",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "part-size",
|
||||
Value: defaultPartSize(),
|
||||
Usage: "customize chunk size for each concurrent upload",
|
||||
},
|
||||
}
|
||||
|
||||
// Display contents of a file.
|
||||
@@ -89,23 +108,46 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
func pipe(targetURL string, encKeyDB map[string][]prefixSSEPair, storageClass string, meta map[string]string) *probe.Error {
|
||||
func pipe(ctx *cli.Context, targetURL string, encKeyDB map[string][]prefixSSEPair, meta map[string]string) *probe.Error {
|
||||
if targetURL == "" {
|
||||
// When no target is specified, pipe cat's stdin to stdout.
|
||||
return catOut(os.Stdin, -1).Trace()
|
||||
}
|
||||
|
||||
storageClass := ctx.String("storage-class")
|
||||
alias, _ := url2Alias(targetURL)
|
||||
sseKey := getSSE(targetURL, encKeyDB[alias])
|
||||
|
||||
multipartThreads := ctx.Int("concurrent")
|
||||
if multipartThreads > 1 {
|
||||
// We will be allocating large buffers, reduce default GC overhead
|
||||
debug.SetGCPercent(20)
|
||||
}
|
||||
|
||||
var multipartSize uint64
|
||||
var e error
|
||||
if partSizeStr := ctx.String("part-size"); partSizeStr != "" {
|
||||
multipartSize, e = humanize.ParseBytes(partSizeStr)
|
||||
if e != nil {
|
||||
return probe.NewError(e)
|
||||
}
|
||||
}
|
||||
|
||||
// Stream from stdin to multiple objects until EOF.
|
||||
// Ignore size, since os.Stat() would not return proper size all the time
|
||||
// for local filesystem for example /proc files.
|
||||
opts := PutOptions{
|
||||
sse: sseKey,
|
||||
storageClass: storageClass,
|
||||
metadata: meta,
|
||||
sse: sseKey,
|
||||
storageClass: storageClass,
|
||||
metadata: meta,
|
||||
multipartSize: multipartSize,
|
||||
multipartThreads: uint(multipartThreads),
|
||||
concurrentStream: ctx.IsSet("concurrent"),
|
||||
}
|
||||
_, err := putTargetStreamWithURL(targetURL, os.Stdin, -1, opts)
|
||||
|
||||
pg := newProgressBar(0)
|
||||
|
||||
_, err := putTargetStreamWithURL(targetURL, io.TeeReader(os.Stdin, pg), -1, opts)
|
||||
// TODO: See if this check is necessary.
|
||||
switch e := err.ToGoError().(type) {
|
||||
case *os.PathError:
|
||||
@@ -142,12 +184,12 @@ func mainPipe(ctx *cli.Context) error {
|
||||
meta["X-Amz-Tagging"] = tags
|
||||
}
|
||||
if len(ctx.Args()) == 0 {
|
||||
err = pipe("", nil, ctx.String("storage-class"), meta)
|
||||
err = pipe(ctx, "", nil, meta)
|
||||
fatalIf(err.Trace("stdout"), "Unable to write to one or more targets.")
|
||||
} else {
|
||||
// extract URLs.
|
||||
URLs := ctx.Args()
|
||||
err = pipe(URLs[0], encKeyDB, ctx.String("storage-class"), meta)
|
||||
err = pipe(ctx, URLs[0], encKeyDB, meta)
|
||||
fatalIf(err.Trace(URLs[0]), "Unable to write to one or more targets.")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module github.com/minio/mc
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/bubbletea v0.22.1
|
||||
@@ -21,7 +21,7 @@ require (
|
||||
github.com/minio/filepath v1.0.0
|
||||
github.com/minio/madmin-go/v2 v2.0.2-0.20221221104141-93e7e5aefaf2
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/minio/minio-go/v7 v7.0.44
|
||||
github.com/minio/minio-go/v7 v7.0.46
|
||||
github.com/minio/pkg v1.5.6
|
||||
github.com/minio/selfupdate v0.5.0
|
||||
github.com/minio/sha256-simd v1.0.0
|
||||
|
||||
@@ -513,8 +513,8 @@ github.com/minio/madmin-go/v2 v2.0.2-0.20221221104141-93e7e5aefaf2/go.mod h1:5aF
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||
github.com/minio/minio-go/v7 v7.0.41/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
|
||||
github.com/minio/minio-go/v7 v7.0.44 h1:9zUJ7iU7ax2P1jOvTp6nVrgzlZq3AZlFm0XfRFDKstM=
|
||||
github.com/minio/minio-go/v7 v7.0.44/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
|
||||
github.com/minio/minio-go/v7 v7.0.46 h1:Vo3tNmNXuj7ME5qrvN4iadO7b4mzu/RSFdUkUhaPldk=
|
||||
github.com/minio/minio-go/v7 v7.0.46/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
|
||||
github.com/minio/pkg v1.5.4/go.mod h1:2MOaRFdmFKULD+uOLc3qHLGTQTuxCNPKNPfLBTxC8CA=
|
||||
github.com/minio/pkg v1.5.6 h1:4OUvRU1gDWilu/dohkJMVapylXN8q94kU5MgkOJ/x0I=
|
||||
github.com/minio/pkg v1.5.6/go.mod h1:EiGlHS2xaooa2VMxhJsxxAZHDObHVUB3HwtuoEXOCVE=
|
||||
|
||||
Reference in New Issue
Block a user