Browse Source

volume server: read all files in a volume

pull/2348/head
Chris Lu 3 years ago
parent
commit
c4d7ee6c5c
  1. 10
      weed/pb/volume_server.proto
  2. 2174
      weed/pb/volume_server_pb/volume_server.pb.go
  3. 50
      weed/server/volume_grpc_read_all.go

10
weed/pb/volume_server.proto

@ -58,6 +58,8 @@ service VolumeServer {
}
rpc WriteNeedleBlob (WriteNeedleBlobRequest) returns (WriteNeedleBlobResponse) {
}
rpc ReadAllNeedles (ReadAllNeedlesRequest) returns (stream ReadAllNeedlesResponse) {
}
rpc VolumeTailSender (VolumeTailSenderRequest) returns (stream VolumeTailSenderResponse) {
}
@ -284,6 +286,14 @@ message WriteNeedleBlobRequest {
message WriteNeedleBlobResponse {
}
message ReadAllNeedlesRequest {
uint32 volume_id = 1;
}
message ReadAllNeedlesResponse {
uint64 needle_id = 1;
bytes needle_blob = 2;
}
message VolumeTailSenderRequest {
uint32 volume_id = 1;
uint64 since_ns = 2;

2174
weed/pb/volume_server_pb/volume_server.pb.go
File diff suppressed because it is too large
View File

50
weed/server/volume_grpc_read_all.go

@ -0,0 +1,50 @@
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"
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
)
func (vs *VolumeServer) ReadAllNeedles(req *volume_server_pb.ReadAllNeedlesRequest, stream volume_server_pb.VolumeServer_ReadAllNeedlesServer) (err error) {
v := vs.store.GetVolume(needle.VolumeId(req.VolumeId))
if v == nil {
return fmt.Errorf("not found volume id %d", req.VolumeId)
}
scanner := &VolumeFileScanner4ReadAll{
stream: stream,
}
err = storage.ScanVolumeFileFrom(v.Version(), v.DataBackend, super_block.SuperBlockSize, scanner)
return err
}
type VolumeFileScanner4ReadAll struct {
stream volume_server_pb.VolumeServer_ReadAllNeedlesServer
}
func (scanner *VolumeFileScanner4ReadAll) VisitSuperBlock(superBlock super_block.SuperBlock) error {
return nil
}
func (scanner *VolumeFileScanner4ReadAll) ReadNeedleBody() bool {
return true
}
func (scanner *VolumeFileScanner4ReadAll) VisitNeedle(n *needle.Needle, offset int64, needleHeader, needleBody []byte) error {
sendErr := scanner.stream.Send(&volume_server_pb.ReadAllNeedlesResponse{
NeedleId: uint64(n.Id),
NeedleBlob: needleBody,
})
if sendErr != nil {
return sendErr
}
return nil
}
Loading…
Cancel
Save