Compare commits

...
Author SHA1 Message Date
poornas 975423abe2 Fix mc cp when legal-hold or retention is set (#3257)
- Send Content-MD5 header if default retention is set on the bucket
- legal-hold needs to be case insensitive
2020-06-16 11:28:25 -07:00
Harshavardhana 3dd971f673 rename multi-master to active-active (#3255) 2020-06-15 18:18:08 -07:00
6 changed files with 74 additions and 63 deletions
+7 -1
View File
@@ -987,13 +987,19 @@ func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, metada
if lockModeStr != "" {
opts.Mode = &lockMode
opts.SendContentMd5 = true
}
if lh, ok := metadata[AmzObjectLockLegalHold]; ok {
delete(metadata, AmzObjectLockLegalHold)
opts.LegalHold = minio.LegalHoldStatus(strings.ToUpper(lh))
opts.SendContentMd5 = true
}
if opts.LegalHold == "" && opts.Mode == nil {
if _, _, _, err := c.api.GetBucketObjectLockConfig(bucket); err == nil {
opts.SendContentMd5 = true
}
}
n, e := c.api.PutObjectWithContext(ctx, bucket, object, reader, size, opts)
if e != nil {
errResponse := minio.ToErrorResponse(e)
+3 -3
View File
@@ -478,7 +478,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p
cpURLs.TargetContent.RetentionEnabled = true
}
cpURLs.TargetContent.RetentionDuration = session.Header.CommandStringFlags[rdFlag]
cpURLs.TargetContent.LegalHold = session.Header.CommandStringFlags[lhFlag]
cpURLs.TargetContent.LegalHold = strings.ToUpper(session.Header.CommandStringFlags[lhFlag])
if cpURLs.TargetContent.LegalHold != "" {
cpURLs.TargetContent.LegalHoldEnabled = true
}
@@ -491,7 +491,7 @@ func doCopySession(cli *cli.Context, session *sessionV8, encKeyDB map[string][]p
cpURLs.TargetContent.RetentionDuration = rd
}
if lh := cli.String(lhFlag); lh != "" {
cpURLs.TargetContent.LegalHold = lh
cpURLs.TargetContent.LegalHold = strings.ToUpper(lh)
cpURLs.TargetContent.LegalHoldEnabled = true
}
}
@@ -642,7 +642,7 @@ func mainCopy(ctx *cli.Context) error {
storageClass := ctx.String("storage-class")
retentionMode := ctx.String(rmFlag)
retentionDuration := ctx.String(rdFlag)
legalHold := ctx.String(lhFlag)
legalHold := strings.ToUpper(ctx.String(lhFlag))
sseKeys := os.Getenv("MC_ENCRYPT_KEY")
if key := ctx.String("encrypt-key"); key != "" {
sseKeys = key
+1 -1
View File
@@ -90,7 +90,7 @@ func (d diffMessage) String() string {
msg = console.Colorize("DiffSize", "! "+d.SecondURL)
case differInMetadata:
msg = console.Colorize("DiffMetadata", "! "+d.SecondURL)
case differInMMSourceMTime:
case differInAASourceMTime:
msg = console.Colorize("DiffMMSourceMTime", "! "+d.SecondURL)
default:
fatalIf(errDummy().Trace(d.FirstURL, d.SecondURL),
+13 -13
View File
@@ -38,7 +38,7 @@ const (
differInType // differs in type, exfile/directory
differInFirst // only in source (FIRST)
differInSecond // only in target (SECOND)
differInMMSourceMTime // differs in multi-master source modtime
differInAASourceMTime // differs in active-active source modtime
)
func (d differType) String() string {
@@ -49,7 +49,7 @@ func (d differType) String() string {
return "size"
case differInMetadata:
return "metadata"
case differInMMSourceMTime:
case differInAASourceMTime:
return "mm-source-mtime"
case differInType:
return "type"
@@ -61,7 +61,7 @@ func (d differType) String() string {
return "unknown"
}
const multiMasterSourceModTimeKey = "X-Amz-Meta-Mm-Source-Mtime"
const activeActiveSourceModTimeKey = "X-Amz-Meta-Mm-Source-Mtime"
func oldestNonNullTime(t1, t2 time.Time) time.Time {
if t1.IsZero() {
@@ -77,9 +77,9 @@ func oldestNonNullTime(t1, t2 time.Time) time.Time {
return t2
}
// multiMasterModTimeUpdated tries to calculate if the object copy in the target
// activeActiveModTimeUpdated tries to calculate if the object copy in the target
// is older than the one in the source by comparing the modtime of the data.
func multiMasterModTimeUpdated(src, dst *ClientContent) bool {
func activeActiveModTimeUpdated(src, dst *ClientContent) bool {
if src == nil || dst == nil {
return false
}
@@ -91,15 +91,15 @@ func multiMasterModTimeUpdated(src, dst *ClientContent) bool {
return false
}
_, ok1 := src.UserMetadata[multiMasterSourceModTimeKey]
_, ok2 := dst.UserMetadata[multiMasterSourceModTimeKey]
_, ok1 := src.UserMetadata[activeActiveSourceModTimeKey]
_, ok2 := dst.UserMetadata[activeActiveSourceModTimeKey]
if !ok1 && !ok2 {
// No multimaster context found, consider src & dst as similar
return false
}
srcOriginLastModified, _ := time.Parse(time.RFC3339Nano, src.UserMetadata[multiMasterSourceModTimeKey])
dstOriginLastModified, _ := time.Parse(time.RFC3339Nano, dst.UserMetadata[multiMasterSourceModTimeKey])
srcOriginLastModified, _ := time.Parse(time.RFC3339Nano, src.UserMetadata[activeActiveSourceModTimeKey])
dstOriginLastModified, _ := time.Parse(time.RFC3339Nano, dst.UserMetadata[activeActiveSourceModTimeKey])
srcActualModTime := oldestNonNullTime(src.Time, srcOriginLastModified)
dstActualModTime := oldestNonNullTime(dst.Time, dstOriginLastModified)
@@ -109,7 +109,7 @@ func multiMasterModTimeUpdated(src, dst *ClientContent) bool {
func metadataEqual(m1, m2 map[string]string) bool {
for k, v := range m1 {
if k == multiMasterSourceModTimeKey {
if k == activeActiveSourceModTimeKey {
continue
}
if m2[k] != v {
@@ -117,7 +117,7 @@ func metadataEqual(m1, m2 map[string]string) bool {
}
}
for k, v := range m2 {
if k == multiMasterSourceModTimeKey {
if k == activeActiveSourceModTimeKey {
continue
}
if m1[k] != v {
@@ -245,11 +245,11 @@ func differenceInternal(sourceClnt, targetClnt Client, sourceURL, targetURL stri
firstContent: srcCtnt,
secondContent: tgtCtnt,
}
} else if multiMasterModTimeUpdated(srcCtnt, tgtCtnt) {
} else if activeActiveModTimeUpdated(srcCtnt, tgtCtnt) {
diffCh <- diffMessage{
FirstURL: srcCtnt.URL.String(),
SecondURL: tgtCtnt.URL.String(),
Diff: differInMMSourceMTime,
Diff: differInAASourceMTime,
firstContent: srcCtnt,
secondContent: tgtCtnt,
}
+49 -44
View File
@@ -72,9 +72,14 @@ var (
Name: "md5",
Usage: "force all upload(s) to calculate md5sum checksum",
},
cli.StringFlag{
Name: "multi-master",
Usage: "enable multi-master multi-site setup",
cli.BoolFlag{
Name: "multi-master",
Usage: "enable multi-master multi-site setup",
Hidden: true,
},
cli.BoolFlag{
Name: "active-active",
Usage: "enable active-active multi-site setup",
},
cli.BoolFlag{
Name: "disable-multipart",
@@ -174,9 +179,9 @@ EXAMPLES:
14. Mirror a local folder recursively to Amazon S3 cloud storage and preserve all local file attributes.
{{.Prompt}} {{.HelpName}} -a backup/ s3/archive
15. Cross mirror between sites in a multi-master deployment.
Site-A: {{.Prompt}} {{.HelpName}} --watch --multi-master siteA siteB
Site-B: {{.Prompt}} {{.HelpName}} --watch --multi-master siteB siteA
15. Cross mirror between sites in a active-active deployment.
Site-A: {{.Prompt}} {{.HelpName}} --watch --active-active siteA siteB
Site-B: {{.Prompt}} {{.HelpName}} --watch --active-active siteB siteA
`,
}
@@ -218,7 +223,7 @@ type mirrorJob struct {
excludeOptions []string
encKeyDB map[string][]prefixSSEPair
multiMasterEnable bool
activeActive bool
}
// mirrorMessage container for file mirror messages
@@ -280,7 +285,7 @@ func (mj *mirrorJob) doRemove(sURLs URLs) URLs {
// doMirror - Mirror an object to multiple destination. URLs status contains a copy of sURLs and error if any.
func (mj *mirrorJob) doMirrorWatch(ctx context.Context, targetPath string, tgtSSE encrypt.ServerSide, sURLs URLs) URLs {
shouldQueue := false
if !mj.isOverwrite && !mj.multiMasterEnable {
if !mj.isOverwrite && !mj.activeActive {
targetClient, err := newClient(targetPath)
if err != nil {
// cannot create targetclient
@@ -294,7 +299,7 @@ func (mj *mirrorJob) doMirrorWatch(ctx context.Context, targetPath string, tgtSS
} // doesn't exist
shouldQueue = true
}
if shouldQueue || mj.isOverwrite || mj.multiMasterEnable {
if shouldQueue || mj.isOverwrite || mj.activeActive {
// adjust total, because we want to show progress of
// the item still queued to be copied.
mj.status.Add(sURLs.SourceContent.Size)
@@ -339,13 +344,13 @@ func (mj *mirrorJob) doMirror(ctx context.Context, sURLs URLs) URLs {
sURLs.TargetContent.Metadata["X-Amz-Storage-Class"] = mj.storageClass
}
if mj.multiMasterEnable {
if mj.activeActive {
// If the source object already has source modtime attribute set, then
// use it in target. Otherwise use the S3 modtime instead.
if sURLs.SourceContent.Metadata[multiMasterSourceModTimeKey] != "" {
sURLs.TargetContent.Metadata[multiMasterSourceModTimeKey] = sURLs.SourceContent.Metadata[multiMasterSourceModTimeKey]
if sURLs.SourceContent.Metadata[activeActiveSourceModTimeKey] != "" {
sURLs.TargetContent.Metadata[activeActiveSourceModTimeKey] = sURLs.SourceContent.Metadata[activeActiveSourceModTimeKey]
} else {
sURLs.TargetContent.Metadata[multiMasterSourceModTimeKey] = sURLs.SourceContent.Time.Format(time.RFC3339Nano)
sURLs.TargetContent.Metadata[activeActiveSourceModTimeKey] = sURLs.SourceContent.Time.Format(time.RFC3339Nano)
}
}
@@ -390,7 +395,7 @@ func (mj *mirrorJob) monitorMirrorStatus() (errDuringMirror bool) {
errorIf(sURLs.Error.Trace(), "Failed to perform mirroring.")
errDuringMirror = true
}
if mj.multiMasterEnable {
if mj.activeActive {
close(mj.stopCh)
break
}
@@ -469,9 +474,9 @@ func (mj *mirrorJob) watchMirrorEvents(ctx context.Context, events []EventInfo)
DisableMultipart: mj.disableMultipart,
encKeyDB: mj.encKeyDB,
}
if mj.multiMasterEnable &&
mirrorURL.SourceContent.Metadata[multiMasterSourceModTimeKey] != "" {
// If source has multi-master attributes, it means that the
if mj.activeActive &&
mirrorURL.SourceContent.Metadata[activeActiveSourceModTimeKey] != "" {
// If source has active-active attributes, it means that the
// object was uploaded by "mc mirror", hence ignore the event
// to avoid copying it.
continue
@@ -494,7 +499,7 @@ func (mj *mirrorJob) watchMirrorEvents(ctx context.Context, events []EventInfo)
}
mirrorURL.TotalCount = mj.status.GetCounts()
mirrorURL.TotalSize = mj.status.Get()
if mirrorURL.TargetContent != nil && (mj.isRemove || mj.multiMasterEnable) {
if mirrorURL.TargetContent != nil && (mj.isRemove || mj.activeActive) {
mj.queueCh <- func() URLs {
return mj.doRemove(mirrorURL)
}
@@ -643,8 +648,8 @@ func (mj *mirrorJob) mirror(ctx context.Context, cancelMirror context.CancelFunc
return mj.monitorMirrorStatus()
}
func newMirrorJob(srcURL, dstURL string, isFake, isRemove, isOverwrite, isWatch, isPreserve, multiMasterEnable bool, excludeOptions []string, olderThan, newerThan string, storageClass string, userMetadata map[string]string, encKeyDB map[string][]prefixSSEPair, md5, disableMultipart bool) *mirrorJob {
if multiMasterEnable {
func newMirrorJob(srcURL, dstURL string, isFake, isRemove, isOverwrite, isWatch, isPreserve, activeActive bool, excludeOptions []string, olderThan, newerThan string, storageClass string, userMetadata map[string]string, encKeyDB map[string][]prefixSSEPair, md5, disableMultipart bool) *mirrorJob {
if activeActive {
isPreserve = true
}
mj := mirrorJob{
@@ -653,22 +658,22 @@ func newMirrorJob(srcURL, dstURL string, isFake, isRemove, isOverwrite, isWatch,
sourceURL: srcURL,
targetURL: dstURL,
isFake: isFake,
isRemove: isRemove,
isOverwrite: isOverwrite,
isWatch: isWatch,
isPreserve: isPreserve || multiMasterEnable,
md5: md5,
disableMultipart: disableMultipart,
excludeOptions: excludeOptions,
olderThan: olderThan,
newerThan: newerThan,
storageClass: storageClass,
userMetadata: userMetadata,
encKeyDB: encKeyDB,
statusCh: make(chan URLs),
watcher: NewWatcher(UTCNow()),
multiMasterEnable: multiMasterEnable,
isFake: isFake,
isRemove: isRemove,
isOverwrite: isOverwrite,
isWatch: isWatch,
isPreserve: isPreserve || activeActive,
md5: md5,
disableMultipart: disableMultipart,
excludeOptions: excludeOptions,
olderThan: olderThan,
newerThan: newerThan,
storageClass: storageClass,
userMetadata: userMetadata,
encKeyDB: encKeyDB,
statusCh: make(chan URLs),
watcher: NewWatcher(UTCNow()),
activeActive: activeActive,
}
mj.parallel, mj.queueCh = newParallelManager(mj.statusCh)
@@ -781,7 +786,7 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr
isOverwrite,
ctx.Bool("watch"),
ctx.Bool("a"),
ctx.Bool("multi-master"),
ctx.Bool("multi-master") || ctx.Bool("active-active"),
ctx.StringSlice("exclude"),
ctx.String("older-than"),
ctx.String("newer-than"),
@@ -801,7 +806,7 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr
// Synchronize buckets using dirDifference function
for d := range dirDifference(srcClt, dstClt, srcURL, dstURL) {
if d.Error != nil {
if mj.multiMasterEnable {
if mj.activeActive {
errorIf(d.Error, "Failed to start mirroring.")
return true
}
@@ -843,7 +848,7 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr
// monitor mode will watch the source folders for changes,
// and queue them for copying.
if err := mj.watchURL(newSrcClt); err != nil {
if mj.multiMasterEnable {
if mj.activeActive {
errorIf(err, "Failed to start monitoring.")
return true
}
@@ -860,7 +865,7 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr
// Create bucket if it doesn't exist at destination.
// ignore if already exists.
if mj.multiMasterEnable {
if mj.activeActive {
err = dstClt.MakeBucket(ctx.String("region"), true, withLock)
errorIf(err, "Unable to create bucket at `"+dstURL+"`.")
if err != nil {
@@ -875,14 +880,14 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr
if mode != "" {
err = dstClt.SetObjectLockConfig(mode, validity, unit)
errorIf(err, "Unable to set object lock config in `"+dstURL+"`.")
if err != nil && mj.multiMasterEnable {
if err != nil && mj.activeActive {
return true
}
}
err = copyBucketPolicies(srcClt, dstClt, isOverwrite)
errorIf(err, "Unable to copy bucket policies to `"+dstClt.GetURL().String()+"`.")
if err != nil && mj.multiMasterEnable {
if err != nil && mj.activeActive {
return true
}
}
@@ -891,7 +896,7 @@ func runMirror(srcURL, dstURL string, ctx *cli.Context, encKeyDB map[string][]pr
// monitor mode will watch the source folders for changes,
// and queue them for copying.
if err := mj.watchURL(srcClt); err != nil {
if mj.multiMasterEnable {
if mj.activeActive {
errorIf(err, "Failed to start monitoring.")
return true
}
@@ -932,7 +937,7 @@ func mainMirror(ctx *cli.Context) error {
}
}
if ctx.Bool("multi-master") {
if ctx.Bool("multi-master") || ctx.Bool("active-active") {
for {
runMirror(srcURL, tgtURL, ctx, encKeyDB)
time.Sleep(time.Second * 2)
+1 -1
View File
@@ -149,7 +149,7 @@ func deltaSourceTarget(sourceURL, targetURL string, isFake, isOverwrite, isRemov
// No difference, continue.
case differInType:
URLsCh <- URLs{Error: errInvalidTarget(diffMsg.SecondURL)}
case differInSize, differInMetadata, differInMMSourceMTime:
case differInSize, differInMetadata, differInAASourceMTime:
if !isOverwrite && !isFake {
// Size or time or etag differs but --overwrite not set.
URLsCh <- URLs{Error: errOverWriteNotAllowed(diffMsg.SecondURL)}