add lots of error checking by GThomas

This commit is contained in:
Chris Lu
2013-02-26 22:54:22 -08:00
parent bd278337db
commit db8e27be6e
29 changed files with 268 additions and 170 deletions

View File

@@ -1,8 +1,8 @@
package topology
import (
_ "fmt"
"code.google.com/p/weed-fs/go/storage"
_ "fmt"
"strconv"
)

View File

@@ -1,8 +1,8 @@
package topology
import (
"fmt"
"code.google.com/p/weed-fs/go/storage"
"fmt"
)
type NodeId string

View File

@@ -1,9 +1,9 @@
package topology
import (
"code.google.com/p/weed-fs/go/storage"
"fmt"
"math/rand"
"code.google.com/p/weed-fs/go/storage"
)
type NodeList struct {

View File

@@ -7,7 +7,11 @@ import (
)
func TestXYZ(t *testing.T) {
topo := NewTopology("topo", "/etc/weed.conf", "/tmp", "test", 234, 5)
topo, err := NewTopology("topo", "/etc/weed.conf", "/tmp", "test", 234, 5)
if err != nil {
t.Error("cannot create new topology:", err)
t.FailNow()
}
for i := 0; i < 5; i++ {
dc := NewDataCenter("dc" + strconv.Itoa(i))
dc.activeVolumeCount = i
@@ -16,22 +20,22 @@ func TestXYZ(t *testing.T) {
}
nl := NewNodeList(topo.Children(), nil)
picked, ret := nl.RandomlyPickN(1)
picked, ret := nl.RandomlyPickN(1, 0)
if !ret || len(picked) != 1 {
t.Error("need to randomly pick 1 node")
}
picked, ret = nl.RandomlyPickN(4)
picked, ret = nl.RandomlyPickN(4, 0)
if !ret || len(picked) != 4 {
t.Error("need to randomly pick 4 nodes")
}
picked, ret = nl.RandomlyPickN(5)
picked, ret = nl.RandomlyPickN(5, 0)
if !ret || len(picked) != 5 {
t.Error("need to randomly pick 5 nodes")
}
picked, ret = nl.RandomlyPickN(6)
picked, ret = nl.RandomlyPickN(6, 0)
if ret || len(picked) != 0 {
t.Error("can not randomly pick 6 nodes:", ret, picked)
}

View File

@@ -1,72 +1,72 @@
package topology
import (
"code.google.com/p/weed-fs/go/storage"
"encoding/json"
"fmt"
"math/rand"
"code.google.com/p/weed-fs/go/storage"
"testing"
"time"
)
var topologyLayout = `
{
"dc1":{
"rack1":{
"server1":{
"volumes":[
{"id":1, "size":12312},
{"id":2, "size":12312},
{"id":3, "size":12312}
],
"limit":3
},
"server2":{
"volumes":[
{"id":4, "size":12312},
{"id":5, "size":12312},
{"id":6, "size":12312}
],
"limit":10
}
},
"rack2":{
"server1":{
"volumes":[
{"id":4, "size":12312},
{"id":5, "size":12312},
{"id":6, "size":12312}
],
"limit":4
},
"server2":{
"volumes":[],
"limit":4
},
"server3":{
"volumes":[
{"id":2, "size":12312},
{"id":3, "size":12312},
{"id":4, "size":12312}
],
"limit":2
}
}
},
"dc2":{
},
"dc3":{
"rack2":{
"server1":{
"volumes":[
{"id":1, "size":12312},
{"id":3, "size":12312},
{"id":5, "size":12312}
],
"limit":4
}
}
}
"dc1":{
"rack1":{
"server1":{
"volumes":[
{"id":1, "size":12312},
{"id":2, "size":12312},
{"id":3, "size":12312}
],
"limit":3
},
"server2":{
"volumes":[
{"id":4, "size":12312},
{"id":5, "size":12312},
{"id":6, "size":12312}
],
"limit":10
}
},
"rack2":{
"server1":{
"volumes":[
{"id":4, "size":12312},
{"id":5, "size":12312},
{"id":6, "size":12312}
],
"limit":4
},
"server2":{
"volumes":[],
"limit":4
},
"server3":{
"volumes":[
{"id":2, "size":12312},
{"id":3, "size":12312},
{"id":4, "size":12312}
],
"limit":2
}
}
},
"dc2":{
},
"dc3":{
"rack2":{
"server1":{
"volumes":[
{"id":1, "size":12312},
{"id":3, "size":12312},
{"id":5, "size":12312}
],
"limit":4
}
}
}
}
`
@@ -78,7 +78,10 @@ func setup(topologyLayout string) *Topology {
}
//need to connect all nodes first before server adding volumes
topo := NewTopology("mynetwork", "/etc/weed.conf", "/tmp", "test", 234, 5)
topo, err := NewTopology("mynetwork", "/etc/weed.conf", "/tmp", "test", 234, 5)
if err != nil {
fmt.Println("error:", err)
}
mTopology := data.(map[string]interface{})
for dcKey, dcValue := range mTopology {
dc := NewDataCenter(dcKey)
@@ -94,7 +97,10 @@ func setup(topologyLayout string) *Topology {
rack.LinkChildNode(server)
for _, v := range serverMap["volumes"].([]interface{}) {
m := v.(map[string]interface{})
vi := storage.VolumeInfo{Id: storage.VolumeId(int64(m["id"].(float64))), Size: int64(m["size"].(float64)), Version: storage.CurrentVersion}
vi := storage.VolumeInfo{
Id: storage.VolumeId(int64(m["id"].(float64))),
Size: uint64(m["size"].(float64)),
Version: storage.CurrentVersion}
server.AddOrUpdateVolume(vi)
}
server.UpAdjustMaxVolumeCountDelta(int(serverMap["limit"].(float64)))

View File

@@ -1,12 +1,12 @@
package topology
import (
"errors"
"io/ioutil"
"math/rand"
"code.google.com/p/weed-fs/go/directory"
"code.google.com/p/weed-fs/go/sequence"
"code.google.com/p/weed-fs/go/storage"
"errors"
"io/ioutil"
"math/rand"
)
type Topology struct {
@@ -28,7 +28,7 @@ type Topology struct {
configuration *Configuration
}
func NewTopology(id string, confFile string, dirname string, sequenceFilename string, volumeSizeLimit uint64, pulse int) *Topology {
func NewTopology(id string, confFile string, dirname string, sequenceFilename string, volumeSizeLimit uint64, pulse int) (*Topology, error) {
t := &Topology{}
t.id = NodeId(id)
t.nodeType = "Topology"
@@ -44,9 +44,9 @@ func NewTopology(id string, confFile string, dirname string, sequenceFilename st
t.chanRecoveredDataNodes = make(chan *DataNode)
t.chanFullVolumes = make(chan storage.VolumeInfo)
t.loadConfiguration(confFile)
err := t.loadConfiguration(confFile)
return t
return t, err
}
func (t *Topology) loadConfiguration(configurationFile string) error {

View File

@@ -1,12 +1,12 @@
package topology
import (
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
"encoding/json"
"errors"
"fmt"
"net/url"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
"time"
)

View File

@@ -1,9 +1,9 @@
package topology
import (
"code.google.com/p/weed-fs/go/storage"
"fmt"
"math/rand"
"code.google.com/p/weed-fs/go/storage"
"time"
)

View File

@@ -1,10 +1,10 @@
package topology
import (
"code.google.com/p/weed-fs/go/storage"
"errors"
"fmt"
"math/rand"
"code.google.com/p/weed-fs/go/storage"
)
type VolumeLayout struct {