mirror of
https://github.com/prometheus/prometheus
synced 2024-12-27 00:53:12 +00:00
Incorporate feedback.
Move back to {Enable, Disable}Compactions. Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
parent
a110a64abd
commit
261cd9f393
7
block.go
7
block.go
@ -291,8 +291,11 @@ func (pb *persistedBlock) Snapshot(dir string) error {
|
||||
}
|
||||
|
||||
// Hardlink meta, index and tombstones
|
||||
filenames := []string{metaFilename, indexFilename, tombstoneFilename}
|
||||
for _, fname := range filenames {
|
||||
for _, fname := range []string{
|
||||
metaFilename,
|
||||
indexFilename,
|
||||
tombstoneFilename,
|
||||
} {
|
||||
if err := os.Link(filepath.Join(pb.dir, fname), filepath.Join(blockDir, fname)); err != nil {
|
||||
return errors.Wrapf(err, "create snapshot %s", fname)
|
||||
}
|
||||
|
21
db.go
21
db.go
@ -530,20 +530,29 @@ func (db *DB) Close() error {
|
||||
return merr.Err()
|
||||
}
|
||||
|
||||
// ToggleCompactions toggles compactions and returns if compactions are on or not.
|
||||
func (db *DB) ToggleCompactions() bool {
|
||||
// DisableCompactions disables compactions.
|
||||
func (db *DB) DisableCompactions() error {
|
||||
if db.compacting {
|
||||
db.cmtx.Lock()
|
||||
db.compacting = false
|
||||
return false
|
||||
db.logger.Log("msg", "compactions disabled")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnableCompactions enables compactions.
|
||||
func (db *DB) EnableCompactions() error {
|
||||
if !db.compacting {
|
||||
db.cmtx.Unlock()
|
||||
db.compacting = true
|
||||
return true
|
||||
db.logger.Log("msg", "compactions enabled")
|
||||
}
|
||||
|
||||
// Snapshot writes the current headBlock snapshots to snapshots directory.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Snapshot writes the current data to the directory.
|
||||
func (db *DB) Snapshot(dir string) error {
|
||||
db.mtx.Lock() // To block any appenders.
|
||||
defer db.mtx.Unlock()
|
||||
@ -553,7 +562,7 @@ func (db *DB) Snapshot(dir string) error {
|
||||
|
||||
blocks := db.blocks[:]
|
||||
for _, b := range blocks {
|
||||
db.logger.Log("msg", "compacting block", "block", b.Dir())
|
||||
db.logger.Log("msg", "snapshotting block", "block", b)
|
||||
if err := b.Snapshot(dir); err != nil {
|
||||
return errors.Wrap(err, "error snapshotting headblock")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user