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