added re-generating and writing the Volume UUID if it is empty (#6568)

This commit is contained in:
Aleksey Kosov 2025-02-24 18:58:43 +03:00 committed by GitHub
parent be74548cb5
commit ef4eda0761
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View File

@ -1,7 +1,6 @@
package stats package stats
import ( import (
"log"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -436,7 +435,7 @@ func StartMetricsServer(ip string, port int) {
return return
} }
http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{})) http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{}))
log.Fatal(http.ListenAndServe(JoinHostPort(ip, port), nil)) glog.Fatal(http.ListenAndServe(JoinHostPort(ip, port), nil))
} }
func SourceName(port uint32) string { func SourceName(port uint32) string {

View File

@ -40,21 +40,28 @@ type DiskLocation struct {
func GenerateDirUuid(dir string) (dirUuidString string, err error) { func GenerateDirUuid(dir string) (dirUuidString string, err error) {
glog.V(1).Infof("Getting uuid of volume directory:%s", dir) glog.V(1).Infof("Getting uuid of volume directory:%s", dir)
dirUuidString = ""
fileName := dir + "/vol_dir.uuid" fileName := dir + "/vol_dir.uuid"
if !util.FileExists(fileName) { if !util.FileExists(fileName) {
dirUuid, _ := uuid.NewRandom() dirUuidString, err = writeNewUuid(fileName)
dirUuidString = dirUuid.String()
writeErr := util.WriteFile(fileName, []byte(dirUuidString), 0644)
if writeErr != nil {
return "", fmt.Errorf("failed to write uuid to %s : %v", fileName, writeErr)
}
} else { } else {
uuidData, readErr := os.ReadFile(fileName) uuidData, readErr := os.ReadFile(fileName)
if readErr != nil { if readErr != nil {
return "", fmt.Errorf("failed to read uuid from %s : %v", fileName, readErr) return "", fmt.Errorf("failed to read uuid from %s : %v", fileName, readErr)
} }
if len(uuidData) > 0 {
dirUuidString = string(uuidData) dirUuidString = string(uuidData)
} else {
dirUuidString, err = writeNewUuid(fileName)
}
}
return dirUuidString, err
}
func writeNewUuid(fileName string) (string, error) {
dirUuid, _ := uuid.NewRandom()
dirUuidString := dirUuid.String()
if err := util.WriteFile(fileName, []byte(dirUuidString), 0644); err != nil {
return "", fmt.Errorf("failed to write uuid to %s : %v", fileName, err)
} }
return dirUuidString, nil return dirUuidString, nil
} }