Chris Lu
6 years ago
8 changed files with 364 additions and 12 deletions
-
7docker/Dockerfile
-
20docker/docker-compose.yml
-
13weed/command/volume.go
-
1weed/pb/Makefile
-
30weed/pb/volume_server.proto
-
220weed/pb/volume_server_pb/volume_server.pb.go
-
78weed/server/volume_grpc_server.go
-
3weed/server/volume_server.go
@ -0,0 +1,30 @@ |
|||||
|
syntax = "proto3"; |
||||
|
|
||||
|
package volume_server_pb; |
||||
|
|
||||
|
////////////////////////////////////////////////// |
||||
|
|
||||
|
service VolumeServer { |
||||
|
//Experts only: takes multiple fid parameters. This function does not propagate deletes to replicas. |
||||
|
rpc BatchDelete (BatchDeleteRequest) returns (BatchDeleteResponse) { |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
////////////////////////////////////////////////// |
||||
|
|
||||
|
message BatchDeleteRequest { |
||||
|
repeated string file_ids = 1; |
||||
|
} |
||||
|
|
||||
|
message BatchDeleteResponse { |
||||
|
repeated DeleteResult results = 1; |
||||
|
} |
||||
|
message DeleteResult { |
||||
|
string file_id = 1; |
||||
|
int32 status = 2; |
||||
|
string error = 3; |
||||
|
uint32 size = 4; |
||||
|
} |
||||
|
|
||||
|
message Empty { |
||||
|
} |
@ -0,0 +1,220 @@ |
|||||
|
// Code generated by protoc-gen-go.
|
||||
|
// source: volume_server.proto
|
||||
|
// DO NOT EDIT!
|
||||
|
|
||||
|
/* |
||||
|
Package volume_server_pb is a generated protocol buffer package. |
||||
|
|
||||
|
It is generated from these files: |
||||
|
volume_server.proto |
||||
|
|
||||
|
It has these top-level messages: |
||||
|
BatchDeleteRequest |
||||
|
BatchDeleteResponse |
||||
|
DeleteResult |
||||
|
Empty |
||||
|
*/ |
||||
|
package volume_server_pb |
||||
|
|
||||
|
import proto "github.com/golang/protobuf/proto" |
||||
|
import fmt "fmt" |
||||
|
import math "math" |
||||
|
|
||||
|
import ( |
||||
|
context "golang.org/x/net/context" |
||||
|
grpc "google.golang.org/grpc" |
||||
|
) |
||||
|
|
||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
var _ = proto.Marshal |
||||
|
var _ = fmt.Errorf |
||||
|
var _ = math.Inf |
||||
|
|
||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||
|
// is compatible with the proto package it is being compiled against.
|
||||
|
// A compilation error at this line likely means your copy of the
|
||||
|
// proto package needs to be updated.
|
||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
|
||||
|
type BatchDeleteRequest struct { |
||||
|
FileIds []string `protobuf:"bytes,1,rep,name=file_ids,json=fileIds" json:"file_ids,omitempty"` |
||||
|
} |
||||
|
|
||||
|
func (m *BatchDeleteRequest) Reset() { *m = BatchDeleteRequest{} } |
||||
|
func (m *BatchDeleteRequest) String() string { return proto.CompactTextString(m) } |
||||
|
func (*BatchDeleteRequest) ProtoMessage() {} |
||||
|
func (*BatchDeleteRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } |
||||
|
|
||||
|
func (m *BatchDeleteRequest) GetFileIds() []string { |
||||
|
if m != nil { |
||||
|
return m.FileIds |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
type BatchDeleteResponse struct { |
||||
|
Results []*DeleteResult `protobuf:"bytes,1,rep,name=results" json:"results,omitempty"` |
||||
|
} |
||||
|
|
||||
|
func (m *BatchDeleteResponse) Reset() { *m = BatchDeleteResponse{} } |
||||
|
func (m *BatchDeleteResponse) String() string { return proto.CompactTextString(m) } |
||||
|
func (*BatchDeleteResponse) ProtoMessage() {} |
||||
|
func (*BatchDeleteResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } |
||||
|
|
||||
|
func (m *BatchDeleteResponse) GetResults() []*DeleteResult { |
||||
|
if m != nil { |
||||
|
return m.Results |
||||
|
} |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
type DeleteResult struct { |
||||
|
FileId string `protobuf:"bytes,1,opt,name=file_id,json=fileId" json:"file_id,omitempty"` |
||||
|
Status int32 `protobuf:"varint,2,opt,name=status" json:"status,omitempty"` |
||||
|
Error string `protobuf:"bytes,3,opt,name=error" json:"error,omitempty"` |
||||
|
Size uint32 `protobuf:"varint,4,opt,name=size" json:"size,omitempty"` |
||||
|
} |
||||
|
|
||||
|
func (m *DeleteResult) Reset() { *m = DeleteResult{} } |
||||
|
func (m *DeleteResult) String() string { return proto.CompactTextString(m) } |
||||
|
func (*DeleteResult) ProtoMessage() {} |
||||
|
func (*DeleteResult) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } |
||||
|
|
||||
|
func (m *DeleteResult) GetFileId() string { |
||||
|
if m != nil { |
||||
|
return m.FileId |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (m *DeleteResult) GetStatus() int32 { |
||||
|
if m != nil { |
||||
|
return m.Status |
||||
|
} |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
func (m *DeleteResult) GetError() string { |
||||
|
if m != nil { |
||||
|
return m.Error |
||||
|
} |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (m *DeleteResult) GetSize() uint32 { |
||||
|
if m != nil { |
||||
|
return m.Size |
||||
|
} |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
type Empty struct { |
||||
|
} |
||||
|
|
||||
|
func (m *Empty) Reset() { *m = Empty{} } |
||||
|
func (m *Empty) String() string { return proto.CompactTextString(m) } |
||||
|
func (*Empty) ProtoMessage() {} |
||||
|
func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } |
||||
|
|
||||
|
func init() { |
||||
|
proto.RegisterType((*BatchDeleteRequest)(nil), "volume_server_pb.BatchDeleteRequest") |
||||
|
proto.RegisterType((*BatchDeleteResponse)(nil), "volume_server_pb.BatchDeleteResponse") |
||||
|
proto.RegisterType((*DeleteResult)(nil), "volume_server_pb.DeleteResult") |
||||
|
proto.RegisterType((*Empty)(nil), "volume_server_pb.Empty") |
||||
|
} |
||||
|
|
||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
var _ context.Context |
||||
|
var _ grpc.ClientConn |
||||
|
|
||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||
|
// is compatible with the grpc package it is being compiled against.
|
||||
|
const _ = grpc.SupportPackageIsVersion4 |
||||
|
|
||||
|
// Client API for VolumeServer service
|
||||
|
|
||||
|
type VolumeServerClient interface { |
||||
|
// Experts only: takes multiple fid parameters. This function does not propagate deletes to replicas.
|
||||
|
BatchDelete(ctx context.Context, in *BatchDeleteRequest, opts ...grpc.CallOption) (*BatchDeleteResponse, error) |
||||
|
} |
||||
|
|
||||
|
type volumeServerClient struct { |
||||
|
cc *grpc.ClientConn |
||||
|
} |
||||
|
|
||||
|
func NewVolumeServerClient(cc *grpc.ClientConn) VolumeServerClient { |
||||
|
return &volumeServerClient{cc} |
||||
|
} |
||||
|
|
||||
|
func (c *volumeServerClient) BatchDelete(ctx context.Context, in *BatchDeleteRequest, opts ...grpc.CallOption) (*BatchDeleteResponse, error) { |
||||
|
out := new(BatchDeleteResponse) |
||||
|
err := grpc.Invoke(ctx, "/volume_server_pb.VolumeServer/BatchDelete", in, out, c.cc, opts...) |
||||
|
if err != nil { |
||||
|
return nil, err |
||||
|
} |
||||
|
return out, nil |
||||
|
} |
||||
|
|
||||
|
// Server API for VolumeServer service
|
||||
|
|
||||
|
type VolumeServerServer interface { |
||||
|
// Experts only: takes multiple fid parameters. This function does not propagate deletes to replicas.
|
||||
|
BatchDelete(context.Context, *BatchDeleteRequest) (*BatchDeleteResponse, error) |
||||
|
} |
||||
|
|
||||
|
func RegisterVolumeServerServer(s *grpc.Server, srv VolumeServerServer) { |
||||
|
s.RegisterService(&_VolumeServer_serviceDesc, srv) |
||||
|
} |
||||
|
|
||||
|
func _VolumeServer_BatchDelete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { |
||||
|
in := new(BatchDeleteRequest) |
||||
|
if err := dec(in); err != nil { |
||||
|
return nil, err |
||||
|
} |
||||
|
if interceptor == nil { |
||||
|
return srv.(VolumeServerServer).BatchDelete(ctx, in) |
||||
|
} |
||||
|
info := &grpc.UnaryServerInfo{ |
||||
|
Server: srv, |
||||
|
FullMethod: "/volume_server_pb.VolumeServer/BatchDelete", |
||||
|
} |
||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
|
return srv.(VolumeServerServer).BatchDelete(ctx, req.(*BatchDeleteRequest)) |
||||
|
} |
||||
|
return interceptor(ctx, in, info, handler) |
||||
|
} |
||||
|
|
||||
|
var _VolumeServer_serviceDesc = grpc.ServiceDesc{ |
||||
|
ServiceName: "volume_server_pb.VolumeServer", |
||||
|
HandlerType: (*VolumeServerServer)(nil), |
||||
|
Methods: []grpc.MethodDesc{ |
||||
|
{ |
||||
|
MethodName: "BatchDelete", |
||||
|
Handler: _VolumeServer_BatchDelete_Handler, |
||||
|
}, |
||||
|
}, |
||||
|
Streams: []grpc.StreamDesc{}, |
||||
|
Metadata: "volume_server.proto", |
||||
|
} |
||||
|
|
||||
|
func init() { proto.RegisterFile("volume_server.proto", fileDescriptor0) } |
||||
|
|
||||
|
var fileDescriptor0 = []byte{ |
||||
|
// 252 bytes of a gzipped FileDescriptorProto
|
||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x50, 0xc1, 0x4a, 0xc3, 0x40, |
||||
|
0x10, 0x75, 0x6d, 0x93, 0xd8, 0x69, 0x05, 0x99, 0x8a, 0xae, 0x1e, 0x24, 0x2c, 0x0a, 0x39, 0x45, |
||||
|
0xa8, 0x17, 0xcf, 0xa2, 0x07, 0x4f, 0xc2, 0x0a, 0x9e, 0x84, 0xd0, 0xda, 0x11, 0x03, 0x5b, 0x37, |
||||
|
0xee, 0xec, 0x16, 0xf4, 0xeb, 0xc5, 0x4d, 0x95, 0xd6, 0x1c, 0x7a, 0x9b, 0x37, 0xf3, 0x1e, 0xef, |
||||
|
0xcd, 0x83, 0xf1, 0xd2,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||||
|
0x00, 0x00, 0xff, 0xff, 0xd3, 0x09, 0x3b, 0x59, 0x93, 0x01, 0x00, 0x00, |
||||
|
} |
@ -0,0 +1,78 @@ |
|||||
|
package weed_server |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"net/http" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/chrislusf/seaweedfs/weed/operation" |
||||
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" |
||||
|
"github.com/chrislusf/seaweedfs/weed/storage" |
||||
|
) |
||||
|
|
||||
|
func (vs *VolumeServer) BatchDelete(ctx context.Context, req *volume_server_pb.BatchDeleteRequest) (*volume_server_pb.BatchDeleteResponse, error) { |
||||
|
|
||||
|
resp := &volume_server_pb.BatchDeleteResponse{} |
||||
|
|
||||
|
now := uint64(time.Now().Unix()) |
||||
|
|
||||
|
for _, fid := range req.FileIds { |
||||
|
vid, id_cookie, err := operation.ParseFileId(fid) |
||||
|
if err != nil { |
||||
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ |
||||
|
FileId: fid, |
||||
|
Status: http.StatusBadRequest, |
||||
|
Error: err.Error()}) |
||||
|
continue |
||||
|
} |
||||
|
|
||||
|
n := new(storage.Needle) |
||||
|
volumeId, _ := storage.NewVolumeId(vid) |
||||
|
n.ParsePath(id_cookie) |
||||
|
|
||||
|
cookie := n.Cookie |
||||
|
if _, err := vs.store.ReadVolumeNeedle(volumeId, n); err != nil { |
||||
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ |
||||
|
FileId: fid, |
||||
|
Status: http.StatusNotFound, |
||||
|
Error: err.Error(), |
||||
|
}) |
||||
|
continue |
||||
|
} |
||||
|
|
||||
|
if n.IsChunkedManifest() { |
||||
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ |
||||
|
FileId: fid, |
||||
|
Status: http.StatusNotAcceptable, |
||||
|
Error: "ChunkManifest: not allowed in batch delete mode.", |
||||
|
}) |
||||
|
continue |
||||
|
} |
||||
|
|
||||
|
if n.Cookie != cookie { |
||||
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ |
||||
|
FileId: fid, |
||||
|
Status: http.StatusBadRequest, |
||||
|
Error: "File Random Cookie does not match.", |
||||
|
}) |
||||
|
break |
||||
|
} |
||||
|
n.LastModified = now |
||||
|
if size, err := vs.store.Delete(volumeId, n); err != nil { |
||||
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ |
||||
|
FileId: fid, |
||||
|
Status: http.StatusInternalServerError, |
||||
|
Error: err.Error()}, |
||||
|
) |
||||
|
} else { |
||||
|
resp.Results = append(resp.Results, &volume_server_pb.DeleteResult{ |
||||
|
FileId: fid, |
||||
|
Status: http.StatusAccepted, |
||||
|
Size: size}, |
||||
|
) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return resp, nil |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue