aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authoryanyiwu <i@yanyiwu.com>2015-01-08 15:54:50 +0800
committeryanyiwu <i@yanyiwu.com>2015-01-08 15:54:50 +0800
commitcacfc8586957220423210a496e3064d7eafab393 (patch)
treeea9b9f8eeb0b7a2799842401192da94b14d5aa2d /go
parentf2b07d605199282dc392c5c10b02218ada7eac56 (diff)
downloadseaweedfs-cacfc8586957220423210a496e3064d7eafab393.tar.xz
seaweedfs-cacfc8586957220423210a496e3064d7eafab393.zip
add some String() to make codes easier to read and debug
Diffstat (limited to 'go')
-rw-r--r--go/operation/lookup.go6
-rw-r--r--go/storage/volume_info.go5
-rw-r--r--go/topology/collection.go6
-rw-r--r--go/topology/data_node.go5
-rw-r--r--go/topology/volume_growth.go4
-rw-r--r--go/topology/volume_layout.go5
-rw-r--r--go/topology/volume_location_list.go8
-rw-r--r--go/util/concurrent_read_map.go4
8 files changed, 41 insertions, 2 deletions
diff --git a/go/operation/lookup.go b/go/operation/lookup.go
index e6b6658da..70bc7146e 100644
--- a/go/operation/lookup.go
+++ b/go/operation/lookup.go
@@ -3,7 +3,7 @@ package operation
import (
"encoding/json"
"errors"
- _ "fmt"
+ "fmt"
"math/rand"
"net/url"
"strings"
@@ -22,6 +22,10 @@ type LookupResult struct {
Error string `json:"error,omitempty"`
}
+func (lr *LookupResult) String() string {
+ return fmt.Sprintf("VolumeId:%s, Locations:%v, Error:%s", lr.VolumeId, lr.Locations, lr.Error)
+}
+
var (
vc VidCache
)
diff --git a/go/storage/volume_info.go b/go/storage/volume_info.go
index 6410c1784..bc8049ea4 100644
--- a/go/storage/volume_info.go
+++ b/go/storage/volume_info.go
@@ -1,6 +1,7 @@
package storage
import (
+ "fmt"
"github.com/chrislusf/weed-fs/go/operation"
)
@@ -36,3 +37,7 @@ func NewVolumeInfo(m *operation.VolumeInformationMessage) (vi VolumeInfo, err er
vi.Ttl = LoadTTLFromUint32(*m.Ttl)
return vi, nil
}
+
+func (vi VolumeInfo) String() string {
+ return fmt.Sprintf("Id:%s, Size:%d, ReplicaPlacement:%s, Collection:%s, Version:%v, FileCount:%d, DeleteCount:%d, DeletedByteCount:%d, ReadOnly:%v", vi.Id, vi.Size, vi.ReplicaPlacement, vi.Collection, vi.Version, vi.FileCount, vi.DeleteCount, vi.DeletedByteCount, vi.ReadOnly)
+}
diff --git a/go/topology/collection.go b/go/topology/collection.go
index 4b47ae88a..5437ffd79 100644
--- a/go/topology/collection.go
+++ b/go/topology/collection.go
@@ -1,6 +1,8 @@
package topology
import (
+ "fmt"
+
"github.com/chrislusf/weed-fs/go/storage"
"github.com/chrislusf/weed-fs/go/util"
)
@@ -17,6 +19,10 @@ func NewCollection(name string, volumeSizeLimit uint64) *Collection {
return c
}
+func (c *Collection) String() string {
+ return fmt.Sprintf("Name:%s, volumeSizeLimit:%d, storageType2VolumeLayout:%v", c.Name, c.volumeSizeLimit, c.storageType2VolumeLayout)
+}
+
func (c *Collection) GetOrCreateVolumeLayout(rp *storage.ReplicaPlacement, ttl *storage.TTL) *VolumeLayout {
keyString := rp.String()
if ttl != nil {
diff --git a/go/topology/data_node.go b/go/topology/data_node.go
index 109bd037f..09b9fac6c 100644
--- a/go/topology/data_node.go
+++ b/go/topology/data_node.go
@@ -1,6 +1,7 @@
package topology
import (
+ "fmt"
"strconv"
"github.com/chrislusf/weed-fs/go/glog"
@@ -26,6 +27,10 @@ func NewDataNode(id string) *DataNode {
return s
}
+func (dn *DataNode) String() string {
+ return fmt.Sprintf("NodeImpl:%s ,volumes:%v, Ip:%s, Port:%d, PublicUrl:%s, Dead:%v", dn.NodeImpl.String(), dn.volumes, dn.Ip, dn.Port, dn.PublicUrl, dn.Dead)
+}
+
func (dn *DataNode) AddOrUpdateVolume(v storage.VolumeInfo) {
if _, ok := dn.volumes[v.Id]; !ok {
dn.volumes[v.Id] = v
diff --git a/go/topology/volume_growth.go b/go/topology/volume_growth.go
index b1f241990..6124c0da2 100644
--- a/go/topology/volume_growth.go
+++ b/go/topology/volume_growth.go
@@ -30,6 +30,10 @@ type VolumeGrowth struct {
accessLock sync.Mutex
}
+func (o *VolumeGrowOption) String() string {
+ return fmt.Sprintf("Collection:%s, ReplicaPlacement:%v, Ttl:%v, DataCenter:%s, Rack:%s, DataNode:%s", o.Collection, o.ReplicaPlacement, o.Ttl, o.DataCenter, o.Rack, o.DataNode)
+}
+
func NewDefaultVolumeGrowth() *VolumeGrowth {
return &VolumeGrowth{}
}
diff --git a/go/topology/volume_layout.go b/go/topology/volume_layout.go
index de72bf895..4b1d3dad9 100644
--- a/go/topology/volume_layout.go
+++ b/go/topology/volume_layout.go
@@ -2,6 +2,7 @@ package topology
import (
"errors"
+ "fmt"
"math/rand"
"sync"
@@ -29,6 +30,10 @@ func NewVolumeLayout(rp *storage.ReplicaPlacement, ttl *storage.TTL, volumeSizeL
}
}
+func (vl *VolumeLayout) String() string {
+ return fmt.Sprintf("rp:%v, ttl:%v, vid2location:%v, writables:%v, volumeSizeLimit:%v", vl.rp, vl.ttl, vl.vid2location, vl.writables, vl.volumeSizeLimit)
+}
+
func (vl *VolumeLayout) RegisterVolume(v *storage.VolumeInfo, dn *DataNode) {
vl.accessLock.Lock()
defer vl.accessLock.Unlock()
diff --git a/go/topology/volume_location_list.go b/go/topology/volume_location_list.go
index 011614013..0f892c010 100644
--- a/go/topology/volume_location_list.go
+++ b/go/topology/volume_location_list.go
@@ -1,5 +1,9 @@
package topology
+import (
+ "fmt"
+)
+
type VolumeLocationList struct {
list []*DataNode
}
@@ -8,6 +12,10 @@ func NewVolumeLocationList() *VolumeLocationList {
return &VolumeLocationList{}
}
+func (dnll *VolumeLocationList) String() string {
+ return fmt.Sprintf("%v", dnll.list)
+}
+
func (dnll *VolumeLocationList) Head() *DataNode {
return dnll.list[0]
}
diff --git a/go/util/concurrent_read_map.go b/go/util/concurrent_read_map.go
index d16fdbcaf..880fe54e3 100644
--- a/go/util/concurrent_read_map.go
+++ b/go/util/concurrent_read_map.go
@@ -1,6 +1,8 @@
package util
-import "sync"
+import (
+ "sync"
+)
// A mostly for read map, which can thread-safely
// initialize the map entries.