aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2025-11-03 17:59:44 +0500
committerKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2025-11-03 17:59:44 +0500
commit47c7d5fc8f8fdc59b9f5dcadb55380ef0b9150a6 (patch)
tree625b4bebbf5fbc6a409ed1181621bf83be2601bb
parentaea73270895d1b0b9ead38023398cc52d5a38f37 (diff)
downloadseaweedfs-47c7d5fc8f8fdc59b9f5dcadb55380ef0b9150a6.tar.xz
seaweedfs-47c7d5fc8f8fdc59b9f5dcadb55380ef0b9150a6.zip
fix test lifecycle expiration
-rw-r--r--weed/pb/filer_pb/filer_pb_helper.go2
-rw-r--r--weed/s3api/filer_util.go32
-rw-r--r--weed/s3api/s3api_bucket_handlers.go5
3 files changed, 38 insertions, 1 deletions
diff --git a/weed/pb/filer_pb/filer_pb_helper.go b/weed/pb/filer_pb/filer_pb_helper.go
index 361f5a60b..62d7e5d81 100644
--- a/weed/pb/filer_pb/filer_pb_helper.go
+++ b/weed/pb/filer_pb/filer_pb_helper.go
@@ -26,7 +26,7 @@ func (entry *Entry) IsDirectoryKeyObject() bool {
func (entry *Entry) IsExpired() bool {
return entry.Attributes != nil && entry.Attributes.TtlSec > 0 &&
- (entry.Attributes.GetMtime()+int64(entry.Attributes.TtlSec)) >= time.Now().UTC().Unix()
+ (entry.Attributes.GetMtime()+int64(entry.Attributes.TtlSec)) >= time.Now().Unix()
}
func (entry *Entry) FileMode() (fileMode os.FileMode) {
diff --git a/weed/s3api/filer_util.go b/weed/s3api/filer_util.go
index 9dd9a684e..e6090b458 100644
--- a/weed/s3api/filer_util.go
+++ b/weed/s3api/filer_util.go
@@ -3,6 +3,7 @@ package s3api
import (
"context"
"fmt"
+ "math"
"strings"
"github.com/seaweedfs/seaweedfs/weed/glog"
@@ -108,6 +109,37 @@ func (s3a *S3ApiServer) updateEntry(parentDirectoryPath string, newEntry *filer_
return err
}
+func (s3a *S3ApiServer) updateEntriesTTL(parentDirectoryPath string, ttlSec int32) error {
+ err := s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
+ ctx := context.Background()
+ err := filer_pb.SeaweedList(ctx, client, parentDirectoryPath, "", func(entry *filer_pb.Entry, isLast bool) error {
+ if entry.IsDirectory {
+ return s3a.updateEntriesTTL(fmt.Sprintf("%s/%s", parentDirectoryPath, entry.Name), ttlSec)
+ }
+ if entry.Attributes != nil {
+ entry.Attributes = &filer_pb.FuseAttributes{}
+ }
+ if entry.Attributes.TtlSec == ttlSec {
+ return nil
+ }
+ entry.Attributes.TtlSec = ttlSec
+ err := filer_pb.UpdateEntry(ctx, client, &filer_pb.UpdateEntryRequest{
+ Directory: parentDirectoryPath,
+ Entry: entry,
+ })
+ if err != nil {
+ return err
+ }
+ return nil
+ }, "", false, math.MaxInt32)
+ if err != nil {
+ return err
+ }
+ return nil
+ })
+ return err
+}
+
func (s3a *S3ApiServer) getCollectionName(bucket string) string {
if s3a.option.FilerGroup != "" {
return fmt.Sprintf("%s_%s", s3a.option.FilerGroup, bucket)
diff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.go
index c3f934557..e204ea2e0 100644
--- a/weed/s3api/s3api_bucket_handlers.go
+++ b/weed/s3api/s3api_bucket_handlers.go
@@ -627,6 +627,11 @@ func (s3a *S3ApiServer) PutBucketLifecycleConfigurationHandler(w http.ResponseWr
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return
}
+ parentDirectoryPath := fmt.Sprintf("%s/%s", s3a.option.BucketsPath, bucket)
+ ttlSec := int32((time.Duration(rule.Expiration.Days) * 24 * time.Hour).Seconds())
+ if updErr := s3a.updateEntriesTTL(parentDirectoryPath, ttlSec); updErr != nil {
+ glog.Errorf("PutBucketLifecycleConfigurationHandler update: %s", err)
+ }
changed = true
}