mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2024-11-10 05:07:25 +01:00
improve logging messages
This commit is contained in:
parent
878e9d7154
commit
ac7e981321
42
archive.go
42
archive.go
@ -66,7 +66,7 @@ func (m *MemoryStore) ToCheckpoint(dir string, from, to int64) (int, error) {
|
|||||||
n += 1
|
n += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *level) toCheckpointFile(from, to int64, m *MemoryStore) (*CheckpointFile, error) {
|
func (l *level) toCheckpointFile(from, to int64, m *MemoryStore) (*CheckpointFile, error) {
|
||||||
@ -399,40 +399,44 @@ func findFiles(direntries []fs.DirEntry, t int64, findMoreRecentFiles bool) ([]s
|
|||||||
|
|
||||||
// ZIP all checkpoint files older than `from` together and write them to the `archiveDir`,
|
// ZIP all checkpoint files older than `from` together and write them to the `archiveDir`,
|
||||||
// deleting them from the `checkpointsDir`.
|
// deleting them from the `checkpointsDir`.
|
||||||
func ArchiveCheckpoints(checkpointsDir, archiveDir string, from int64) error {
|
func ArchiveCheckpoints(checkpointsDir, archiveDir string, from int64) (int, error) {
|
||||||
entries1, err := os.ReadDir(checkpointsDir)
|
entries1, err := os.ReadDir(checkpointsDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n := 0
|
||||||
for _, de1 := range entries1 {
|
for _, de1 := range entries1 {
|
||||||
entries2, err := os.ReadDir(filepath.Join(checkpointsDir, de1.Name()))
|
entries2, err := os.ReadDir(filepath.Join(checkpointsDir, de1.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, de2 := range entries2 {
|
for _, de2 := range entries2 {
|
||||||
cdir := filepath.Join(checkpointsDir, de1.Name(), de2.Name())
|
cdir := filepath.Join(checkpointsDir, de1.Name(), de2.Name())
|
||||||
adir := filepath.Join(archiveDir, de1.Name(), de2.Name())
|
adir := filepath.Join(archiveDir, de1.Name(), de2.Name())
|
||||||
if err := archiveCheckpoints(cdir, adir, from); err != nil {
|
m, err := archiveCheckpoints(cdir, adir, from)
|
||||||
return err
|
n += m
|
||||||
|
if err != nil {
|
||||||
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function for `ArchiveCheckpoints`.
|
// Helper function for `ArchiveCheckpoints`.
|
||||||
func archiveCheckpoints(dir string, archiveDir string, from int64) error {
|
func archiveCheckpoints(dir string, archiveDir string, from int64) (int, error) {
|
||||||
entries, err := os.ReadDir(dir)
|
entries, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := findFiles(entries, from, false)
|
files, err := findFiles(entries, from, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
filename := filepath.Join(archiveDir, fmt.Sprintf("%d.zip", from))
|
filename := filepath.Join(archiveDir, fmt.Sprintf("%d.zip", from))
|
||||||
@ -444,40 +448,42 @@ func archiveCheckpoints(dir string, archiveDir string, from int64) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
bw := bufio.NewWriter(f)
|
bw := bufio.NewWriter(f)
|
||||||
zw := zip.NewWriter(bw)
|
zw := zip.NewWriter(bw)
|
||||||
|
|
||||||
|
n := 0
|
||||||
for _, jsonFile := range files {
|
for _, jsonFile := range files {
|
||||||
filename := filepath.Join(dir, jsonFile)
|
filename := filepath.Join(dir, jsonFile)
|
||||||
r, err := os.Open(filename)
|
r, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
w, err := zw.Create(jsonFile)
|
w, err := zw.Create(jsonFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = io.Copy(w, r); err != nil {
|
if _, err = io.Copy(w, r); err != nil {
|
||||||
return err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.Remove(filename); err != nil {
|
if err = os.Remove(filename); err != nil {
|
||||||
return err
|
return n, err
|
||||||
}
|
}
|
||||||
|
n += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = zw.Close(); err != nil {
|
if err = zw.Close(); err != nil {
|
||||||
return err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bw.Flush(); err != nil {
|
if err = bw.Flush(); err != nil {
|
||||||
return err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
@ -147,13 +147,13 @@ func intervals(wg *sync.WaitGroup, ctx context.Context) {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-ticks:
|
case <-ticks:
|
||||||
log.Println("Freeing up memory...")
|
|
||||||
t := time.Now().Add(-d)
|
t := time.Now().Add(-d)
|
||||||
|
log.Printf("start freeing buffers (older than %s)...\n", t.Format(time.RFC3339))
|
||||||
freed, err := memoryStore.Free(Selector{}, t.Unix())
|
freed, err := memoryStore.Free(Selector{}, t.Unix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Freeing up memory failed: %s\n", err.Error())
|
log.Printf("freeing up buffers failed: %s\n", err.Error())
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%d buffers freed\n", freed)
|
log.Printf("done: %d buffers freed\n", freed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,14 +172,14 @@ func intervals(wg *sync.WaitGroup, ctx context.Context) {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-ticks:
|
case <-ticks:
|
||||||
log.Println("Checkpoint creation started...")
|
log.Printf("start checkpointing (starting at %s)...\n", lastCheckpoint.Format(time.RFC3339))
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
n, err := memoryStore.ToCheckpoint(conf.Checkpoints.RootDir,
|
n, err := memoryStore.ToCheckpoint(conf.Checkpoints.RootDir,
|
||||||
lastCheckpoint.Unix(), now.Unix())
|
lastCheckpoint.Unix(), now.Unix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Checkpoint creation failed: %s\n", err.Error())
|
log.Printf("checkpointing failed: %s\n", err.Error())
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Checkpoint finished (%d files)\n", n)
|
log.Printf("done: %d checkpoint files created\n", n)
|
||||||
lastCheckpoint = now
|
lastCheckpoint = now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,13 +198,13 @@ func intervals(wg *sync.WaitGroup, ctx context.Context) {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-ticks:
|
case <-ticks:
|
||||||
log.Println("Start zipping and deleting old checkpoints...")
|
|
||||||
t := time.Now().Add(-d)
|
t := time.Now().Add(-d)
|
||||||
err := ArchiveCheckpoints(conf.Checkpoints.RootDir, conf.Archive.RootDir, t.Unix())
|
log.Printf("start archiving checkpoints (older than %s)...\n", t.Format(time.RFC3339))
|
||||||
|
n, err := ArchiveCheckpoints(conf.Checkpoints.RootDir, conf.Archive.RootDir, t.Unix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Archiving failed: %s\n", err.Error())
|
log.Printf("archiving failed: %s\n", err.Error())
|
||||||
} else {
|
} else {
|
||||||
log.Println("Archiving checkpoints completed!")
|
log.Printf("done: %d files zipped and moved to archive\n", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user