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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
adjusting refresh topology writable volumes(not finished yet)
Chris Lub0e250d43753
diff --git a/weed-fs/src/cmd/weed/master.go b/weed-fs/src/cmd/weed/master.goindex a61c65f397..d2e58eb5b6 100644--- a/weed-fs/src/cmd/weed/master.go+++ b/weed-fs/src/cmd/weed/master.go@@ -2,6 +2,7 @@ package mainimport ("encoding/json"+ "errors""log""net/http""pkg/directory"@@ -70,9 +71,9 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) {func dirAssign2Handler(w http.ResponseWriter, r *http.Request) {c, _ := strconv.Atoi(r.FormValue("count"))rt, err := storage.NewReplicationType(r.FormValue("replication"))- if err!=nil {- writeJson(w, r, map[string]string{"error": err.Error()})- return+ if err != nil {+ writeJson(w, r, map[string]string{"error": err.Error()})+ return}if topo.GetVolumeLayout(rt).GetActiveVolumeCount() <= 0 {if topo.FreeSpace() <= 0 {@@ -111,22 +112,21 @@ func dirNewStatusHandler(w http.ResponseWriter, r *http.Request) {writeJson(w, r, topo.ToMap())}func volumeGrowHandler(w http.ResponseWriter, r *http.Request) {- rt, err := storage.NewReplicationType(r.FormValue("replication"))- if err!=nil {- writeJson(w, r, map[string]string{"error": err.Error()})- return- }- count, err := strconv.Atoi(r.FormValue("count"))- if topo.FreeSpace() < count * rt.GetCopyCount() {- writeJson(w, r, map[string]string{"error": "Only "+strconv.Itoa(topo.FreeSpace())+" volumes left! Not enough for "+strconv.Itoa(count*rt.GetCopyCount())})- return+ count := 0+ rt, err := storage.NewReplicationType(r.FormValue("replication"))+ if err == nil {+ if count, err = strconv.Atoi(r.FormValue("count")); err == nil {+ if topo.FreeSpace() < count*rt.GetCopyCount() {+ err = errors.New("Only " + strconv.Itoa(topo.FreeSpace()) + " volumes left! Not enough for " + strconv.Itoa(count*rt.GetCopyCount()))+ } else {+ count, err = vg.GrowByCountAndType(count, rt, topo)+ }+ }}if err != nil {- count, err := vg.GrowByType(rt, topo)- writeJson(w, r, map[string]interface{}{"count": count, "error": err})+ writeJson(w, r, map[string]string{"error": err.Error()})} else {- count, err := vg.GrowByCountAndType(count, rt, topo)- writeJson(w, r, map[string]interface{}{"count": count, "error": err})+ writeJson(w, r, map[string]interface{}{"count": count})}}@@ -144,6 +144,7 @@ func runMaster(cmd *Command, args []string) bool {http.HandleFunc("/vol/grow", volumeGrowHandler)mapper.StartRefreshWritableVolumes()+ topo.StartRefreshWritableVolumes()log.Println("Start directory service at http://127.0.0.1:" + strconv.Itoa(*mport))e := http.ListenAndServe(":"+strconv.Itoa(*mport), nil)diff --git a/weed-fs/src/pkg/directory/volume_mapping.go b/weed-fs/src/pkg/directory/volume_mapping.goindex 495c579301..da41b35107 100644--- a/weed-fs/src/pkg/directory/volume_mapping.go+++ b/weed-fs/src/pkg/directory/volume_mapping.go@@ -120,7 +120,7 @@ func (m *Mapper) StartRefreshWritableVolumes() {}func (m *Mapper) refreshWritableVolumes() {- freshThreshHold := time.Now().Unix() - 5*m.pulse //5 times of sleep interval+ freshThreshHold := time.Now().Unix() - 3*m.pulse //3 times of sleep interval//setting Writers, copy-on-write because of possible updating, this needs some future work!var writers []storage.VolumeIdfor _, machine_entry := range m.Machines {diff --git a/weed-fs/src/pkg/replication/volume_growth.go b/weed-fs/src/pkg/replication/volume_growth.goindex 8519921f5e..28dca68b40 100644--- a/weed-fs/src/pkg/replication/volume_growth.go+++ b/weed-fs/src/pkg/replication/volume_growth.go@@ -44,7 +44,7 @@ func (vg *VolumeGrowth) GrowByType(repType storage.ReplicationType, topo *topolocase storage.Copy11:return vg.GrowByCountAndType(vg.copy3factor, repType, topo)}- return 0, nil+ return 0, errors.New("Unknown Replication Type!")}func (vg *VolumeGrowth) GrowByCountAndType(count int, repType storage.ReplicationType, topo *topology.Topology) (counter int, err error) {counter = 0diff --git a/weed-fs/src/pkg/topology/data_node.go b/weed-fs/src/pkg/topology/data_node.goindex 1516572fd7..04c7cf1117 100644--- a/weed-fs/src/pkg/topology/data_node.go+++ b/weed-fs/src/pkg/topology/data_node.go@@ -11,7 +11,7 @@ type DataNode struct {Ip stringPort intPublicUrl string- lastSeen int64 // unix time in seconds+ LastSeen int64 // unix time in seconds}func NewDataNode(id string) *DataNode {diff --git a/weed-fs/src/pkg/topology/node.go b/weed-fs/src/pkg/topology/node.goindex e73719794d..ddaf9f0b24 100644--- a/weed-fs/src/pkg/topology/node.go+++ b/weed-fs/src/pkg/topology/node.go@@ -151,7 +151,7 @@ func (n *NodeImpl) CollectWritableVolumes(freshThreshHold int64, volumeSizeLimitif n.IsRack() {for _, c := range n.Children() {dn := c.(*DataNode) //can not cast n to DataNode- if dn.lastSeen > freshThreshHold {+ if dn.LastSeen > freshThreshHold {continue}for _, v := range dn.volumes {diff --git a/weed-fs/src/pkg/topology/rack.go b/weed-fs/src/pkg/topology/rack.goindex f685f1a822..c819feb00b 100644--- a/weed-fs/src/pkg/topology/rack.go+++ b/weed-fs/src/pkg/topology/rack.go@@ -2,6 +2,7 @@ package topologyimport ("strconv"+ "time")type Rack struct {@@ -28,7 +29,8 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVolfor _, c := range r.Children() {dn := c.(*DataNode)if dn.MatchLocation(ip, port) {- dn.NodeImpl.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount)+ dn.LastSeen = time.Now().Unix()+ dn.UpAdjustMaxVolumeCountDelta(maxVolumeCount - dn.maxVolumeCount)return dn}}@@ -37,6 +39,7 @@ func (r *Rack) GetOrCreateDataNode(ip string, port int, publicUrl string, maxVoldn.Port = portdn.PublicUrl = publicUrldn.maxVolumeCount = maxVolumeCount+ dn.LastSeen = time.Now().Unix()r.LinkChildNode(dn)return dn}diff --git a/weed-fs/src/pkg/topology/topology.go b/weed-fs/src/pkg/topology/topology.goindex 079fb54d9b..a60768f143 100644--- a/weed-fs/src/pkg/topology/topology.go+++ b/weed-fs/src/pkg/topology/topology.go@@ -6,6 +6,7 @@ import ("pkg/directory""pkg/sequence""pkg/storage"+ "time")type Topology struct {@@ -125,3 +126,19 @@ func (t *Topology) ToMap() interface{} {m["layouts"] = layoutsreturn m}++func (t *Topology) StartRefreshWritableVolumes() {+ go func() {+ for {+ t.refreshWritableVolumes()+ time.Sleep(time.Duration(float32(t.pulse*1e3)*(1+rand.Float32())) * time.Millisecond)+ }+ }()+}++func (t *Topology) refreshWritableVolumes() {+ freshThreshHold := time.Now().Unix() - 3*t.pulse //5 times of sleep interval+ //setting Writers, copy-on-write because of possible updating, this needs some future work!+ t.CollectWritableVolumes(freshThreshHold, t.volumeSizeLimit)+ //TODO: collect writable columes for each replication type+}diff --git a/weed-fs/src/pkg/topology/volume_location.go b/weed-fs/src/pkg/topology/volume_location.goindex 92d89ae460..f2e5dd894b 100644--- a/weed-fs/src/pkg/topology/volume_location.go+++ b/weed-fs/src/pkg/topology/volume_location.go@@ -27,7 +27,7 @@ func (dnll *DataNodeLocationList) Add(loc *DataNode) bool {func (dnll *DataNodeLocationList) Refresh(freshThreshHold int64) {var changed boolfor _, dnl := range dnll.list {- if dnl.lastSeen < freshThreshHold {+ if dnl.LastSeen < freshThreshHold {changed = truebreak}@@ -35,7 +35,7 @@ func (dnll *DataNodeLocationList) Refresh(freshThreshHold int64) {if changed {var l []*DataNodefor _, dnl := range dnll.list {- if dnl.lastSeen >= freshThreshHold {+ if dnl.LastSeen >= freshThreshHold {l = append(l, dnl)}}