mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/{mergeset,storage}: make mustReadPartNames() code more clear
This commit is contained in:
parent
52006149b2
commit
2a4c48c59d
2 changed files with 10 additions and 10 deletions
|
@ -1477,17 +1477,17 @@ func mustWritePartNames(pws []*partWrapper, dstDir string) {
|
|||
|
||||
func mustReadPartNames(srcDir string) []string {
|
||||
partNamesPath := filepath.Join(srcDir, partsFilename)
|
||||
data, err := os.ReadFile(partNamesPath)
|
||||
if err == nil {
|
||||
if fs.IsPathExist(partNamesPath) {
|
||||
data, err := os.ReadFile(partNamesPath)
|
||||
if err != nil {
|
||||
logger.Panicf("FATAL: cannot read %s file: %s", partsFilename, err)
|
||||
}
|
||||
var partNames []string
|
||||
if err := json.Unmarshal(data, &partNames); err != nil {
|
||||
logger.Panicf("FATAL: cannot parse %s: %s", partNamesPath, err)
|
||||
}
|
||||
return partNames
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
logger.Panicf("FATAL: cannot read %s file: %s", partsFilename, err)
|
||||
}
|
||||
// The partsFilename is missing. This is the upgrade from versions previous to v1.90.0.
|
||||
// Read part names from directories under srcDir
|
||||
des := fs.MustReadDir(srcDir)
|
||||
|
|
|
@ -1903,17 +1903,17 @@ func getPartNames(pws []*partWrapper) []string {
|
|||
|
||||
func mustReadPartNames(smallPartsPath, bigPartsPath string) ([]string, []string) {
|
||||
partNamesPath := filepath.Join(smallPartsPath, partsFilename)
|
||||
data, err := os.ReadFile(partNamesPath)
|
||||
if err == nil {
|
||||
if fs.IsPathExist(partNamesPath) {
|
||||
data, err := os.ReadFile(partNamesPath)
|
||||
if err != nil {
|
||||
logger.Panicf("FATAL: cannot read %s file: %s", partsFilename, err)
|
||||
}
|
||||
var partNames partNamesJSON
|
||||
if err := json.Unmarshal(data, &partNames); err != nil {
|
||||
logger.Panicf("FATAL: cannot parse %s: %s", partNamesPath, err)
|
||||
}
|
||||
return partNames.Small, partNames.Big
|
||||
}
|
||||
if !os.IsNotExist(err) {
|
||||
logger.Panicf("FATAL: cannot read %s file: %s", partsFilename, err)
|
||||
}
|
||||
// The partsFilename is missing. This is the upgrade from versions previous to v1.90.0.
|
||||
// Read part names from smallPartsPath and bigPartsPath directories
|
||||
partNamesSmall := mustReadPartNamesFromDir(smallPartsPath)
|
||||
|
|
Loading…
Reference in a new issue