mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add volume number param in assign operation
This commit is contained in:
parent
c34ffed43f
commit
61fa485700
|
@ -18,6 +18,7 @@ type VolumeAssignRequest struct {
|
||||||
DataCenter string
|
DataCenter string
|
||||||
Rack string
|
Rack string
|
||||||
DataNode string
|
DataNode string
|
||||||
|
WritableVolumeCount uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type AssignResult struct {
|
type AssignResult struct {
|
||||||
|
@ -53,6 +54,7 @@ func Assign(server string, grpcDialOption grpc.DialOption, primaryRequest *Volum
|
||||||
DataCenter: primaryRequest.DataCenter,
|
DataCenter: primaryRequest.DataCenter,
|
||||||
Rack: primaryRequest.Rack,
|
Rack: primaryRequest.Rack,
|
||||||
DataNode: primaryRequest.DataNode,
|
DataNode: primaryRequest.DataNode,
|
||||||
|
WritableVolumeCount: primaryRequest.WritableVolumeCount,
|
||||||
}
|
}
|
||||||
resp, grpcErr := masterClient.Assign(context.Background(), req)
|
resp, grpcErr := masterClient.Assign(context.Background(), req)
|
||||||
if grpcErr != nil {
|
if grpcErr != nil {
|
||||||
|
|
|
@ -140,6 +140,7 @@ message AssignRequest {
|
||||||
string rack = 6;
|
string rack = 6;
|
||||||
string data_node = 7;
|
string data_node = 7;
|
||||||
uint32 memory_map_max_size_mb = 8;
|
uint32 memory_map_max_size_mb = 8;
|
||||||
|
uint32 WritableVolumeCount = 9;
|
||||||
}
|
}
|
||||||
message AssignResponse {
|
message AssignResponse {
|
||||||
string fid = 1;
|
string fid = 1;
|
||||||
|
|
|
@ -656,6 +656,7 @@ type AssignRequest struct {
|
||||||
Rack string `protobuf:"bytes,6,opt,name=rack" json:"rack,omitempty"`
|
Rack string `protobuf:"bytes,6,opt,name=rack" json:"rack,omitempty"`
|
||||||
DataNode string `protobuf:"bytes,7,opt,name=data_node,json=dataNode" json:"data_node,omitempty"`
|
DataNode string `protobuf:"bytes,7,opt,name=data_node,json=dataNode" json:"data_node,omitempty"`
|
||||||
MemoryMapMaxSizeMb uint32 `protobuf:"varint,8,opt,name=memory_map_max_size_mb,json=MemoryMapMaxSizeMb" json:"memory_map_max_size_mb,omitempty"`
|
MemoryMapMaxSizeMb uint32 `protobuf:"varint,8,opt,name=memory_map_max_size_mb,json=MemoryMapMaxSizeMb" json:"memory_map_max_size_mb,omitempty"`
|
||||||
|
WritableVolumeCount uint32 `protobuf:"varint,9,opt,name=writable_volume_count" json:"writable_volume_count,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *AssignRequest) Reset() { *m = AssignRequest{} }
|
func (m *AssignRequest) Reset() { *m = AssignRequest{} }
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (ms *MasterServer) Assign(ctx context.Context, req *master_pb.AssignRequest
|
||||||
}
|
}
|
||||||
ms.vgLock.Lock()
|
ms.vgLock.Lock()
|
||||||
if !ms.Topo.HasWritableVolume(option) {
|
if !ms.Topo.HasWritableVolume(option) {
|
||||||
if _, err = ms.vg.AutomaticGrowByType(option, ms.grpcDialOption, ms.Topo); err != nil {
|
if _, err = ms.vg.AutomaticGrowByType(option, ms.grpcDialOption, ms.Topo, int(req.WritableVolumeCount)); err != nil {
|
||||||
ms.vgLock.Unlock()
|
ms.vgLock.Unlock()
|
||||||
return nil, fmt.Errorf("Cannot grow volume group! %v", err)
|
return nil, fmt.Errorf("Cannot grow volume group! %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,11 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
|
||||||
requestedCount = 1
|
requestedCount = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writableVolumeCount, e := strconv.Atoi(r.FormValue("writableVolumeCount"))
|
||||||
|
if e != nil {
|
||||||
|
writableVolumeCount = 0
|
||||||
|
}
|
||||||
|
|
||||||
option, err := ms.getVolumeGrowOption(r)
|
option, err := ms.getVolumeGrowOption(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeJsonQuiet(w, r, http.StatusNotAcceptable, operation.AssignResult{Error: err.Error()})
|
writeJsonQuiet(w, r, http.StatusNotAcceptable, operation.AssignResult{Error: err.Error()})
|
||||||
|
@ -114,7 +119,7 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
|
||||||
ms.vgLock.Lock()
|
ms.vgLock.Lock()
|
||||||
defer ms.vgLock.Unlock()
|
defer ms.vgLock.Unlock()
|
||||||
if !ms.Topo.HasWritableVolume(option) {
|
if !ms.Topo.HasWritableVolume(option) {
|
||||||
if _, err = ms.vg.AutomaticGrowByType(option, ms.grpcDialOption, ms.Topo); err != nil {
|
if _, err = ms.vg.AutomaticGrowByType(option, ms.grpcDialOption, ms.Topo, writableVolumeCount); err != nil {
|
||||||
writeJsonError(w, r, http.StatusInternalServerError,
|
writeJsonError(w, r, http.StatusInternalServerError,
|
||||||
fmt.Errorf("Cannot grow volume group! %v", err))
|
fmt.Errorf("Cannot grow volume group! %v", err))
|
||||||
return
|
return
|
||||||
|
|
|
@ -59,8 +59,11 @@ func (vg *VolumeGrowth) findVolumeCount(copyCount int) (count int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vg *VolumeGrowth) AutomaticGrowByType(option *VolumeGrowOption, grpcDialOption grpc.DialOption, topo *Topology) (count int, err error) {
|
func (vg *VolumeGrowth) AutomaticGrowByType(option *VolumeGrowOption, grpcDialOption grpc.DialOption, topo *Topology, targetCount int) (count int, err error) {
|
||||||
count, err = vg.GrowByCountAndType(grpcDialOption, vg.findVolumeCount(option.ReplicaPlacement.GetCopyCount()), option, topo)
|
if targetCount == 0 {
|
||||||
|
targetCount = vg.findVolumeCount(option.ReplicaPlacement.GetCopyCount())
|
||||||
|
}
|
||||||
|
count, err = vg.GrowByCountAndType(grpcDialOption, targetCount, option, topo)
|
||||||
if count > 0 && count%option.ReplicaPlacement.GetCopyCount() == 0 {
|
if count > 0 && count%option.ReplicaPlacement.GetCopyCount() == 0 {
|
||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue