Incorporate feedback.

Move back to {Enable, Disable}Compactions.

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2017-06-06 20:23:20 +05:30
parent a110a64abd
commit 261cd9f393
No known key found for this signature in database
GPG Key ID: F1C217E8E9023CAD
2 changed files with 22 additions and 10 deletions

View File

@ -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
View File

@ -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")
}