Merge pull request #51 from aszxqw/master

add some String() to make codes easier to read and debug
This commit is contained in:
chrislusf 2015-01-08 00:12:56 -08:00
commit 31979d6192
8 changed files with 41 additions and 2 deletions

View file

@ -3,7 +3,7 @@ package operation
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
_ "fmt" "fmt"
"math/rand" "math/rand"
"net/url" "net/url"
"strings" "strings"
@ -22,6 +22,10 @@ type LookupResult struct {
Error string `json:"error,omitempty"` 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 ( var (
vc VidCache vc VidCache
) )

View file

@ -1,6 +1,7 @@
package storage package storage
import ( import (
"fmt"
"github.com/chrislusf/weed-fs/go/operation" "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) vi.Ttl = LoadTTLFromUint32(*m.Ttl)
return vi, nil 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)
}

View file

@ -1,6 +1,8 @@
package topology package topology
import ( import (
"fmt"
"github.com/chrislusf/weed-fs/go/storage" "github.com/chrislusf/weed-fs/go/storage"
"github.com/chrislusf/weed-fs/go/util" "github.com/chrislusf/weed-fs/go/util"
) )
@ -17,6 +19,10 @@ func NewCollection(name string, volumeSizeLimit uint64) *Collection {
return c 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 { func (c *Collection) GetOrCreateVolumeLayout(rp *storage.ReplicaPlacement, ttl *storage.TTL) *VolumeLayout {
keyString := rp.String() keyString := rp.String()
if ttl != nil { if ttl != nil {

View file

@ -1,6 +1,7 @@
package topology package topology
import ( import (
"fmt"
"strconv" "strconv"
"github.com/chrislusf/weed-fs/go/glog" "github.com/chrislusf/weed-fs/go/glog"
@ -26,6 +27,10 @@ func NewDataNode(id string) *DataNode {
return s 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) { func (dn *DataNode) AddOrUpdateVolume(v storage.VolumeInfo) {
if _, ok := dn.volumes[v.Id]; !ok { if _, ok := dn.volumes[v.Id]; !ok {
dn.volumes[v.Id] = v dn.volumes[v.Id] = v

View file

@ -30,6 +30,10 @@ type VolumeGrowth struct {
accessLock sync.Mutex 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 { func NewDefaultVolumeGrowth() *VolumeGrowth {
return &VolumeGrowth{} return &VolumeGrowth{}
} }

View file

@ -2,6 +2,7 @@ package topology
import ( import (
"errors" "errors"
"fmt"
"math/rand" "math/rand"
"sync" "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) { func (vl *VolumeLayout) RegisterVolume(v *storage.VolumeInfo, dn *DataNode) {
vl.accessLock.Lock() vl.accessLock.Lock()
defer vl.accessLock.Unlock() defer vl.accessLock.Unlock()

View file

@ -1,5 +1,9 @@
package topology package topology
import (
"fmt"
)
type VolumeLocationList struct { type VolumeLocationList struct {
list []*DataNode list []*DataNode
} }
@ -8,6 +12,10 @@ func NewVolumeLocationList() *VolumeLocationList {
return &VolumeLocationList{} return &VolumeLocationList{}
} }
func (dnll *VolumeLocationList) String() string {
return fmt.Sprintf("%v", dnll.list)
}
func (dnll *VolumeLocationList) Head() *DataNode { func (dnll *VolumeLocationList) Head() *DataNode {
return dnll.list[0] return dnll.list[0]
} }

View file

@ -1,6 +1,8 @@
package util package util
import "sync" import (
"sync"
)
// A mostly for read map, which can thread-safely // A mostly for read map, which can thread-safely
// initialize the map entries. // initialize the map entries.