2021-09-27 16:45:32 +08:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (vs *VolumeServer) ReadAllNeedles(req *volume_server_pb.ReadAllNeedlesRequest, stream volume_server_pb.VolumeServer_ReadAllNeedlesServer) (err error) {
|
|
|
|
|
2021-09-27 17:51:31 +08:00
|
|
|
for _, vid := range req.VolumeIds {
|
|
|
|
if err := vs.streaReadOneVolume(needle.VolumeId(vid), stream, err); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vs *VolumeServer) streaReadOneVolume(vid needle.VolumeId, stream volume_server_pb.VolumeServer_ReadAllNeedlesServer, err error) error {
|
|
|
|
v := vs.store.GetVolume(vid)
|
2021-09-27 16:45:32 +08:00
|
|
|
if v == nil {
|
2021-09-27 17:51:31 +08:00
|
|
|
return fmt.Errorf("not found volume id %d", vid)
|
2021-09-27 16:45:32 +08:00
|
|
|
}
|
|
|
|
|
2021-09-27 18:07:44 +08:00
|
|
|
scanner := &storage.VolumeFileScanner4ReadAll{
|
|
|
|
Stream: stream,
|
|
|
|
V: v,
|
2021-09-27 16:45:32 +08:00
|
|
|
}
|
|
|
|
|
2021-09-27 17:01:29 +08:00
|
|
|
offset := int64(v.SuperBlock.BlockSize())
|
|
|
|
|
|
|
|
err = storage.ScanVolumeFileFrom(v.Version(), v.DataBackend, offset, scanner)
|
2021-09-27 16:45:32 +08:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|