Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

adding locking to avoid nil VolumeLocationList

Chris Lu720b1d9b8813
diff --git a/weed/topology/topology.go b/weed/topology/topology.go
index a11a1bac69..e217617e97 100644
--- a/weed/topology/topology.go
+++ b/weed/topology/topology.go
@@ -221,7 +221,7 @@ func (t *Topology) SyncDataNodeRegistration(volumes []*master_pb.VolumeInformati
}
for _, v := range changedVolumes {
vl := t.GetVolumeLayout(v.Collection, v.ReplicaPlacement, v.Ttl)
- vl.ensureCorrectWritables(&v)
+ vl.EnsureCorrectWritables(&v)
}
return
}
diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go
index e7659e0eb3..dddcfc9c9d 100644
--- a/weed/topology/volume_layout.go
+++ b/weed/topology/volume_layout.go
@@ -198,6 +198,13 @@ func (vl *VolumeLayout) UnRegisterVolume(v *storage.VolumeInfo, dn *DataNode) {
}
}
+func (vl *VolumeLayout) EnsureCorrectWritables(v *storage.VolumeInfo) {
+ vl.accessLock.Lock()
+ defer vl.accessLock.Unlock()
+
+ vl.ensureCorrectWritables(v)
+}
+
func (vl *VolumeLayout) ensureCorrectWritables(v *storage.VolumeInfo) {
if vl.enoughCopies(v.Id) && vl.isWritable(v) {
if !vl.oversizedVolumes.IsTrue(v.Id) {
diff --git a/weed/topology/volume_location_list.go b/weed/topology/volume_location_list.go
index 6acd70f2f5..64c13ca527 100644
--- a/weed/topology/volume_location_list.go
+++ b/weed/topology/volume_location_list.go
@@ -32,6 +32,9 @@ func (dnll *VolumeLocationList) Head() *DataNode {
}
func (dnll *VolumeLocationList) Length() int {
+ if dnll == nil {
+ return 0
+ }
return len(dnll.list)
}