aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-03-24 18:41:25 -0700
committerChris Lu <chris.lu@gmail.com>2020-03-24 18:41:25 -0700
commite63a79ade842df4bcd0ec0096229028236215ae1 (patch)
tree723f4added2eea495a2aaaf3c244337e18f7e3e1
parent4d5554b16f9d86d06995c5440540a605c3296b26 (diff)
downloadseaweedfs-e63a79ade842df4bcd0ec0096229028236215ae1.tar.xz
seaweedfs-e63a79ade842df4bcd0ec0096229028236215ae1.zip
better handle lock in case of exception
-rw-r--r--weed/storage/store.go65
1 files changed, 43 insertions, 22 deletions
diff --git a/weed/storage/store.go b/weed/storage/store.go
index 4ef3682d8..84374b174 100644
--- a/weed/storage/store.go
+++ b/weed/storage/store.go
@@ -135,33 +135,54 @@ func (s *Store) addVolume(vid needle.VolumeId, collection string, needleMapKind
return fmt.Errorf("No more free space left")
}
-func (s *Store) VolumeInfos() []*VolumeInfo {
- var stats []*VolumeInfo
+func (s *Store) VolumeInfos() (allStats []*VolumeInfo) {
for _, location := range s.Locations {
- location.volumesLock.RLock()
- for k, v := range location.volumes {
- s := &VolumeInfo{
- Id: needle.VolumeId(k),
- Size: v.ContentSize(),
- Collection: v.Collection,
- ReplicaPlacement: v.ReplicaPlacement,
- Version: v.Version(),
- FileCount: int(v.FileCount()),
- DeleteCount: int(v.DeletedCount()),
- DeletedByteCount: v.DeletedSize(),
- ReadOnly: v.IsReadOnly(),
- Ttl: v.Ttl,
- CompactRevision: uint32(v.CompactionRevision),
- }
- s.RemoteStorageName, s.RemoteStorageKey = v.RemoteStorageNameKey()
- stats = append(stats, s)
- }
- location.volumesLock.RUnlock()
+ stats := collectStatsForOneLocation(location)
+ allStats = append(allStats, stats...)
+ }
+ sortVolumeInfos(allStats)
+ return allStats
+}
+
+func collectStatsForOneLocation(location *DiskLocation) (stats []*VolumeInfo) {
+ location.volumesLock.RLock()
+ defer location.volumesLock.RUnlock()
+
+ for k, v := range location.volumes {
+ s := collectStatForOneVolume(k, v)
+ stats = append(stats, s)
}
- sortVolumeInfos(stats)
return stats
}
+func collectStatForOneVolume(vid needle.VolumeId, v *Volume) (s *VolumeInfo) {
+
+ s = &VolumeInfo{
+ Id: vid,
+ Collection: v.Collection,
+ ReplicaPlacement: v.ReplicaPlacement,
+ Version: v.Version(),
+ ReadOnly: v.IsReadOnly(),
+ Ttl: v.Ttl,
+ CompactRevision: uint32(v.CompactionRevision),
+ }
+ s.RemoteStorageName, s.RemoteStorageKey = v.RemoteStorageNameKey()
+
+ v.dataFileAccessLock.RLock()
+ defer v.dataFileAccessLock.RUnlock()
+
+ if v.nm == nil {
+ return
+ }
+
+ s.FileCount = v.nm.FileCount()
+ s.DeleteCount = v.nm.DeletedCount()
+ s.DeletedByteCount = v.nm.DeletedSize()
+ s.Size = v.nm.ContentSize()
+
+ return
+}
+
func (s *Store) SetDataCenter(dataCenter string) {
s.dataCenter = dataCenter
}