From 0306fc61932dbf2d3bb35173f5d741eca7d6a814 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Wed, 3 Aug 2016 10:09:57 -0600 Subject: [PATCH] delete snaphost when task is deleted --- CHANGELOG.md | 1 + services/task_store/dao.go | 9 ++++++++- services/task_store/service.go | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9842ff008..4cecefcc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - [#783](https://github.com/influxdata/kapacitor/pull/783): Fix panic when revoking tokens not already defined. - [#784](https://github.com/influxdata/kapacitor/pull/784): Fix several issues with comment formatting in TICKscript. +- [#772](https://github.com/influxdata/kapacitor/issues/772): Delete task snapshot data when a task is deleted. ## v1.0.0-beta4 [2016-07-27] diff --git a/services/task_store/dao.go b/services/task_store/dao.go index 52b16ec96..53e3fa4de 100644 --- a/services/task_store/dao.go +++ b/services/task_store/dao.go @@ -78,10 +78,12 @@ type TemplateDAO interface { // Data access object for Snapshot data. type SnapshotDAO interface { // Load a saved snapshot. - // ErrNoSnapshotExists will be returned if HasSnapshot returns false. + // ErrNoSnapshotExists will be returned if the snapshot does not exist. Get(id string) (*Snapshot, error) // Save a snapshot. Put(id string, snapshot *Snapshot) error + // Delete a snapshot + Delete(id string) error // Whether a snapshot exists in the store. Exists(id string) (bool, error) } @@ -563,6 +565,11 @@ func (d *snapshotKV) Put(id string, snapshot *Snapshot) error { return d.store.Put(key, data) } +func (d *snapshotKV) Delete(id string) error { + key := d.snapshotDataKey(id) + return d.store.Delete(key) +} + func (d *snapshotKV) Exists(id string) (bool, error) { key := d.snapshotDataKey(id) return d.store.Exists(key) diff --git a/services/task_store/service.go b/services/task_store/service.go index f61299fe1..c940576a2 100644 --- a/services/task_store/service.go +++ b/services/task_store/service.go @@ -1301,6 +1301,10 @@ func (ts *Service) handleDeleteTask(w http.ResponseWriter, r *http.Request) { } func (ts *Service) deleteTask(id string) error { + // Delete associated snapshot + ts.snapshots.Delete(id) + + // Delete task object task, err := ts.tasks.Get(id) if err != nil { if err == ErrNoTaskExists {