Browse Source

fix updateTTL

pull/7426/head
Konstantin Lebedev 4 weeks ago
parent
commit
20fb1ead77
  1. 5
      .github/workflows/s3tests.yml
  2. 5
      weed/filer/filer.go
  3. 4
      weed/s3api/filer_util.go
  4. 2
      weed/s3api/s3api_object_handlers_list.go

5
.github/workflows/s3tests.yml

@ -1126,7 +1126,10 @@ jobs:
s3tests/functional/test_s3.py::test_copy_object_ifnonematch_good \ s3tests/functional/test_s3.py::test_copy_object_ifnonematch_good \
s3tests/functional/test_s3.py::test_lifecycle_set \ s3tests/functional/test_s3.py::test_lifecycle_set \
s3tests/functional/test_s3.py::test_lifecycle_get \ s3tests/functional/test_s3.py::test_lifecycle_get \
s3tests/functional/test_s3.py::test_lifecycle_set_filter
s3tests/functional/test_s3.py::test_lifecycle_set_filter \
s3tests/functional/test_s3.py::test_lifecycle_expiration \
s3tests/functional/test_s3.py::test_lifecyclev2_expiration \
s3tests/functional/test_s3.py::test_lifecycle_expiration_versioning_enabled
kill -9 $pid || true kill -9 $pid || true
# Clean up data directory # Clean up data directory
rm -rf "$WEED_DATA_DIR" || true rm -rf "$WEED_DATA_DIR" || true

5
weed/filer/filer.go

@ -380,10 +380,13 @@ func (f *Filer) doListDirectoryEntries(ctx context.Context, p util.FullPath, sta
if delErr := f.doDeleteEntryMetaAndData(ctx, entry, false, true, nil); delErr != nil { if delErr := f.doDeleteEntryMetaAndData(ctx, entry, false, true, nil); delErr != nil {
glog.ErrorfCtx(ctx, "doListDirectoryEntries doDeleteEntryMetaAndData %s failed: %v", entry.FullPath, delErr) glog.ErrorfCtx(ctx, "doListDirectoryEntries doDeleteEntryMetaAndData %s failed: %v", entry.FullPath, delErr)
} }
expiredCount++
return true return true
} }
} else if entry.Crtime.Add(time.Duration(entry.TtlSec) * time.Second).Before(time.Now()) { } else if entry.Crtime.Add(time.Duration(entry.TtlSec) * time.Second).Before(time.Now()) {
f.Store.DeleteOneEntry(ctx, entry)
if delErr := f.Store.DeleteOneEntry(ctx, entry); delErr != nil {
glog.ErrorfCtx(ctx, "doListDirectoryEntries DeleteOneEntry %s failed: %v", entry.FullPath, delErr)
}
expiredCount++ expiredCount++
return true return true
} }

4
weed/s3api/filer_util.go

@ -3,6 +3,7 @@ package s3api
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
"math" "math"
"strings" "strings"
@ -114,11 +115,12 @@ func (s3a *S3ApiServer) updateEntriesTTL(parentDirectoryPath string, ttlSec int3
ctx := context.Background() ctx := context.Background()
err := filer_pb.SeaweedList(ctx, client, parentDirectoryPath, "", func(entry *filer_pb.Entry, isLast bool) error { err := filer_pb.SeaweedList(ctx, client, parentDirectoryPath, "", func(entry *filer_pb.Entry, isLast bool) error {
if entry.IsDirectory { if entry.IsDirectory {
return s3a.updateEntriesTTL(fmt.Sprintf("%s/%s", parentDirectoryPath, entry.Name), ttlSec)
return s3a.updateEntriesTTL(fmt.Sprintf("%s/%s", strings.TrimRight(parentDirectoryPath, "/"), entry.Name), ttlSec)
} }
if entry.Attributes == nil { if entry.Attributes == nil {
entry.Attributes = &filer_pb.FuseAttributes{} entry.Attributes = &filer_pb.FuseAttributes{}
} }
entry.Extended[s3_constants.SeaweedFSExpiresS3] = []byte("true")
if entry.Attributes.TtlSec == ttlSec { if entry.Attributes.TtlSec == ttlSec {
return nil return nil
} }

2
weed/s3api/s3api_object_handlers_list.go

@ -141,8 +141,10 @@ func (s3a *S3ApiServer) ListObjectsV1Handler(w http.ResponseWriter, r *http.Requ
// Adjust marker if it ends with delimiter to skip all entries with that prefix // Adjust marker if it ends with delimiter to skip all entries with that prefix
marker = adjustMarkerForDelimiter(marker, delimiter) marker = adjustMarkerForDelimiter(marker, delimiter)
glog.V(3).Infof("Start listFilerEntries %s", originalPrefix)
response, err := s3a.listFilerEntries(bucket, originalPrefix, uint16(maxKeys), marker, delimiter, encodingTypeUrl, true) response, err := s3a.listFilerEntries(bucket, originalPrefix, uint16(maxKeys), marker, delimiter, encodingTypeUrl, true)
glog.V(3).Infof("End listFilerEntries %s", originalPrefix)
if err != nil { if err != nil {
s3err.WriteErrorResponse(w, r, s3err.ErrInternalError) s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)

Loading…
Cancel
Save