Chris Lu
13 years ago
8 changed files with 172 additions and 129 deletions
-
1weed-fs/bin/.gitignore
-
5weed-fs/pkg/linux_amd64/pkg/.gitignore
-
9weed-fs/src/pkg/topology/data_center.go
-
162weed-fs/src/pkg/topology/node.go
-
9weed-fs/src/pkg/topology/rack.go
-
37weed-fs/src/pkg/topology/server.go
-
48weed-fs/src/pkg/topology/topo_test.go
-
30weed-fs/src/pkg/topology/topology.go
@ -0,0 +1 @@ |
|||||
|
/weed |
@ -0,0 +1,5 @@ |
|||||
|
/directory.a |
||||
|
/replication.a |
||||
|
/storage.a |
||||
|
/topology.a |
||||
|
/util.a |
@ -1,28 +1,31 @@ |
|||||
package topology |
package topology |
||||
|
|
||||
import ( |
import ( |
||||
"pkg/storage" |
|
||||
_ "fmt" |
|
||||
|
_ "fmt" |
||||
|
"pkg/storage" |
||||
) |
) |
||||
|
|
||||
type Server struct { |
type Server struct { |
||||
Node |
|
||||
volumes map[storage.VolumeId]*storage.VolumeInfo |
|
||||
Ip NodeId |
|
||||
Port int |
|
||||
PublicUrl string |
|
||||
|
NodeImpl |
||||
|
volumes map[storage.VolumeId]*storage.VolumeInfo |
||||
|
Ip NodeId |
||||
|
Port int |
||||
|
PublicUrl string |
||||
} |
} |
||||
func NewServer(id NodeId) *Server{ |
|
||||
s := &Server{} |
|
||||
s.Node.Id = id |
|
||||
s.volumes = make(map[storage.VolumeId]*storage.VolumeInfo) |
|
||||
return s |
|
||||
|
|
||||
|
func NewServer(id string) *Server { |
||||
|
s := &Server{} |
||||
|
s.id = NodeId(id) |
||||
|
s.nodeType = "Server" |
||||
|
s.volumes = make(map[storage.VolumeId]*storage.VolumeInfo) |
||||
|
return s |
||||
} |
} |
||||
func (s *Server) CreateOneVolume(r int, vid storage.VolumeId) storage.VolumeId { |
func (s *Server) CreateOneVolume(r int, vid storage.VolumeId) storage.VolumeId { |
||||
s.AddVolume(&storage.VolumeInfo{Id:vid, Size: 32*1024*1024*1024}) |
|
||||
return vid |
|
||||
|
s.AddVolume(&storage.VolumeInfo{Id: vid, Size: 32 * 1024 * 1024 * 1024}) |
||||
|
return vid |
||||
} |
} |
||||
func (s *Server) AddVolume(v *storage.VolumeInfo){ |
|
||||
s.volumes[v.Id] = v |
|
||||
s.Node.AddVolume(v) |
|
||||
|
func (s *Server) AddVolume(v *storage.VolumeInfo) { |
||||
|
s.volumes[v.Id] = v |
||||
|
s.UpAdjustActiveVolumeCountDelta(1) |
||||
|
s.UpAdjustMaxVolumeId(v.Id) |
||||
} |
} |
@ -1,30 +1,30 @@ |
|||||
package topology |
package topology |
||||
|
|
||||
import ( |
import ( |
||||
"math/rand" |
|
||||
|
"fmt" |
||||
|
"math/rand" |
||||
"pkg/storage" |
"pkg/storage" |
||||
_ "fmt" |
|
||||
) |
) |
||||
|
|
||||
type Topology struct { |
type Topology struct { |
||||
Node |
|
||||
} |
|
||||
func NewTopology(id NodeId) *Topology{ |
|
||||
t := &Topology{} |
|
||||
t.Node = *NewNode() |
|
||||
t.Node.Id = id |
|
||||
return t |
|
||||
|
NodeImpl |
||||
} |
} |
||||
|
|
||||
func (t *Topology) RandomlyReserveOneVolume() (bool, *Node, storage.VolumeId) { |
|
||||
slots := t.Node.maxVolumeCount-t.Node.activeVolumeCount |
|
||||
r := rand.Intn(slots) |
|
||||
vid := t.nextVolumeId() |
|
||||
ret, node := t.Node.ReserveOneVolume(r,vid) |
|
||||
|
func NewTopology(id string) *Topology { |
||||
|
t := &Topology{} |
||||
|
t.id = NodeId(id) |
||||
|
t.nodeType = "Topology" |
||||
|
t.children = make(map[NodeId]Node) |
||||
|
return t |
||||
|
} |
||||
|
func (t *Topology) RandomlyReserveOneVolume() (bool, *Server, storage.VolumeId) { |
||||
|
vid := t.nextVolumeId() |
||||
|
ret, node := t.ReserveOneVolume(rand.Intn(t.FreeSpace()), vid) |
||||
|
fmt.Println("node.IsServer", node.IsServer()) |
||||
return ret, node, vid |
return ret, node, vid |
||||
} |
} |
||||
|
|
||||
func (t *Topology) nextVolumeId() storage.VolumeId { |
func (t *Topology) nextVolumeId() storage.VolumeId { |
||||
vid := t.Node.GetMaxVolumeId() |
|
||||
|
vid := t.GetMaxVolumeId() |
||||
return vid.Next() |
return vid.Next() |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue