2021-09-27 16:45:32 +08:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
2021-09-27 16:45:32 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2022-08-19 14:25:32 +08:00
|
|
|
if err := vs.streamReadOneVolume(needle.VolumeId(vid), stream, err); err != nil {
|
2021-09-27 17:51:31 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-19 14:25:32 +08:00
|
|
|
func (vs *VolumeServer) streamReadOneVolume(vid needle.VolumeId, stream volume_server_pb.VolumeServer_ReadAllNeedlesServer, err error) error {
|
2021-09-27 17:51:31 +08:00
|
|
|
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
|
|
|
|
}
|