2021-09-27 08:45:32 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-07-29 07:17:28 +00: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 08:45:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (vs *VolumeServer) ReadAllNeedles(req *volume_server_pb.ReadAllNeedlesRequest, stream volume_server_pb.VolumeServer_ReadAllNeedlesServer) (err error) {
|
|
|
|
|
2021-09-27 09:51:31 +00:00
|
|
|
for _, vid := range req.VolumeIds {
|
2023-12-28 19:45:13 +00:00
|
|
|
if err := vs.streamReadOneVolume(needle.VolumeId(vid), stream); err != nil {
|
2021-09-27 09:51:31 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-12-28 19:45:13 +00:00
|
|
|
func (vs *VolumeServer) streamReadOneVolume(vid needle.VolumeId, stream volume_server_pb.VolumeServer_ReadAllNeedlesServer) error {
|
2021-09-27 09:51:31 +00:00
|
|
|
v := vs.store.GetVolume(vid)
|
2021-09-27 08:45:32 +00:00
|
|
|
if v == nil {
|
2021-09-27 09:51:31 +00:00
|
|
|
return fmt.Errorf("not found volume id %d", vid)
|
2021-09-27 08:45:32 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 10:07:44 +00:00
|
|
|
scanner := &storage.VolumeFileScanner4ReadAll{
|
|
|
|
Stream: stream,
|
|
|
|
V: v,
|
2021-09-27 08:45:32 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 09:01:29 +00:00
|
|
|
offset := int64(v.SuperBlock.BlockSize())
|
|
|
|
|
2023-12-28 19:45:13 +00:00
|
|
|
return storage.ScanVolumeFileFrom(v.Version(), v.DataBackend, offset, scanner)
|
2021-09-27 08:45:32 +00:00
|
|
|
}
|