2015-05-26 07:58:41 +00:00
|
|
|
package operation
|
|
|
|
|
|
|
|
import (
|
2018-10-15 08:19:15 +00:00
|
|
|
"context"
|
2018-12-22 19:10:08 +00:00
|
|
|
"fmt"
|
2018-10-15 08:19:15 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
2018-07-08 09:28:04 +00:00
|
|
|
. "github.com/chrislusf/seaweedfs/weed/storage/types"
|
2018-07-22 00:39:10 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2019-02-20 09:01:01 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"io"
|
2015-05-26 07:58:41 +00:00
|
|
|
)
|
|
|
|
|
2019-02-18 20:11:52 +00:00
|
|
|
func GetVolumeSyncStatus(server string, grpcDialOption grpc.DialOption, vid uint32) (resp *volume_server_pb.VolumeSyncStatusResponse, err error) {
|
2015-05-26 07:58:41 +00:00
|
|
|
|
2019-02-18 20:11:52 +00:00
|
|
|
WithVolumeServerClient(server, grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
|
2019-01-10 08:43:44 +00:00
|
|
|
|
2019-02-20 09:01:01 +00:00
|
|
|
resp, err = client.VolumeSyncStatus(context.Background(), &volume_server_pb.VolumeSyncStatusRequest{
|
2018-10-15 08:19:15 +00:00
|
|
|
VolumdId: vid,
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
2015-05-26 07:58:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 20:11:52 +00:00
|
|
|
func GetVolumeIdxEntries(server string, grpcDialOption grpc.DialOption, vid uint32, eachEntryFn func(key NeedleId, offset Offset, size uint32)) error {
|
2018-10-16 04:44:41 +00:00
|
|
|
|
2019-02-18 20:11:52 +00:00
|
|
|
return WithVolumeServerClient(server, grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
|
2018-12-22 19:10:08 +00:00
|
|
|
stream, err := client.VolumeSyncIndex(context.Background(), &volume_server_pb.VolumeSyncIndexRequest{
|
2018-10-16 04:44:41 +00:00
|
|
|
VolumdId: vid,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-12-22 19:10:08 +00:00
|
|
|
var indexFileContent []byte
|
|
|
|
|
|
|
|
for {
|
|
|
|
resp, err := stream.Recv()
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("read index entries: %v", err)
|
|
|
|
}
|
|
|
|
indexFileContent = append(indexFileContent, resp.IndexFileContent...)
|
|
|
|
}
|
|
|
|
|
|
|
|
dataSize := len(indexFileContent)
|
2018-10-16 04:44:41 +00:00
|
|
|
|
|
|
|
for idx := 0; idx+NeedleEntrySize <= dataSize; idx += NeedleEntrySize {
|
2018-12-22 19:10:08 +00:00
|
|
|
line := indexFileContent[idx : idx+NeedleEntrySize]
|
2018-10-16 04:44:41 +00:00
|
|
|
key := BytesToNeedleId(line[:NeedleIdSize])
|
|
|
|
offset := BytesToOffset(line[NeedleIdSize : NeedleIdSize+OffsetSize])
|
|
|
|
size := util.BytesToUint32(line[NeedleIdSize+OffsetSize : NeedleIdSize+OffsetSize+SizeSize])
|
|
|
|
eachEntryFn(key, offset, size)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2015-05-26 07:58:41 +00:00
|
|
|
})
|
|
|
|
}
|