aboutsummaryrefslogtreecommitdiff
path: root/weed/topology/topology.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/topology/topology.go')
-rw-r--r--weed/topology/topology.go29
1 files changed, 20 insertions, 9 deletions
diff --git a/weed/topology/topology.go b/weed/topology/topology.go
index bde72cf09..62332f805 100644
--- a/weed/topology/topology.go
+++ b/weed/topology/topology.go
@@ -121,12 +121,12 @@ func (t *Topology) NextVolumeId() (needle.VolumeId, error) {
}
func (t *Topology) HasWritableVolume(option *VolumeGrowOption) bool {
- vl := t.GetVolumeLayout(option.Collection, option.ReplicaPlacement, option.Ttl)
+ vl := t.GetVolumeLayout(option.Collection, option.ReplicaPlacement, option.Ttl, option.VolumeType)
return vl.GetActiveVolumeCount(option) > 0
}
func (t *Topology) PickForWrite(count uint64, option *VolumeGrowOption) (string, uint64, *DataNode, error) {
- vid, count, datanodes, err := t.GetVolumeLayout(option.Collection, option.ReplicaPlacement, option.Ttl).PickForWrite(count, option)
+ vid, count, datanodes, err := t.GetVolumeLayout(option.Collection, option.ReplicaPlacement, option.Ttl, option.VolumeType).PickForWrite(count, option)
if err != nil {
return "", 0, nil, fmt.Errorf("failed to find writable volumes for collection:%s replication:%s ttl:%s error: %v", option.Collection, option.ReplicaPlacement.String(), option.Ttl.String(), err)
}
@@ -137,10 +137,10 @@ func (t *Topology) PickForWrite(count uint64, option *VolumeGrowOption) (string,
return needle.NewFileId(*vid, fileId, rand.Uint32()).String(), count, datanodes.Head(), nil
}
-func (t *Topology) GetVolumeLayout(collectionName string, rp *super_block.ReplicaPlacement, ttl *needle.TTL) *VolumeLayout {
+func (t *Topology) GetVolumeLayout(collectionName string, rp *super_block.ReplicaPlacement, ttl *needle.TTL, volumeType storage.VolumeType) *VolumeLayout {
return t.collectionMap.Get(collectionName, func() interface{} {
return NewCollection(collectionName, t.volumeSizeLimit, t.replicationAsMin)
- }).(*Collection).GetOrCreateVolumeLayout(rp, ttl)
+ }).(*Collection).GetOrCreateVolumeLayout(rp, ttl, volumeType)
}
func (t *Topology) ListCollections(includeNormalVolumes, includeEcVolumes bool) (ret []string) {
@@ -176,17 +176,27 @@ func (t *Topology) DeleteCollection(collectionName string) {
t.collectionMap.Delete(collectionName)
}
+func (t *Topology) DeleteLayout(collectionName string, rp *super_block.ReplicaPlacement, ttl *needle.TTL, volumeType storage.VolumeType) {
+ collection, found := t.FindCollection(collectionName)
+ if !found {
+ return
+ }
+ collection.DeleteVolumeLayout(rp, ttl, volumeType)
+}
+
func (t *Topology) RegisterVolumeLayout(v storage.VolumeInfo, dn *DataNode) {
- vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
+ volumeType, _ := storage.ToVolumeType(v.VolumeType)
+ vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, volumeType)
vl.RegisterVolume(&v, dn)
vl.EnsureCorrectWritables(&v)
}
func (t *Topology) UnRegisterVolumeLayout(v storage.VolumeInfo, dn *DataNode) {
- glog.Infof("removing volume info:%+v", v)
- volumeLayout := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
+ glog.Infof("removing volume info: %+v", v)
+ volumeType, _ := storage.ToVolumeType(v.VolumeType)
+ volumeLayout := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, volumeType)
volumeLayout.UnRegisterVolume(&v, dn)
if volumeLayout.isEmpty() {
- t.DeleteCollection(v.Collection)
+ t.DeleteLayout(v.Collection, v.ReplicaPlacement, v.Ttl, volumeType)
}
}
@@ -222,7 +232,8 @@ func (t *Topology) SyncDataNodeRegistration(volumes []*master_pb.VolumeInformati
t.UnRegisterVolumeLayout(v, dn)
}
for _, v := range changedVolumes {
- vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
+ volumeType, _ := storage.ToVolumeType(v.VolumeType)
+ vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl, volumeType)
vl.EnsureCorrectWritables(&v)
}
return