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
add http endpoint to get the size of a collection (#5910)
Riccardo Bertossa6fe86395046c
diff --git a/weed/server/master_server.go b/weed/server/master_server.goindex 44a1664c06..ee28f3386f 100644--- a/weed/server/master_server.go+++ b/weed/server/master_server.go@@ -146,6 +146,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.Ser.HandleFunc("/vol/status", ms.proxyToLeader(ms.guard.WhiteList(ms.volumeStatusHandler)))r.HandleFunc("/vol/vacuum", ms.proxyToLeader(ms.guard.WhiteList(ms.volumeVacuumHandler)))r.HandleFunc("/submit", ms.guard.WhiteList(ms.submitFromMasterServerHandler))+ r.HandleFunc("/collection/info", ms.guard.WhiteList(ms.collectionInfoHandler))/*r.HandleFunc("/stats/health", ms.guard.WhiteList(statsHealthHandler))r.HandleFunc("/stats/counter", ms.guard.WhiteList(statsCounterHandler))diff --git a/weed/server/master_server_handlers_admin.go b/weed/server/master_server_handlers_admin.goindex 7479b5535b..e003d7d9f6 100644--- a/weed/server/master_server_handlers_admin.go+++ b/weed/server/master_server_handlers_admin.go@@ -178,3 +178,58 @@ func (ms *MasterServer) getVolumeGrowOption(r *http.Request) (*topology.VolumeGr}return volumeGrowOption, nil}++func (ms *MasterServer) collectionInfoHandler(w http.ResponseWriter, r *http.Request) {+ //get collection from request+ collectionName := r.FormValue("collection")+ if collectionName == "" {+ writeJsonError(w, r, http.StatusBadRequest, fmt.Errorf("collection is required"))+ return+ }+ //output details of the volumes?+ detail := r.FormValue("detail") == "true"+ //collect collection info+ collection, ok := ms.Topo.FindCollection(collectionName)+ if !ok {+ writeJsonError(w, r, http.StatusBadRequest, fmt.Errorf("collection %s does not exist", collectionName))+ return+ }++ volumeLayouts := collection.GetAllVolumeLayouts()++ if detail {+ //prepare the json response+ all_stats := make([]map[string]interface{}, len(volumeLayouts))+ for i, volumeLayout := range volumeLayouts {+ volumeLayoutStats := volumeLayout.Stats()+ m := make(map[string]interface{})+ m["Version"] = util.Version()+ m["Collection"] = collectionName+ m["TotalSize"] = volumeLayoutStats.TotalSize+ m["FileCount"] = volumeLayoutStats.FileCount+ m["UsedSize"] = volumeLayoutStats.UsedSize+ all_stats[i] = m+ }+ //write it+ writeJsonQuiet(w, r, http.StatusOK, all_stats)+ } else {+ //prepare the json response+ collectionStats := map[string]interface{}{+ "Version": util.Version(),+ "Collection": collectionName,+ "TotalSize": uint64(0),+ "FileCount": uint64(0),+ "UsedSize": uint64(0),+ "VolumeCount": uint64(0),+ }+ for _, volumeLayout := range volumeLayouts {+ volumeLayoutStats := volumeLayout.Stats()+ collectionStats["TotalSize"] = collectionStats["TotalSize"].(uint64) + volumeLayoutStats.TotalSize+ collectionStats["FileCount"] = collectionStats["FileCount"].(uint64) + volumeLayoutStats.FileCount+ collectionStats["UsedSize"] = collectionStats["UsedSize"].(uint64) + volumeLayoutStats.UsedSize+ collectionStats["VolumeCount"] = collectionStats["VolumeCount"].(uint64) + 1+ }+ //write it+ writeJsonQuiet(w, r, http.StatusOK, collectionStats)+ }+}diff --git a/weed/topology/collection.go b/weed/topology/collection.goindex cea3d3b211..e197ce1a2b 100644--- a/weed/topology/collection.go+++ b/weed/topology/collection.go@@ -44,6 +44,28 @@ func (c *Collection) GetOrCreateVolumeLayout(rp *super_block.ReplicaPlacement, treturn vl.(*VolumeLayout)}+func (c *Collection) GetVolumeLayout(rp *super_block.ReplicaPlacement, ttl *needle.TTL, diskType types.DiskType) (*VolumeLayout, bool) {+ keyString := rp.String()+ if ttl != nil {+ keyString += ttl.String()+ }+ if diskType != types.HardDriveType {+ keyString += string(diskType)+ }+ vl, ok := c.storageType2VolumeLayout.Find(keyString)+ return vl.(*VolumeLayout), ok+}++func (c *Collection) GetAllVolumeLayouts() []*VolumeLayout {+ var vls []*VolumeLayout+ for _, vl := range c.storageType2VolumeLayout.Items() {+ if vl != nil {+ vls = append(vls, vl.(*VolumeLayout))+ }+ }+ return vls+}+func (c *Collection) DeleteVolumeLayout(rp *super_block.ReplicaPlacement, ttl *needle.TTL, diskType types.DiskType) {keyString := rp.String()if ttl != nil {