aboutsummaryrefslogtreecommitdiff
path: root/weed/storage/disk_location_ec.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2019-05-27 21:40:51 -0700
committerChris Lu <chris.lu@gmail.com>2019-05-27 21:40:51 -0700
commit217cde0a3bdb676e4a68959ca2aec0e7c82e2f7d (patch)
tree6e7818e20e9642eac208177cc06ee8375079e544 /weed/storage/disk_location_ec.go
parent03b9291e5da8a25a9c8a968de752e331da60ef7c (diff)
downloadseaweedfs-217cde0a3bdb676e4a68959ca2aec0e7c82e2f7d.tar.xz
seaweedfs-217cde0a3bdb676e4a68959ca2aec0e7c82e2f7d.zip
refactoring
Diffstat (limited to 'weed/storage/disk_location_ec.go')
-rw-r--r--weed/storage/disk_location_ec.go47
1 files changed, 18 insertions, 29 deletions
diff --git a/weed/storage/disk_location_ec.go b/weed/storage/disk_location_ec.go
index e91c0f262..2aec1502b 100644
--- a/weed/storage/disk_location_ec.go
+++ b/weed/storage/disk_location_ec.go
@@ -16,26 +16,26 @@ var (
re = regexp.MustCompile("\\.ec[0-9][0-9]")
)
-func (l *DiskLocation) HasEcShard(vid needle.VolumeId) (erasure_coding.EcVolumeShards, bool) {
- l.ecShardsLock.RLock()
- defer l.ecShardsLock.RUnlock()
+func (l *DiskLocation) FindEcVolume(vid needle.VolumeId) (*erasure_coding.EcVolume, bool) {
+ l.ecVolumesLock.RLock()
+ defer l.ecVolumesLock.RUnlock()
- ecShards, ok := l.ecShards[vid]
+ ecVolume, ok := l.ecVolumes[vid]
if ok {
- return ecShards, true
+ return ecVolume, true
}
return nil, false
}
func (l *DiskLocation) FindEcShard(vid needle.VolumeId, shardId erasure_coding.ShardId) (*erasure_coding.EcVolumeShard, bool) {
- l.ecShardsLock.RLock()
- defer l.ecShardsLock.RUnlock()
+ l.ecVolumesLock.RLock()
+ defer l.ecVolumesLock.RUnlock()
- ecShards, ok := l.ecShards[vid]
+ ecVolume, ok := l.ecVolumes[vid]
if !ok {
return nil, false
}
- for _, ecShard := range ecShards {
+ for _, ecShard := range ecVolume.Shards {
if ecShard.ShardId == shardId {
return ecShard, true
}
@@ -49,40 +49,29 @@ func (l *DiskLocation) LoadEcShard(collection string, vid needle.VolumeId, shard
if err != nil {
return fmt.Errorf("failed to create ec shard %d.%d: %v", vid, shardId, err)
}
- l.ecShardsLock.Lock()
- l.ecShards[vid] = append(l.ecShards[vid], ecVolumeShard)
- l.ecShardsLock.Unlock()
+ l.ecVolumesLock.Lock()
+ l.ecVolumes[vid].AddEcVolumeShard(ecVolumeShard)
+ l.ecVolumesLock.Unlock()
return nil
}
func (l *DiskLocation) UnloadEcShard(vid needle.VolumeId, shardId erasure_coding.ShardId) bool {
- l.ecShardsLock.Lock()
- defer l.ecShardsLock.Unlock()
+ l.ecVolumesLock.Lock()
+ defer l.ecVolumesLock.Unlock()
- vidShards, found := l.ecShards[vid]
+ ecVolume, found := l.ecVolumes[vid]
if !found {
return false
}
- shardIndex := -1
- for i, shard := range vidShards {
- if shard.ShardId == shardId {
- shardIndex = i
- break
+ if deleted := ecVolume.DeleteEcVolumeShard(shardId); deleted {
+ if len(ecVolume.Shards) == 0 {
+ delete(l.ecVolumes, vid)
}
- }
- if shardIndex < 0 {
- return false
- }
-
- if len(vidShards) == 1 {
- delete(l.ecShards, vid)
return true
}
- l.ecShards[vid] = append(vidShards[:shardIndex], vidShards[shardIndex+1:]...)
-
return true
}