seaweedfs/weed/filesys/wfs_deletion.go

59 lines
1.2 KiB
Go
Raw Normal View History

2019-01-01 10:33:57 +00:00
package filesys
import (
"context"
"time"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
func (wfs *WFS) loopProcessingDeletion() {
ticker := time.NewTicker(2 * time.Second)
wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
var fileIds []string
for {
select {
case fids := <-wfs.fileIdsDeletionChan:
fileIds = append(fileIds, fids...)
2019-01-04 06:21:57 +00:00
if len(fileIds) >= 1024 {
2019-01-01 10:33:57 +00:00
glog.V(1).Infof("deleting fileIds len=%d", len(fileIds))
deleteFileIds(context.Background(), client, fileIds)
fileIds = fileIds[:0]
}
case <-ticker.C:
if len(fileIds) > 0 {
glog.V(1).Infof("timed deletion fileIds len=%d", len(fileIds))
deleteFileIds(context.Background(), client, fileIds)
fileIds = fileIds[:0]
}
}
}
})
}
2019-01-06 06:51:50 +00:00
func (wfs *WFS) deleteFileChunks(chunks []*filer_pb.FileChunk) {
if len(chunks) == 0 {
return
}
var fileIds []string
for _, chunk := range chunks {
fileIds = append(fileIds, chunk.FileId)
}
var async = false
if async {
2019-01-01 10:33:57 +00:00
wfs.fileIdsDeletionChan <- fileIds
2019-01-06 06:51:50 +00:00
return
2019-01-01 10:33:57 +00:00
}
2019-01-06 06:51:50 +00:00
wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
deleteFileIds(context.Background(), client, fileIds)
return nil
})
2019-01-01 10:33:57 +00:00
}