diff options
| -rw-r--r-- | .github/workflows/s3tests.yml | 4 | ||||
| -rw-r--r-- | weed/pb/filer_pb/filer_pb_helper.go | 11 | ||||
| -rw-r--r-- | weed/s3api/s3api_bucket_handlers.go | 5 | ||||
| -rw-r--r-- | weed/s3api/s3api_object_handlers_list.go | 5 | ||||
| -rw-r--r-- | weed/util/constants_lifecycle_interval_10sec.go | 8 | ||||
| -rw-r--r-- | weed/util/constants_lifecycle_interval_day.go | 8 |
6 files changed, 34 insertions, 7 deletions
diff --git a/.github/workflows/s3tests.yml b/.github/workflows/s3tests.yml index accfe8b01..2796bf636 100644 --- a/.github/workflows/s3tests.yml +++ b/.github/workflows/s3tests.yml @@ -54,7 +54,7 @@ jobs: shell: bash run: | cd weed - go install -buildvcs=false + go install -tags s3tests -buildvcs=false set -x # Create clean data directory for this test run export WEED_DATA_DIR="/tmp/seaweedfs-s3tests-$(date +%s)" @@ -794,7 +794,7 @@ jobs: exit 1 fi - go install -tags "sqlite" -buildvcs=false + go install -tags "sqlite s3tests" -buildvcs=false # Create clean data directory for this test run with unique timestamp and process ID export WEED_DATA_DIR="/tmp/seaweedfs-sql-test-$(date +%s)-$$" mkdir -p "$WEED_DATA_DIR" diff --git a/weed/pb/filer_pb/filer_pb_helper.go b/weed/pb/filer_pb/filer_pb_helper.go index c72034bb4..3ce494716 100644 --- a/weed/pb/filer_pb/filer_pb_helper.go +++ b/weed/pb/filer_pb/filer_pb_helper.go @@ -24,9 +24,18 @@ func (entry *Entry) IsDirectoryKeyObject() bool { return entry.IsDirectory && entry.Attributes != nil && entry.Attributes.Mime != "" } +func (entry *Entry) GetExpiryTime() (expiryTime int64) { + expiryTime = entry.Attributes.Mtime + if expiryTime == 0 { + expiryTime = entry.Attributes.Crtime + } + expiryTime += int64(entry.Attributes.TtlSec) + return expiryTime +} + func (entry *Entry) IsExpired() bool { return entry != nil && entry.Attributes != nil && entry.Attributes.TtlSec > 0 && - (entry.Attributes.GetMtime()+int64(entry.Attributes.TtlSec)) >= time.Now().Unix() + time.Now().Unix() >= entry.GetExpiryTime() } func (entry *Entry) FileMode() (fileMode os.FileMode) { diff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.go index 32bfc2832..390b19dbf 100644 --- a/weed/s3api/s3api_bucket_handlers.go +++ b/weed/s3api/s3api_bucket_handlers.go @@ -7,6 +7,7 @@ import ( "encoding/xml" "errors" "fmt" + "github.com/seaweedfs/seaweedfs/weed/util" "math" "net/http" "sort" @@ -615,7 +616,7 @@ func (s3a *S3ApiServer) PutBucketLifecycleConfigurationHandler(w http.ResponseWr } locationPrefix := fmt.Sprintf("%s/%s/%s", s3a.option.BucketsPath, bucket, rulePrefix) locConf := &filer_pb.FilerConf_PathConf{ - LocationPrefix: fmt.Sprintf("%s/%s/%s", s3a.option.BucketsPath, bucket, rulePrefix), + LocationPrefix: locationPrefix, Collection: collectionName, Ttl: fmt.Sprintf("%dd", rule.Expiration.Days), } @@ -627,7 +628,7 @@ func (s3a *S3ApiServer) PutBucketLifecycleConfigurationHandler(w http.ResponseWr s3err.WriteErrorResponse(w, r, s3err.ErrInternalError) return } - ttlSec := int32((time.Duration(rule.Expiration.Days) * 24 * time.Hour).Seconds()) + ttlSec := int32((time.Duration(rule.Expiration.Days) * util.LifeCycleInterval).Seconds()) if updErr := s3a.updateEntriesTTL(locationPrefix, ttlSec); updErr != nil { glog.Errorf("PutBucketLifecycleConfigurationHandler update: %s", err) } diff --git a/weed/s3api/s3api_object_handlers_list.go b/weed/s3api/s3api_object_handlers_list.go index f0479b4ea..5730df613 100644 --- a/weed/s3api/s3api_object_handlers_list.go +++ b/weed/s3api/s3api_object_handlers_list.go @@ -304,8 +304,9 @@ func (s3a *S3ApiServer) listFilerEntries(bucket string, originalPrefix string, m } } if s3a.option.AllowDeleteObjectsByTTL && entry.IsExpired() { - if delErr := doDeleteEntry(client, dir, entry.Name, true, false); delErr != nil { - glog.Errorf("delete expired entries %s/%s: %v", dir, entry.Name, delErr) + glog.V(1).Infof("Do delete expired entry %s/%s", dirName, entryName) + if delErr := doDeleteEntry(client, dirName, entryName, true, false); delErr != nil { + glog.Errorf("delete expired entries %s/%s: %v", dirName, entryName, delErr) } return } diff --git a/weed/util/constants_lifecycle_interval_10sec.go b/weed/util/constants_lifecycle_interval_10sec.go new file mode 100644 index 000000000..60f19c316 --- /dev/null +++ b/weed/util/constants_lifecycle_interval_10sec.go @@ -0,0 +1,8 @@ +//go:build s3tests +// +build s3tests + +package util + +import "time" + +const LifeCycleInterval = 10 * time.Second diff --git a/weed/util/constants_lifecycle_interval_day.go b/weed/util/constants_lifecycle_interval_day.go new file mode 100644 index 000000000..e2465ad5f --- /dev/null +++ b/weed/util/constants_lifecycle_interval_day.go @@ -0,0 +1,8 @@ +//go:build !s3tests +// +build !s3tests + +package util + +import "time" + +const LifeCycleInterval = 24 * time.Hour |
