Browse Source

fix s3tests

pull/7426/head
Konstantin Lebedev 3 months ago
parent
commit
0e6f40e903
  1. 4
      .github/workflows/s3tests.yml
  2. 11
      weed/pb/filer_pb/filer_pb_helper.go
  3. 5
      weed/s3api/s3api_bucket_handlers.go
  4. 5
      weed/s3api/s3api_object_handlers_list.go
  5. 8
      weed/util/constants_lifecycle_interval_10sec.go
  6. 8
      weed/util/constants_lifecycle_interval_day.go

4
.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"

11
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) {

5
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)
}

5
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
}

8
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

8
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
Loading…
Cancel
Save