aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2017-01-20 10:18:43 -0800
committerChris Lu <chris.lu@gmail.com>2017-01-20 10:18:43 -0800
commit043b7a7c65dfa0c80c667d3d1e67c7489060dbcf (patch)
treeaf023492207b474dfb2916a0b8c5db7be2f9c767
parentbfd2739fcee72d46f87de2d15455fc285dd9ecd7 (diff)
downloadseaweedfs-043b7a7c65dfa0c80c667d3d1e67c7489060dbcf.tar.xz
seaweedfs-043b7a7c65dfa0c80c667d3d1e67c7489060dbcf.zip
add locking to access l.volumes
-rw-r--r--weed/storage/disk_location.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go
index 9b9468c5b..99c4f3c34 100644
--- a/weed/storage/disk_location.go
+++ b/weed/storage/disk_location.go
@@ -6,8 +6,9 @@ import (
"strings"
"sync"
- "github.com/chrislusf/seaweedfs/weed/glog"
"fmt"
+
+ "github.com/chrislusf/seaweedfs/weed/glog"
)
type DiskLocation struct {
@@ -27,12 +28,12 @@ func (l *DiskLocation) volumeIdFromPath(dir os.FileInfo) (VolumeId, string, erro
name := dir.Name()
if !dir.IsDir() && strings.HasSuffix(name, ".dat") {
collection := ""
- base := name[:len(name) - len(".dat")]
+ base := name[:len(name)-len(".dat")]
i := strings.LastIndex(base, "_")
if i > 0 {
- collection, base = base[0:i], base[i + 1:]
+ collection, base = base[0:i], base[i+1:]
}
- vol, err := NewVolumeId(base);
+ vol, err := NewVolumeId(base)
return vol, collection, err
}
@@ -148,7 +149,10 @@ func (l *DiskLocation) LoadVolume(vid VolumeId, needleMapKind NeedleMapType) boo
return false
}
-func (l *DiskLocation) DeleteVolume(vid VolumeId) (error) {
+func (l *DiskLocation) DeleteVolume(vid VolumeId) error {
+ l.Lock()
+ defer l.Unlock()
+
_, ok := l.volumes[vid]
if !ok {
return fmt.Errorf("Volume not found, VolumeId: %d", vid)
@@ -156,7 +160,10 @@ func (l *DiskLocation) DeleteVolume(vid VolumeId) (error) {
return l.deleteVolumeById(vid)
}
-func (l *DiskLocation) UnloadVolume(vid VolumeId) (error) {
+func (l *DiskLocation) UnloadVolume(vid VolumeId) error {
+ l.Lock()
+ defer l.Unlock()
+
_, ok := l.volumes[vid]
if !ok {
return fmt.Errorf("Volume not loaded, VolumeId: %d", vid)