|
@ -6,6 +6,7 @@ import ( |
|
|
"pkg/directory" |
|
|
"pkg/directory" |
|
|
"pkg/sequence" |
|
|
"pkg/sequence" |
|
|
"pkg/storage" |
|
|
"pkg/storage" |
|
|
|
|
|
"io/ioutil" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type Topology struct { |
|
|
type Topology struct { |
|
@ -23,9 +24,11 @@ type Topology struct { |
|
|
chanDeadDataNodes chan *DataNode |
|
|
chanDeadDataNodes chan *DataNode |
|
|
chanRecoveredDataNodes chan *DataNode |
|
|
chanRecoveredDataNodes chan *DataNode |
|
|
chanFullVolumes chan *storage.VolumeInfo |
|
|
chanFullVolumes chan *storage.VolumeInfo |
|
|
|
|
|
|
|
|
|
|
|
configuration *Configuration |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewTopology(id string, dirname string, filename string, volumeSizeLimit uint64, pulse int) *Topology { |
|
|
|
|
|
|
|
|
func NewTopology(id string, confFile string, dirname string, filename string, volumeSizeLimit uint64, pulse int) *Topology { |
|
|
t := &Topology{} |
|
|
t := &Topology{} |
|
|
t.id = NodeId(id) |
|
|
t.id = NodeId(id) |
|
|
t.nodeType = "Topology" |
|
|
t.nodeType = "Topology" |
|
@ -41,9 +44,19 @@ func NewTopology(id string, dirname string, filename string, volumeSizeLimit uin |
|
|
t.chanRecoveredDataNodes = make(chan *DataNode) |
|
|
t.chanRecoveredDataNodes = make(chan *DataNode) |
|
|
t.chanFullVolumes = make(chan *storage.VolumeInfo) |
|
|
t.chanFullVolumes = make(chan *storage.VolumeInfo) |
|
|
|
|
|
|
|
|
|
|
|
t.loadConfiguration(confFile) |
|
|
|
|
|
|
|
|
return t |
|
|
return t |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *Topology) loadConfiguration(configurationFile string)error{ |
|
|
|
|
|
b, e := ioutil.ReadFile(configurationFile); |
|
|
|
|
|
if e ==nil{ |
|
|
|
|
|
t.configuration, e = NewConfiguration(b) |
|
|
|
|
|
} |
|
|
|
|
|
return e |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (t *Topology) RandomlyReserveOneVolume() (bool, *DataNode, *storage.VolumeId) { |
|
|
func (t *Topology) RandomlyReserveOneVolume() (bool, *DataNode, *storage.VolumeId) { |
|
|
if t.FreeSpace() <= 0 { |
|
|
if t.FreeSpace() <= 0 { |
|
|
return false, nil, nil |
|
|
return false, nil, nil |
|
@ -97,8 +110,9 @@ func (t *Topology) RegisterVolumeLayout(v *storage.VolumeInfo, dn *DataNode) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *Topology) RegisterVolumes(volumeInfos []storage.VolumeInfo, ip string, port int, publicUrl string, maxVolumeCount int) { |
|
|
func (t *Topology) RegisterVolumes(volumeInfos []storage.VolumeInfo, ip string, port int, publicUrl string, maxVolumeCount int) { |
|
|
dc := t.GetOrCreateDataCenter(ip) |
|
|
|
|
|
rack := dc.GetOrCreateRack(ip) |
|
|
|
|
|
|
|
|
dcName, rackName := t.configuration.Locate(ip) |
|
|
|
|
|
dc := t.GetOrCreateDataCenter(dcName) |
|
|
|
|
|
rack := dc.GetOrCreateRack(rackName) |
|
|
dn := rack.GetOrCreateDataNode(ip, port, publicUrl, maxVolumeCount) |
|
|
dn := rack.GetOrCreateDataNode(ip, port, publicUrl, maxVolumeCount) |
|
|
for _, v := range volumeInfos { |
|
|
for _, v := range volumeInfos { |
|
|
dn.AddOrUpdateVolume(v) |
|
|
dn.AddOrUpdateVolume(v) |
|
@ -106,14 +120,14 @@ func (t *Topology) RegisterVolumes(volumeInfos []storage.VolumeInfo, ip string, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (t *Topology) GetOrCreateDataCenter(ip string) *DataCenter { |
|
|
|
|
|
|
|
|
func (t *Topology) GetOrCreateDataCenter(dcName string) *DataCenter { |
|
|
for _, c := range t.Children() { |
|
|
for _, c := range t.Children() { |
|
|
dc := c.(*DataCenter) |
|
|
dc := c.(*DataCenter) |
|
|
if dc.MatchLocationRange(ip) { |
|
|
|
|
|
|
|
|
if string(dc.Id()) == dcName { |
|
|
return dc |
|
|
return dc |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
dc := NewDataCenter("DefaultDataCenter") |
|
|
|
|
|
|
|
|
dc := NewDataCenter(dcName) |
|
|
t.LinkChildNode(dc) |
|
|
t.LinkChildNode(dc) |
|
|
return dc |
|
|
return dc |
|
|
} |
|
|
} |
|
|