mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-06-28 15:41:13 +08:00
added re-generating and writing the Volume UUID if it is empty (#6568)
This commit is contained in:
parent
be74548cb5
commit
ef4eda0761
@ -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 {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
dirUuidString = string(uuidData)
|
if len(uuidData) > 0 {
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user