aboutsummaryrefslogtreecommitdiff
path: root/go/topology
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-02-26 22:54:22 -0800
committerChris Lu <chris.lu@gmail.com>2013-02-26 22:54:22 -0800
commitdb8e27be6ec7daa1a188f90f61e385c04cb6b008 (patch)
tree33e53b6ec51157709bc6121adeb8b19fe668c79b /go/topology
parentbd278337db4e3c1937f2d7cd1623ee9627c77619 (diff)
downloadseaweedfs-db8e27be6ec7daa1a188f90f61e385c04cb6b008.tar.xz
seaweedfs-db8e27be6ec7daa1a188f90f61e385c04cb6b008.zip
add lots of error checking by GThomas
Diffstat (limited to 'go/topology')
-rw-r--r--go/topology/data_node.go2
-rw-r--r--go/topology/node.go2
-rw-r--r--go/topology/node_list.go2
-rw-r--r--go/topology/node_list_test.go14
-rw-r--r--go/topology/topo_test.go124
-rw-r--r--go/topology/topology.go12
-rw-r--r--go/topology/topology_compact.go4
-rw-r--r--go/topology/topology_event_handling.go2
-rw-r--r--go/topology/volume_layout.go2
9 files changed, 87 insertions, 77 deletions
diff --git a/go/topology/data_node.go b/go/topology/data_node.go
index ba37f0d5f..ea4ea5d39 100644
--- a/go/topology/data_node.go
+++ b/go/topology/data_node.go
@@ -1,8 +1,8 @@
package topology
import (
- _ "fmt"
"code.google.com/p/weed-fs/go/storage"
+ _ "fmt"
"strconv"
)
diff --git a/go/topology/node.go b/go/topology/node.go
index 90826dfae..786f76702 100644
--- a/go/topology/node.go
+++ b/go/topology/node.go
@@ -1,8 +1,8 @@
package topology
import (
- "fmt"
"code.google.com/p/weed-fs/go/storage"
+ "fmt"
)
type NodeId string
diff --git a/go/topology/node_list.go b/go/topology/node_list.go
index 293f534ea..db7723714 100644
--- a/go/topology/node_list.go
+++ b/go/topology/node_list.go
@@ -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 {
diff --git a/go/topology/node_list_test.go b/go/topology/node_list_test.go
index 4cd2ebaa1..c6e530724 100644
--- a/go/topology/node_list_test.go
+++ b/go/topology/node_list_test.go
@@ -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)
}
diff --git a/go/topology/topo_test.go b/go/topology/topo_test.go
index f8af79b21..99e570821 100644
--- a/go/topology/topo_test.go
+++ b/go/topology/topo_test.go
@@ -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)))
diff --git a/go/topology/topology.go b/go/topology/topology.go
index 70a1ad268..74dc1cd09 100644
--- a/go/topology/topology.go
+++ b/go/topology/topology.go
@@ -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 {
diff --git a/go/topology/topology_compact.go b/go/topology/topology_compact.go
index 9c9abde4f..7215edc4e 100644
--- a/go/topology/topology_compact.go
+++ b/go/topology/topology_compact.go
@@ -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"
)
diff --git a/go/topology/topology_event_handling.go b/go/topology/topology_event_handling.go
index 9093bf884..fd2fe3bef 100644
--- a/go/topology/topology_event_handling.go
+++ b/go/topology/topology_event_handling.go
@@ -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"
)
diff --git a/go/topology/volume_layout.go b/go/topology/volume_layout.go
index b6e6e8bfe..f5c2e2360 100644
--- a/go/topology/volume_layout.go
+++ b/go/topology/volume_layout.go
@@ -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 {