diff --git a/weed/operation/assign_file_id.go b/weed/operation/assign_file_id.go index acc2d3034..a893e836b 100644 --- a/weed/operation/assign_file_id.go +++ b/weed/operation/assign_file_id.go @@ -19,7 +19,13 @@ type AssignResult struct { Error string `json:"error,omitempty"` } -func Assign(server string, count uint64, replication string, collection string, ttl string) (*AssignResult, error) { +/* +options params meaning: +options[0] main data Center +options[1] main rack +options[2] main data node +*/ +func Assign(server string, count uint64, replication string, collection string, ttl string, options ...string) (*AssignResult, error) { values := make(url.Values) values.Add("count", strconv.FormatUint(count, 10)) if replication != "" { @@ -31,6 +37,31 @@ func Assign(server string, count uint64, replication string, collection string, if ttl != "" { values.Add("ttl", ttl) } + + var dataCenter, rack, dataNode string + switch len(options) { + case 1: + dataCenter = options[0] + case 2: + dataCenter = options[0] + rack = options[1] + case 3: + dataCenter = options[0] + rack = options[1] + dataNode = options[2] + default: + } + + if dataCenter != "" { + values.Add("dataCenter", dataCenter) + } + if rack != "" { + values.Add("rack", rack) + } + if dataNode != "" { + values.Add("dataNode", dataNode) + } + jsonBlob, err := util.Post("http://"+server+"/dir/assign", values) glog.V(2).Info("assign result :", string(jsonBlob)) if err != nil {