mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 15:16:42 +00:00
lib/storage: store node ID in metadata so that it is included in the backups
Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
This commit is contained in:
parent
8d8073a24d
commit
41e217423f
1 changed files with 13 additions and 14 deletions
|
@ -214,19 +214,6 @@ func MustOpenStorage(path string, retention time.Duration, maxHourlySeries, maxD
|
||||||
logger.Panicf("FATAL: incomplete vmrestore run; run vmrestore again or remove lock file %q", restoreLockF)
|
logger.Panicf("FATAL: incomplete vmrestore run; run vmrestore again or remove lock file %q", restoreLockF)
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeIDFileF := filepath.Join(path, nodeIDFilename)
|
|
||||||
if fs.IsPathExist(nodeIDFileF) {
|
|
||||||
r, err := os.Open(nodeIDFileF)
|
|
||||||
nodeID, err := io.ReadAll(r)
|
|
||||||
if err != nil {
|
|
||||||
logger.Panicf("FATAL: cannot read nodeID from %q: %s", nodeIDFileF, err)
|
|
||||||
}
|
|
||||||
s.nodeID = encoding.UnmarshalUint64(nodeID)
|
|
||||||
} else {
|
|
||||||
nodeID := rand.Uint64()
|
|
||||||
s.nodeID = nodeID
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pre-create snapshots directory if it is missing.
|
// Pre-create snapshots directory if it is missing.
|
||||||
snapshotsPath := filepath.Join(path, snapshotsDirname)
|
snapshotsPath := filepath.Join(path, snapshotsDirname)
|
||||||
fs.MustMkdirIfNotExist(snapshotsPath)
|
fs.MustMkdirIfNotExist(snapshotsPath)
|
||||||
|
@ -262,6 +249,18 @@ func MustOpenStorage(path string, retention time.Duration, maxHourlySeries, maxD
|
||||||
isEmptyDB := !fs.IsPathExist(filepath.Join(path, indexdbDirname))
|
isEmptyDB := !fs.IsPathExist(filepath.Join(path, indexdbDirname))
|
||||||
fs.MustMkdirIfNotExist(metadataDir)
|
fs.MustMkdirIfNotExist(metadataDir)
|
||||||
s.minTimestampForCompositeIndex = mustGetMinTimestampForCompositeIndex(metadataDir, isEmptyDB)
|
s.minTimestampForCompositeIndex = mustGetMinTimestampForCompositeIndex(metadataDir, isEmptyDB)
|
||||||
|
nodeIDFileF := filepath.Join(metadataDir, nodeIDFilename)
|
||||||
|
if fs.IsPathExist(nodeIDFileF) {
|
||||||
|
r, err := os.Open(nodeIDFileF)
|
||||||
|
nodeID, err := io.ReadAll(r)
|
||||||
|
if err != nil {
|
||||||
|
logger.Panicf("FATAL: cannot read nodeID from %q: %s", nodeIDFileF, err)
|
||||||
|
}
|
||||||
|
s.nodeID = encoding.UnmarshalUint64(nodeID)
|
||||||
|
} else {
|
||||||
|
nodeID := rand.Uint64()
|
||||||
|
s.nodeID = nodeID
|
||||||
|
}
|
||||||
|
|
||||||
// Load indexdb
|
// Load indexdb
|
||||||
idbPath := filepath.Join(path, indexdbDirname)
|
idbPath := filepath.Join(path, indexdbDirname)
|
||||||
|
@ -1053,7 +1052,7 @@ func (s *Storage) mustLoadHourMetricIDs(hour uint64, name string) *hourMetricIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) mustSaveNodeID() {
|
func (s *Storage) mustSaveNodeID() {
|
||||||
path := filepath.Join(s.path, nodeIDFilename)
|
path := filepath.Join(s.path, metadataDirname, nodeIDFilename)
|
||||||
dst := make([]byte, 0)
|
dst := make([]byte, 0)
|
||||||
dst = encoding.MarshalUint64(dst, s.nodeID)
|
dst = encoding.MarshalUint64(dst, s.nodeID)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue