filer: avoid concurrent modification to result slice

fix https://github.com/chrislusf/seaweedfs/issues/972
This commit is contained in:
Chris Lu 2019-06-28 01:12:41 -07:00
parent a3d1296ed9
commit 327336ecf3

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
"google.golang.org/grpc" "google.golang.org/grpc"
"net/http" "net/http"
@ -84,8 +85,8 @@ func DeleteFilesWithLookupVolumeId(grpcDialOption grpc.DialOption, fileIds []str
} }
} }
resultChan := make(chan []*volume_server_pb.DeleteResult, len(server_to_fileIds))
var wg sync.WaitGroup var wg sync.WaitGroup
for server, fidList := range server_to_fileIds { for server, fidList := range server_to_fileIds {
wg.Add(1) wg.Add(1)
go func(server string, fidList []string) { go func(server string, fidList []string) {
@ -94,12 +95,19 @@ func DeleteFilesWithLookupVolumeId(grpcDialOption grpc.DialOption, fileIds []str
if deleteResults, deleteErr := DeleteFilesAtOneVolumeServer(server, grpcDialOption, fidList); deleteErr != nil { if deleteResults, deleteErr := DeleteFilesAtOneVolumeServer(server, grpcDialOption, fidList); deleteErr != nil {
err = deleteErr err = deleteErr
} else { } else {
ret = append(ret, deleteResults...) resultChan <- deleteResults
} }
}(server, fidList) }(server, fidList)
} }
wg.Wait() wg.Wait()
close(resultChan)
for result := range resultChan {
ret = append(ret, result...)
}
glog.V(0).Infof("deleted %d items", len(ret))
return ret, err return ret, err
} }