Browse Source

resolv comment

pull/7426/head
Konstantin Lebedev 2 months ago
parent
commit
cf75abb408
  1. 2
      weed/filer/filer.go
  2. 22
      weed/s3api/filer_util.go

2
weed/filer/filer.go

@ -354,7 +354,7 @@ func (f *Filer) FindEntry(ctx context.Context, p util.FullPath) (entry *Entry, e
if entry.IsExpireS3Enabled() { if entry.IsExpireS3Enabled() {
if entry.GetS3ExpireTime().Before(time.Now()) { if entry.GetS3ExpireTime().Before(time.Now()) {
f.Store.DeleteOneEntry(ctx, entry) f.Store.DeleteOneEntry(ctx, entry)
if delErr := f.doDeleteEntryMetaAndData(ctx, entry, false, true, nil); delErr != nil {
if delErr := f.doDeleteEntryMetaAndData(ctx, entry, true, false, nil); delErr != nil {
glog.ErrorfCtx(ctx, "FindEntry doDeleteEntryMetaAndData %s failed: %v", entry.FullPath, delErr) glog.ErrorfCtx(ctx, "FindEntry doDeleteEntryMetaAndData %s failed: %v", entry.FullPath, delErr)
} }
return nil, filer_pb.ErrNotFound return nil, filer_pb.ErrNotFound

22
weed/s3api/filer_util.go

@ -111,31 +111,37 @@ func (s3a *S3ApiServer) updateEntry(parentDirectoryPath string, newEntry *filer_
} }
func (s3a *S3ApiServer) updateEntriesTTL(parentDirectoryPath string, ttlSec int32) error { func (s3a *S3ApiServer) updateEntriesTTL(parentDirectoryPath string, ttlSec int32) error {
var updateErrors []error
err := s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error { err := s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
ctx := context.Background() ctx := context.Background()
err := filer_pb.SeaweedList(ctx, client, parentDirectoryPath, "", func(entry *filer_pb.Entry, isLast bool) error {
_ = 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", strings.TrimRight(parentDirectoryPath, "/"), entry.Name), ttlSec)
if err := s3a.updateEntriesTTL(fmt.Sprintf("%s/%s", strings.TrimRight(parentDirectoryPath, "/"), entry.Name), ttlSec); err != nil {
updateErrors = append(updateErrors, fmt.Errorf("dir %s: %w", entry.Name, err))
}
return nil
} }
if entry.Attributes == nil { if entry.Attributes == nil {
entry.Attributes = &filer_pb.FuseAttributes{} entry.Attributes = &filer_pb.FuseAttributes{}
} }
if entry.Extended == nil {
entry.Extended = make(map[string][]byte)
}
entry.Extended[s3_constants.SeaweedFSExpiresS3] = []byte("true") entry.Extended[s3_constants.SeaweedFSExpiresS3] = []byte("true")
if entry.Attributes.TtlSec == ttlSec { if entry.Attributes.TtlSec == ttlSec {
return nil return nil
} }
entry.Attributes.TtlSec = ttlSec entry.Attributes.TtlSec = ttlSec
err := filer_pb.UpdateEntry(ctx, client, &filer_pb.UpdateEntryRequest{
if err := filer_pb.UpdateEntry(ctx, client, &filer_pb.UpdateEntryRequest{
Directory: parentDirectoryPath, Directory: parentDirectoryPath,
Entry: entry, Entry: entry,
})
if err != nil {
return err
}); err != nil {
updateErrors = append(updateErrors, fmt.Errorf("file %s: %w", entry.Name, err))
} }
return nil return nil
}, "", false, math.MaxInt32) }, "", false, math.MaxInt32)
if err != nil {
return err
if len(updateErrors) > 0 {
return fmt.Errorf("failed to update %d entries: %v", len(updateErrors), updateErrors[0])
} }
return nil return nil
}) })

Loading…
Cancel
Save