alt request for dc preferred requests

This commit is contained in:
Chris Lu 2018-07-10 00:20:50 -07:00
parent 8a12fd9ec4
commit 007c4a1965
2 changed files with 15 additions and 4 deletions

View file

@ -173,7 +173,7 @@ func (fs *FilerServer) AssignVolume(ctx context.Context, req *filer_pb.AssignVol
ttlStr = strconv.Itoa(int(req.TtlSec)) ttlStr = strconv.Itoa(int(req.TtlSec))
} }
var backupRequest *operation.VolumeAssignRequest var altRequest *operation.VolumeAssignRequest
assignRequest := &operation.VolumeAssignRequest{ assignRequest := &operation.VolumeAssignRequest{
Count: uint64(req.Count), Count: uint64(req.Count),
@ -183,7 +183,7 @@ func (fs *FilerServer) AssignVolume(ctx context.Context, req *filer_pb.AssignVol
DataCenter: fs.option.DataCenter, DataCenter: fs.option.DataCenter,
} }
if fs.option.DataCenter != "" { if fs.option.DataCenter != "" {
backupRequest = &operation.VolumeAssignRequest{ altRequest = &operation.VolumeAssignRequest{
Count: uint64(req.Count), Count: uint64(req.Count),
Replication: req.Replication, Replication: req.Replication,
Collection: req.Collection, Collection: req.Collection,
@ -191,7 +191,7 @@ func (fs *FilerServer) AssignVolume(ctx context.Context, req *filer_pb.AssignVol
DataCenter: "", DataCenter: "",
} }
} }
assignResult, err := operation.Assign(fs.filer.GetMaster(), assignRequest, backupRequest) assignResult, err := operation.Assign(fs.filer.GetMaster(), assignRequest, altRequest)
if err != nil { if err != nil {
return nil, fmt.Errorf("assign volume: %v", err) return nil, fmt.Errorf("assign volume: %v", err)
} }

View file

@ -47,8 +47,19 @@ func (fs *FilerServer) assignNewFileInfo(w http.ResponseWriter, r *http.Request,
Replication: replication, Replication: replication,
Collection: collection, Collection: collection,
Ttl: r.URL.Query().Get("ttl"), Ttl: r.URL.Query().Get("ttl"),
DataCenter: fs.option.DataCenter,
} }
assignResult, ae := operation.Assign(fs.filer.GetMaster(), ar) var altRequest *operation.VolumeAssignRequest
if fs.option.DataCenter != "" {
altRequest = &operation.VolumeAssignRequest{
Count: 1,
Replication: replication,
Collection: collection,
Ttl: r.URL.Query().Get("ttl"),
DataCenter: "",
}
}
assignResult, ae := operation.Assign(fs.filer.GetMaster(), ar, altRequest)
if ae != nil { if ae != nil {
glog.V(0).Infoln("failing to assign a file id", ae.Error()) glog.V(0).Infoln("failing to assign a file id", ae.Error())
writeJsonError(w, r, http.StatusInternalServerError, ae) writeJsonError(w, r, http.StatusInternalServerError, ae)