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 // Hardlink meta, index and tombstones
filenames := []string{metaFilename, indexFilename, tombstoneFilename} for _, fname := range []string{
for _, fname := range filenames { metaFilename,
indexFilename,
tombstoneFilename,
} {
if err := os.Link(filepath.Join(pb.dir, fname), filepath.Join(blockDir, fname)); err != nil { if err := os.Link(filepath.Join(pb.dir, fname), filepath.Join(blockDir, fname)); err != nil {
return errors.Wrapf(err, "create snapshot %s", fname) return errors.Wrapf(err, "create snapshot %s", fname)
} }

25
db.go
View file

@ -530,20 +530,29 @@ func (db *DB) Close() error {
return merr.Err() return merr.Err()
} }
// ToggleCompactions toggles compactions and returns if compactions are on or not. // DisableCompactions disables compactions.
func (db *DB) ToggleCompactions() bool { func (db *DB) DisableCompactions() error {
if db.compacting { if db.compacting {
db.cmtx.Lock() db.cmtx.Lock()
db.compacting = false db.compacting = false
return false db.logger.Log("msg", "compactions disabled")
} }
db.cmtx.Unlock() return nil
db.compacting = true
return true
} }
// Snapshot writes the current headBlock snapshots to snapshots directory. // EnableCompactions enables compactions.
func (db *DB) EnableCompactions() error {
if !db.compacting {
db.cmtx.Unlock()
db.compacting = true
db.logger.Log("msg", "compactions enabled")
}
return nil
}
// Snapshot writes the current data to the directory.
func (db *DB) Snapshot(dir string) error { func (db *DB) Snapshot(dir string) error {
db.mtx.Lock() // To block any appenders. db.mtx.Lock() // To block any appenders.
defer db.mtx.Unlock() defer db.mtx.Unlock()
@ -553,7 +562,7 @@ func (db *DB) Snapshot(dir string) error {
blocks := db.blocks[:] blocks := db.blocks[:]
for _, b := range 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 { if err := b.Snapshot(dir); err != nil {
return errors.Wrap(err, "error snapshotting headblock") return errors.Wrap(err, "error snapshotting headblock")
} }