mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-08-24 09:01:21 +08:00
lots of fix
1. sending 404 if not found 2. handle node-up/node-down/changing-max/volume-become-full
This commit is contained in:
parent
eae0080d75
commit
a1bc529db6
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -16,16 +15,20 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var uploadReplication *string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmdUpload.Run = runUpload // break init cycle
|
cmdUpload.Run = runUpload // break init cycle
|
||||||
IsDebug = cmdUpload.Flag.Bool("debug", false, "verbose debug information")
|
IsDebug = cmdUpload.Flag.Bool("debug", false, "verbose debug information")
|
||||||
server = cmdUpload.Flag.String("server", "localhost:9333", "weedfs master location")
|
server = cmdUpload.Flag.String("server", "localhost:9333", "weedfs master location")
|
||||||
|
uploadReplication = cmdUpload.Flag.String("replication", "00", "replication type(00,01,10,11)")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdUpload = &Command{
|
var cmdUpload = &Command{
|
||||||
UsageLine: "upload -server=localhost:9333 file1 file2 file2",
|
UsageLine: "upload -server=localhost:9333 file1 [file2 file3]",
|
||||||
Short: "upload a set of files, using consecutive file keys",
|
Short: "upload one or a list of files",
|
||||||
Long: `upload a set of files, using consecutive file keys.
|
Long: `upload one or a list of files.
|
||||||
|
It uses consecutive file keys for the list of files.
|
||||||
e.g. If the file1 uses key k, file2 can be read via k_1
|
e.g. If the file1 uses key k, file2 can be read via k_1
|
||||||
|
|
||||||
`,
|
`,
|
||||||
@ -35,14 +38,18 @@ type AssignResult struct {
|
|||||||
Fid string "fid"
|
Fid string "fid"
|
||||||
Url string "url"
|
Url string "url"
|
||||||
PublicUrl string "publicUrl"
|
PublicUrl string "publicUrl"
|
||||||
Count int `json:",string"`
|
Count int
|
||||||
Error string "error"
|
Error string "error"
|
||||||
}
|
}
|
||||||
|
|
||||||
func assign(count int) (*AssignResult, error) {
|
func assign(count int) (*AssignResult, error) {
|
||||||
values := make(url.Values)
|
values := make(url.Values)
|
||||||
values.Add("count", strconv.Itoa(count))
|
values.Add("count", strconv.Itoa(count))
|
||||||
jsonBlob, err := util.Post("http://"+*server+"/dir/assign", values)
|
values.Add("replication", *uploadReplication)
|
||||||
|
jsonBlob, err := util.Post("http://"+*server+"/dir/assign2", values)
|
||||||
|
if *IsDebug {
|
||||||
|
fmt.Println("debug", *IsDebug, "assign result :", string(jsonBlob))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -62,14 +69,23 @@ type UploadResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func upload(filename string, uploadUrl string) (int, string) {
|
func upload(filename string, uploadUrl string) (int, string) {
|
||||||
|
if *IsDebug {
|
||||||
|
fmt.Println("Start uploading file:", filename)
|
||||||
|
}
|
||||||
body_buf := bytes.NewBufferString("")
|
body_buf := bytes.NewBufferString("")
|
||||||
body_writer := multipart.NewWriter(body_buf)
|
body_writer := multipart.NewWriter(body_buf)
|
||||||
file_writer, err := body_writer.CreateFormFile("file", filename)
|
file_writer, err := body_writer.CreateFormFile("file", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if *IsDebug {
|
||||||
|
fmt.Println("Failed to create form file:", filename)
|
||||||
|
}
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
fh, err := os.Open(filename)
|
fh, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if *IsDebug {
|
||||||
|
fmt.Println("Failed to open file:", filename)
|
||||||
|
}
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
io.Copy(file_writer, fh)
|
io.Copy(file_writer, fh)
|
||||||
@ -77,10 +93,16 @@ func upload(filename string, uploadUrl string) (int, string) {
|
|||||||
body_writer.Close()
|
body_writer.Close()
|
||||||
resp, err := http.Post(uploadUrl, content_type, body_buf)
|
resp, err := http.Post(uploadUrl, content_type, body_buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if *IsDebug {
|
||||||
|
fmt.Println("Failed to upload file to", uploadUrl)
|
||||||
|
}
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
resp_body, err := ioutil.ReadAll(resp.Body)
|
resp_body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if *IsDebug {
|
||||||
|
fmt.Println("Upload response:", string(resp_body))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
@ -98,7 +120,7 @@ type SubmitResult struct {
|
|||||||
Size int "size"
|
Size int "size"
|
||||||
}
|
}
|
||||||
|
|
||||||
func submit(files []string)([]SubmitResult) {
|
func submit(files []string) []SubmitResult {
|
||||||
ret, err := assign(len(files))
|
ret, err := assign(len(files))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -117,10 +139,11 @@ func submit(files []string)([]SubmitResult) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runUpload(cmd *Command, args []string) bool {
|
func runUpload(cmd *Command, args []string) bool {
|
||||||
|
*IsDebug = true
|
||||||
if len(cmdUpload.Flag.Args()) == 0 {
|
if len(cmdUpload.Flag.Args()) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
results := submit(flag.Args())
|
results := submit(args)
|
||||||
bytes, _ := json.Marshal(results)
|
bytes, _ := json.Marshal(results)
|
||||||
fmt.Print(string(bytes))
|
fmt.Print(string(bytes))
|
||||||
return true
|
return true
|
||||||
|
@ -88,11 +88,12 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
cookie := n.Cookie
|
cookie := n.Cookie
|
||||||
count, e := store.Read(volumeId, n)
|
count, e := store.Read(volumeId, n)
|
||||||
if e != nil {
|
|
||||||
w.WriteHeader(404)
|
|
||||||
}
|
|
||||||
if *IsDebug {
|
if *IsDebug {
|
||||||
log.Println("read bytes", count, "error", e)
|
log.Println("read bytes", count, "error", e)
|
||||||
|
}
|
||||||
|
if e != nil || count <= 0 {
|
||||||
|
w.WriteHeader(404)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if n.Cookie != cookie {
|
if n.Cookie != cookie {
|
||||||
log.Println("request with unmaching cookie from ", r.RemoteAddr, "agent", r.UserAgent())
|
log.Println("request with unmaching cookie from ", r.RemoteAddr, "agent", r.UserAgent())
|
||||||
@ -161,6 +162,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJson(w, r, m)
|
writeJson(w, r, m)
|
||||||
}
|
}
|
||||||
func parseURLPath(path string) (vid, fid, ext string) {
|
func parseURLPath(path string) (vid, fid, ext string) {
|
||||||
|
|
||||||
sepIndex := strings.LastIndex(path, "/")
|
sepIndex := strings.LastIndex(path, "/")
|
||||||
commaIndex := strings.LastIndex(path[sepIndex:], ",")
|
commaIndex := strings.LastIndex(path[sepIndex:], ",")
|
||||||
if commaIndex <= 0 {
|
if commaIndex <= 0 {
|
||||||
@ -199,7 +201,6 @@ func runVolume(cmd *Command, args []string) bool {
|
|||||||
http.HandleFunc("/admin/assign_volume", assignVolumeHandler)
|
http.HandleFunc("/admin/assign_volume", assignVolumeHandler)
|
||||||
http.HandleFunc("/admin/set_volume_locations_list", setVolumeLocationsHandler)
|
http.HandleFunc("/admin/set_volume_locations_list", setVolumeLocationsHandler)
|
||||||
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
store.Join(*masterNode)
|
store.Join(*masterNode)
|
||||||
|
@ -126,7 +126,7 @@ func (vg *VolumeGrowth) GrowByCountAndType(count int, repType storage.Replicatio
|
|||||||
func (vg *VolumeGrowth) grow(topo *topology.Topology, vid storage.VolumeId, repType storage.ReplicationType, servers ...*topology.DataNode) error {
|
func (vg *VolumeGrowth) grow(topo *topology.Topology, vid storage.VolumeId, repType storage.ReplicationType, servers ...*topology.DataNode) error {
|
||||||
for _, server := range servers {
|
for _, server := range servers {
|
||||||
if err := AllocateVolume(server, vid, repType); err == nil {
|
if err := AllocateVolume(server, vid, repType); err == nil {
|
||||||
vi := storage.VolumeInfo{Id: vid, Size: 0}
|
vi := storage.VolumeInfo{Id: vid, Size: 0, RepType:repType}
|
||||||
server.AddOrUpdateVolume(vi)
|
server.AddOrUpdateVolume(vi)
|
||||||
topo.RegisterVolumeLayout(&vi, server)
|
topo.RegisterVolumeLayout(&vi, server)
|
||||||
fmt.Println("Created Volume", vid, "on", server)
|
fmt.Println("Created Volume", vid, "on", server)
|
||||||
|
@ -38,6 +38,7 @@ func (dc *DataCenter) GetOrCreateRack(ip string) *Rack {
|
|||||||
|
|
||||||
func (dc *DataCenter) ToMap() interface{}{
|
func (dc *DataCenter) ToMap() interface{}{
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
|
m["Max"] = dc.GetMaxVolumeCount()
|
||||||
m["Free"] = dc.FreeSpace()
|
m["Free"] = dc.FreeSpace()
|
||||||
var racks []interface{}
|
var racks []interface{}
|
||||||
for _, c := range dc.Children() {
|
for _, c := range dc.Children() {
|
||||||
|
@ -49,8 +49,8 @@ func (dn *DataNode) ToMap() interface{} {
|
|||||||
ret["Ip"] = dn.Ip
|
ret["Ip"] = dn.Ip
|
||||||
ret["Port"] = dn.Port
|
ret["Port"] = dn.Port
|
||||||
ret["Volumes"] = dn.GetActiveVolumeCount()
|
ret["Volumes"] = dn.GetActiveVolumeCount()
|
||||||
ret["MaxVolumeCount"] = dn.GetMaxVolumeCount()
|
ret["Max"] = dn.GetMaxVolumeCount()
|
||||||
ret["FreeVolumeCount"] = dn.FreeSpace()
|
ret["Free"] = dn.FreeSpace()
|
||||||
ret["PublicUrl"] = dn.PublicUrl
|
ret["PublicUrl"] = dn.PublicUrl
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,8 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVol
|
|||||||
if dn.Dead {
|
if dn.Dead {
|
||||||
dn.Dead = false
|
dn.Dead = false
|
||||||
r.GetTopology().chanRecoveredDataNodes <- dn
|
r.GetTopology().chanRecoveredDataNodes <- dn
|
||||||
}
|
|
||||||
dn.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount)
|
dn.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount)
|
||||||
|
}
|
||||||
return dn
|
return dn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,6 +51,7 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVol
|
|||||||
|
|
||||||
func (rack *Rack) ToMap() interface{} {
|
func (rack *Rack) ToMap() interface{} {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
|
m["Max"] = rack.GetMaxVolumeCount()
|
||||||
m["Free"] = rack.FreeSpace()
|
m["Free"] = rack.FreeSpace()
|
||||||
var dns []interface{}
|
var dns []interface{}
|
||||||
for _, c := range rack.Children() {
|
for _, c := range rack.Children() {
|
||||||
|
@ -23,8 +23,6 @@ type Topology struct {
|
|||||||
chanDeadDataNodes chan *DataNode
|
chanDeadDataNodes chan *DataNode
|
||||||
chanRecoveredDataNodes chan *DataNode
|
chanRecoveredDataNodes chan *DataNode
|
||||||
chanFullVolumes chan *storage.VolumeInfo
|
chanFullVolumes chan *storage.VolumeInfo
|
||||||
chanIncomplemteVolumes chan *storage.VolumeInfo
|
|
||||||
chanRecoveredVolumes chan *storage.VolumeInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTopology(id string, dirname string, filename string, volumeSizeLimit uint64, pulse int) *Topology {
|
func NewTopology(id string, dirname string, filename string, volumeSizeLimit uint64, pulse int) *Topology {
|
||||||
@ -42,8 +40,6 @@ func NewTopology(id string, dirname string, filename string, volumeSizeLimit uin
|
|||||||
t.chanDeadDataNodes = make(chan *DataNode)
|
t.chanDeadDataNodes = make(chan *DataNode)
|
||||||
t.chanRecoveredDataNodes = make(chan *DataNode)
|
t.chanRecoveredDataNodes = make(chan *DataNode)
|
||||||
t.chanFullVolumes = make(chan *storage.VolumeInfo)
|
t.chanFullVolumes = make(chan *storage.VolumeInfo)
|
||||||
t.chanIncomplemteVolumes = make(chan *storage.VolumeInfo)
|
|
||||||
t.chanRecoveredVolumes = make(chan *storage.VolumeInfo)
|
|
||||||
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
@ -124,6 +120,7 @@ func (t *Topology) GetOrCreateDataCenter(ip string) *DataCenter {
|
|||||||
|
|
||||||
func (t *Topology) ToMap() interface{} {
|
func (t *Topology) ToMap() interface{} {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
|
m["Max"] = t.GetMaxVolumeCount()
|
||||||
m["Free"] = t.FreeSpace()
|
m["Free"] = t.FreeSpace()
|
||||||
var dcs []interface{}
|
var dcs []interface{}
|
||||||
for _, c := range t.Children() {
|
for _, c := range t.Children() {
|
||||||
|
@ -18,10 +18,6 @@ func (t *Topology) StartRefreshWritableVolumes() {
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case v := <-t.chanIncomplemteVolumes:
|
|
||||||
fmt.Println("Volume", v, "is incomplete!")
|
|
||||||
case v := <-t.chanRecoveredVolumes:
|
|
||||||
fmt.Println("Volume", v, "is recovered!")
|
|
||||||
case v := <-t.chanFullVolumes:
|
case v := <-t.chanFullVolumes:
|
||||||
t.SetVolumeCapacityFull(v)
|
t.SetVolumeCapacityFull(v)
|
||||||
fmt.Println("Volume", v, "is full!")
|
fmt.Println("Volume", v, "is full!")
|
||||||
@ -38,6 +34,9 @@ func (t *Topology) StartRefreshWritableVolumes() {
|
|||||||
func (t *Topology) SetVolumeCapacityFull(volumeInfo *storage.VolumeInfo) {
|
func (t *Topology) SetVolumeCapacityFull(volumeInfo *storage.VolumeInfo) {
|
||||||
vl := t.GetVolumeLayout(volumeInfo.RepType)
|
vl := t.GetVolumeLayout(volumeInfo.RepType)
|
||||||
vl.SetVolumeCapacityFull(volumeInfo.Id)
|
vl.SetVolumeCapacityFull(volumeInfo.Id)
|
||||||
|
for _, dn := range vl.vid2location[volumeInfo.Id].list {
|
||||||
|
dn.UpAdjustActiveVolumeCountDelta(-1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
func (t *Topology) UnRegisterDataNode(dn *DataNode) {
|
func (t *Topology) UnRegisterDataNode(dn *DataNode) {
|
||||||
for _, v := range dn.volumes {
|
for _, v := range dn.volumes {
|
||||||
@ -45,6 +44,9 @@ func (t *Topology) UnRegisterDataNode(dn *DataNode) {
|
|||||||
vl := t.GetVolumeLayout(v.RepType)
|
vl := t.GetVolumeLayout(v.RepType)
|
||||||
vl.SetVolumeUnavailable(dn, v.Id)
|
vl.SetVolumeUnavailable(dn, v.Id)
|
||||||
}
|
}
|
||||||
|
dn.UpAdjustActiveVolumeCountDelta(-dn.GetActiveVolumeCount())
|
||||||
|
dn.UpAdjustMaxVolumeCountDelta(-dn.GetMaxVolumeCount())
|
||||||
|
dn.Parent().UnlinkChildNode(dn.Id())
|
||||||
}
|
}
|
||||||
func (t *Topology) RegisterRecoveredDataNode(dn *DataNode) {
|
func (t *Topology) RegisterRecoveredDataNode(dn *DataNode) {
|
||||||
for _, v := range dn.volumes {
|
for _, v := range dn.volumes {
|
||||||
|
@ -78,6 +78,7 @@ func (vl *VolumeLayout) setVolumeWritable(vid storage.VolumeId) bool {
|
|||||||
func (vl *VolumeLayout) SetVolumeUnavailable(dn *DataNode, vid storage.VolumeId) bool {
|
func (vl *VolumeLayout) SetVolumeUnavailable(dn *DataNode, vid storage.VolumeId) bool {
|
||||||
if vl.vid2location[vid].Remove(dn) {
|
if vl.vid2location[vid].Remove(dn) {
|
||||||
if vl.vid2location[vid].Length() < vl.repType.GetCopyCount() {
|
if vl.vid2location[vid].Length() < vl.repType.GetCopyCount() {
|
||||||
|
fmt.Println("Volume", vid, "has", vl.vid2location[vid].Length(), "replica, less than required", vl.repType.GetCopyCount())
|
||||||
return vl.removeFromWritable(vid)
|
return vl.removeFromWritable(vid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,6 +87,7 @@ func (vl *VolumeLayout) SetVolumeUnavailable(dn *DataNode, vid storage.VolumeId)
|
|||||||
func (vl *VolumeLayout) SetVolumeAvailable(dn *DataNode, vid storage.VolumeId) bool {
|
func (vl *VolumeLayout) SetVolumeAvailable(dn *DataNode, vid storage.VolumeId) bool {
|
||||||
if vl.vid2location[vid].Add(dn) {
|
if vl.vid2location[vid].Add(dn) {
|
||||||
if vl.vid2location[vid].Length() >= vl.repType.GetCopyCount() {
|
if vl.vid2location[vid].Length() >= vl.repType.GetCopyCount() {
|
||||||
|
fmt.Println("Volume", vid, "becomes writable")
|
||||||
return vl.setVolumeWritable(vid)
|
return vl.setVolumeWritable(vid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user