fix: notify bucket replication after replication/ilm (#11343)

master
Harshavardhana 4 years ago committed by GitHub
parent eb6871ecd9
commit 7e266293e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      cmd/bucket-lifecycle.go
  2. 48
      cmd/bucket-replication.go

@ -284,19 +284,17 @@ func deleteTransitionedObject(ctx context.Context, objectAPI ObjectLayer, bucket
if isDeleteTierOnly { if isDeleteTierOnly {
return nil return nil
} }
_, err = objectAPI.DeleteObject(ctx, bucket, object, opts)
objInfo, err := objectAPI.DeleteObject(ctx, bucket, object, opts)
if err != nil { if err != nil {
return err return err
} }
eventName := event.ObjectRemovedDelete eventName := event.ObjectRemovedDelete
if lcOpts.DeleteMarker { if lcOpts.DeleteMarker {
eventName = event.ObjectRemovedDeleteMarkerCreated eventName = event.ObjectRemovedDeleteMarkerCreated
} }
objInfo := ObjectInfo{
Name: object,
VersionID: lcOpts.VersionID,
DeleteMarker: lcOpts.DeleteMarker,
}
// Notify object deleted event. // Notify object deleted event.
sendEvent(eventArgs{ sendEvent(eventArgs{
EventName: eventName, EventName: eventName,
@ -358,18 +356,16 @@ func transitionObject(ctx context.Context, objectAPI ObjectLayer, objInfo Object
opts.TransitionStatus = lifecycle.TransitionComplete opts.TransitionStatus = lifecycle.TransitionComplete
eventName := event.ObjectTransitionComplete eventName := event.ObjectTransitionComplete
_, err = objectAPI.DeleteObject(ctx, oi.Bucket, oi.Name, opts) objInfo, err = objectAPI.DeleteObject(ctx, oi.Bucket, oi.Name, opts)
if err != nil { if err != nil {
eventName = event.ObjectTransitionFailed eventName = event.ObjectTransitionFailed
} }
// Notify object deleted event. // Notify object deleted event.
sendEvent(eventArgs{ sendEvent(eventArgs{
EventName: eventName, EventName: eventName,
BucketName: oi.Bucket, BucketName: objInfo.Bucket,
Object: ObjectInfo{ Object: objInfo,
Name: oi.Name,
VersionID: opts.VersionID,
},
Host: "Internal: [ILM-Transition]", Host: "Internal: [ILM-Transition]",
}) })
return err return err

@ -251,37 +251,31 @@ func replicateDelete(ctx context.Context, dobj DeletedObjectVersionInfo, objectA
versionPurgeStatus = Complete versionPurgeStatus = Complete
} }
} }
var eventName = event.ObjectReplicationComplete var eventName = event.ObjectReplicationComplete
if replicationStatus == string(replication.Failed) || versionPurgeStatus == Failed { if replicationStatus == string(replication.Failed) || versionPurgeStatus == Failed {
eventName = event.ObjectReplicationFailed eventName = event.ObjectReplicationFailed
} }
objInfo := ObjectInfo{
Name: dobj.ObjectName,
DeleteMarker: dobj.DeleteMarker,
VersionID: versionID,
ReplicationStatus: replication.StatusType(dobj.DeleteMarkerReplicationStatus),
VersionPurgeStatus: versionPurgeStatus,
}
eventArg := &eventArgs{
BucketName: bucket,
Object: objInfo,
Host: "Internal: [Replication]",
EventName: eventName,
}
sendEvent(*eventArg)
// Update metadata on the delete marker or purge permanent delete if replication success. // Update metadata on the delete marker or purge permanent delete if replication success.
if _, err = objectAPI.DeleteObject(ctx, bucket, dobj.ObjectName, ObjectOptions{ objInfo, err := objectAPI.DeleteObject(ctx, bucket, dobj.ObjectName, ObjectOptions{
VersionID: versionID, VersionID: versionID,
DeleteMarker: dobj.DeleteMarker, DeleteMarker: dobj.DeleteMarker,
DeleteMarkerReplicationStatus: replicationStatus, DeleteMarkerReplicationStatus: replicationStatus,
Versioned: globalBucketVersioningSys.Enabled(bucket), Versioned: globalBucketVersioningSys.Enabled(bucket),
VersionPurgeStatus: versionPurgeStatus, VersionPurgeStatus: versionPurgeStatus,
VersionSuspended: globalBucketVersioningSys.Suspended(bucket), VersionSuspended: globalBucketVersioningSys.Suspended(bucket),
}); err != nil { })
if err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to update replication metadata for %s/%s %s: %w", bucket, dobj.ObjectName, dobj.VersionID, err)) logger.LogIf(ctx, fmt.Errorf("Unable to update replication metadata for %s/%s %s: %w", bucket, dobj.ObjectName, dobj.VersionID, err))
} }
sendEvent(eventArgs{
BucketName: bucket,
Object: objInfo,
Host: "Internal: [Replication]",
EventName: eventName,
})
} }
func getCopyObjMetadata(oi ObjectInfo, dest replication.Destination) map[string]string { func getCopyObjMetadata(oi ObjectInfo, dest replication.Destination) map[string]string {
@ -511,6 +505,7 @@ func replicateObject(ctx context.Context, objInfo ObjectInfo, objectAPI ObjectLa
} }
r.Close() r.Close()
} }
objInfo.UserDefined[xhttp.AmzBucketReplicationStatus] = replicationStatus.String() objInfo.UserDefined[xhttp.AmzBucketReplicationStatus] = replicationStatus.String()
if objInfo.UserTags != "" { if objInfo.UserTags != "" {
objInfo.UserDefined[xhttp.AmzObjectTagging] = objInfo.UserTags objInfo.UserDefined[xhttp.AmzObjectTagging] = objInfo.UserTags
@ -524,20 +519,23 @@ func replicateObject(ctx context.Context, objInfo ObjectInfo, objectAPI ObjectLa
if replicationStatus == replication.Failed { if replicationStatus == replication.Failed {
eventName = event.ObjectReplicationFailed eventName = event.ObjectReplicationFailed
} }
sendEvent(eventArgs{
EventName: eventName,
BucketName: bucket,
Object: objInfo,
Host: "Internal: [Replication]",
})
objInfo.metadataOnly = true // Perform only metadata updates. objInfo.metadataOnly = true // Perform only metadata updates.
if _, err = objectAPI.CopyObject(ctx, bucket, object, bucket, object, objInfo, ObjectOptions{ objInfo, err = objectAPI.CopyObject(ctx, bucket, object, bucket, object, objInfo, ObjectOptions{
VersionID: objInfo.VersionID, VersionID: objInfo.VersionID,
}, ObjectOptions{ }, ObjectOptions{
VersionID: objInfo.VersionID, VersionID: objInfo.VersionID,
}); err != nil { })
if err != nil {
logger.LogIf(ctx, fmt.Errorf("Unable to update replication metadata for %s: %s", objInfo.VersionID, err)) logger.LogIf(ctx, fmt.Errorf("Unable to update replication metadata for %s: %s", objInfo.VersionID, err))
} }
sendEvent(eventArgs{
EventName: eventName,
BucketName: bucket,
Object: objInfo,
Host: "Internal: [Replication]",
})
} }
// filterReplicationStatusMetadata filters replication status metadata for COPY // filterReplicationStatusMetadata filters replication status metadata for COPY

Loading…
Cancel
Save