Browse Source

fix test lifecycle expiration

pull/7426/head
Konstantin Lebedev 2 months ago
parent
commit
47c7d5fc8f
  1. 2
      weed/pb/filer_pb/filer_pb_helper.go
  2. 32
      weed/s3api/filer_util.go
  3. 5
      weed/s3api/s3api_bucket_handlers.go

2
weed/pb/filer_pb/filer_pb_helper.go

@ -26,7 +26,7 @@ func (entry *Entry) IsDirectoryKeyObject() bool {
func (entry *Entry) IsExpired() bool { func (entry *Entry) IsExpired() bool {
return entry.Attributes != nil && entry.Attributes.TtlSec > 0 && 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) { func (entry *Entry) FileMode() (fileMode os.FileMode) {

32
weed/s3api/filer_util.go

@ -3,6 +3,7 @@ package s3api
import ( import (
"context" "context"
"fmt" "fmt"
"math"
"strings" "strings"
"github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/glog"
@ -108,6 +109,37 @@ func (s3a *S3ApiServer) updateEntry(parentDirectoryPath string, newEntry *filer_
return err 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 { func (s3a *S3ApiServer) getCollectionName(bucket string) string {
if s3a.option.FilerGroup != "" { if s3a.option.FilerGroup != "" {
return fmt.Sprintf("%s_%s", s3a.option.FilerGroup, bucket) return fmt.Sprintf("%s_%s", s3a.option.FilerGroup, bucket)

5
weed/s3api/s3api_bucket_handlers.go

@ -627,6 +627,11 @@ func (s3a *S3ApiServer) PutBucketLifecycleConfigurationHandler(w http.ResponseWr
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError) s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)
return 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 changed = true
} }

Loading…
Cancel
Save