9898: test updates
[arvados.git] / services / keepstore / s3_volume.go
index 0cfaaaf3b4a079c60afe4c0e96db12a4b03371ce..1a2a47b0df3b27d9c38ae7f4c8986a0f48f933a2 100644 (file)
@@ -18,8 +18,8 @@ import (
 )
 
 var (
-       // Returned by Trash if that operation is impossible with the
-       // current config.
+       // ErrS3TrashDisabled is returned by Trash if that operation
+       // is impossible with the current config.
        ErrS3TrashDisabled = fmt.Errorf("trash function is disabled because -trash-lifetime=0 and -s3-unsafe-delete=false")
 
        s3AccessKeyFile string
@@ -43,9 +43,6 @@ type s3VolumeAdder struct {
 }
 
 func (s *s3VolumeAdder) Set(bucketName string) error {
-       if trashLifetime != 0 {
-               return ErrNotImplemented
-       }
        if bucketName == "" {
                return fmt.Errorf("no container name given")
        }
@@ -575,8 +572,15 @@ func (v *S3Volume) EmptyTrash() {
                        continue
                }
                recent, err := v.Bucket.Head("recent/"+loc, nil)
-               if err != nil {
-                       log.Printf("warning: %s: EmptyTrash: cannot delete trash %q with no corresponding recent/* marker", v, trash.Key)
+               if err != nil && os.IsNotExist(v.translateError(err)) {
+                       log.Printf("warning: %s: EmptyTrash: found trash marker %q but no %q (%s); calling Untrash", v, trash.Key, "recent/"+loc, err)
+                       err = v.Untrash(loc)
+                       if err != nil {
+                               log.Printf("error: %s: EmptyTrash: Untrash(%q): %s", v, loc, err)
+                       }
+                       continue
+               } else if err != nil {
+                       log.Printf("warning: %s: EmptyTrash: HEAD %q: %s", v, "recent/"+loc, err)
                        continue
                }
                recentT, err := v.lastModified(recent)
@@ -585,7 +589,7 @@ func (v *S3Volume) EmptyTrash() {
                        continue
                }
                if trashT.Sub(recentT) < blobSignatureTTL {
-                       if age := startT.Sub(recentT); age >= blobSignatureTTL - v.raceWindow {
+                       if age := startT.Sub(recentT); age >= blobSignatureTTL-v.raceWindow {
                                // recent/loc is too old to protect
                                // loc from being Trashed again during
                                // the raceWindow that starts if we