aboutsummaryrefslogtreecommitdiff
path: root/go/topology
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2016-05-30 12:30:26 -0700
committerChris Lu <chris.lu@gmail.com>2016-05-30 12:30:26 -0700
commit6df18a918103634fd4e5e3297e9d2b1597ec5b73 (patch)
tree7d0e918cd4a04348eb2edf67f7951835ca20011d /go/topology
parent46a89a7d61a269dbf8cfb1d113d328f138ac5361 (diff)
downloadseaweedfs-6df18a918103634fd4e5e3297e9d2b1597ec5b73.tar.xz
seaweedfs-6df18a918103634fd4e5e3297e9d2b1597ec5b73.zip
rwlock concurrent read map
Diffstat (limited to 'go/topology')
-rw-r--r--go/topology/collection.go4
-rw-r--r--go/topology/data_node.go2
-rw-r--r--go/topology/topology.go10
-rw-r--r--go/topology/topology_map.go4
-rw-r--r--go/topology/topology_vacuum.go4
5 files changed, 11 insertions, 13 deletions
diff --git a/go/topology/collection.go b/go/topology/collection.go
index 376b62405..6368900c3 100644
--- a/go/topology/collection.go
+++ b/go/topology/collection.go
@@ -35,7 +35,7 @@ func (c *Collection) GetOrCreateVolumeLayout(rp *storage.ReplicaPlacement, ttl *
}
func (c *Collection) Lookup(vid storage.VolumeId) []*DataNode {
- for _, vl := range c.storageType2VolumeLayout.Items {
+ for _, vl := range c.storageType2VolumeLayout.Items() {
if vl != nil {
if list := vl.(*VolumeLayout).Lookup(vid); list != nil {
return list
@@ -46,7 +46,7 @@ func (c *Collection) Lookup(vid storage.VolumeId) []*DataNode {
}
func (c *Collection) ListVolumeServers() (nodes []*DataNode) {
- for _, vl := range c.storageType2VolumeLayout.Items {
+ for _, vl := range c.storageType2VolumeLayout.Items() {
if vl != nil {
if list := vl.(*VolumeLayout).ListVolumeServers(); list != nil {
nodes = append(nodes, list...)
diff --git a/go/topology/data_node.go b/go/topology/data_node.go
index 01419a791..3bad8c188 100644
--- a/go/topology/data_node.go
+++ b/go/topology/data_node.go
@@ -3,7 +3,6 @@ package topology
import (
"fmt"
"strconv"
- "sync"
"github.com/chrislusf/seaweedfs/go/glog"
"github.com/chrislusf/seaweedfs/go/storage"
@@ -11,7 +10,6 @@ import (
type DataNode struct {
NodeImpl
- sync.RWMutex
volumes map[storage.VolumeId]storage.VolumeInfo
Ip string
Port int
diff --git a/go/topology/topology.go b/go/topology/topology.go
index ee1477cd2..088639eef 100644
--- a/go/topology/topology.go
+++ b/go/topology/topology.go
@@ -90,13 +90,13 @@ func (t *Topology) loadConfiguration(configurationFile string) error {
func (t *Topology) Lookup(collection string, vid storage.VolumeId) []*DataNode {
//maybe an issue if lots of collections?
if collection == "" {
- for _, c := range t.collectionMap.Items {
+ for _, c := range t.collectionMap.Items() {
if list := c.(*Collection).Lookup(vid); list != nil {
return list
}
}
} else {
- if c, ok := t.collectionMap.Items[collection]; ok {
+ if c, ok := t.collectionMap.Find(collection); ok {
return c.(*Collection).Lookup(vid)
}
}
@@ -130,13 +130,13 @@ func (t *Topology) GetVolumeLayout(collectionName string, rp *storage.ReplicaPla
}).(*Collection).GetOrCreateVolumeLayout(rp, ttl)
}
-func (t *Topology) GetCollection(collectionName string) (*Collection, bool) {
- c, hasCollection := t.collectionMap.Items[collectionName]
+func (t *Topology) FindCollection(collectionName string) (*Collection, bool) {
+ c, hasCollection := t.collectionMap.Find(collectionName)
return c.(*Collection), hasCollection
}
func (t *Topology) DeleteCollection(collectionName string) {
- delete(t.collectionMap.Items, collectionName)
+ t.collectionMap.Delete(collectionName)
}
func (t *Topology) RegisterVolumeLayout(v storage.VolumeInfo, dn *DataNode) {
diff --git a/go/topology/topology_map.go b/go/topology/topology_map.go
index dff11aaad..ce8e9e663 100644
--- a/go/topology/topology_map.go
+++ b/go/topology/topology_map.go
@@ -11,9 +11,9 @@ func (t *Topology) ToMap() interface{} {
}
m["DataCenters"] = dcs
var layouts []interface{}
- for _, col := range t.collectionMap.Items {
+ for _, col := range t.collectionMap.Items() {
c := col.(*Collection)
- for _, layout := range c.storageType2VolumeLayout.Items {
+ for _, layout := range c.storageType2VolumeLayout.Items() {
if layout != nil {
tmp := layout.(*VolumeLayout).ToMap()
tmp["collection"] = c.Name
diff --git a/go/topology/topology_vacuum.go b/go/topology/topology_vacuum.go
index 48bc8311d..eeb4fef69 100644
--- a/go/topology/topology_vacuum.go
+++ b/go/topology/topology_vacuum.go
@@ -81,10 +81,10 @@ func batchVacuumVolumeCommit(vl *VolumeLayout, vid storage.VolumeId, locationlis
}
func (t *Topology) Vacuum(garbageThreshold string) int {
glog.V(0).Infoln("Start vacuum on demand")
- for _, col := range t.collectionMap.Items {
+ for _, col := range t.collectionMap.Items() {
c := col.(*Collection)
glog.V(0).Infoln("vacuum on collection:", c.Name)
- for _, vl := range c.storageType2VolumeLayout.Items {
+ for _, vl := range c.storageType2VolumeLayout.Items() {
if vl != nil {
volumeLayout := vl.(*VolumeLayout)
for vid, locationlist := range volumeLayout.vid2location {