From b1bbbafe00c65da63ce4eb66161134da4e15b92f Mon Sep 17 00:00:00 2001 From: nakabonne Date: Sun, 11 Jul 2021 14:33:01 +0900 Subject: [PATCH] Add interface to clean partition resources --- disk_partition.go | 5 +++++ fake_partition.go | 4 ++++ memory_partition.go | 6 ++++++ partition.go | 2 ++ partition_list.go | 3 +++ 5 files changed, 20 insertions(+) diff --git a/disk_partition.go b/disk_partition.go index 415f656..407b380 100644 --- a/disk_partition.go +++ b/disk_partition.go @@ -142,3 +142,8 @@ func (d *diskPartition) size() int { func (d *diskPartition) active() bool { return false } + +func (d *diskPartition) clean() error { + // FIXME: Remove the directory this partition holds. + return nil +} diff --git a/fake_partition.go b/fake_partition.go index c14f961..43dd2db 100644 --- a/fake_partition.go +++ b/fake_partition.go @@ -32,3 +32,7 @@ func (f *fakePartition) size() int { func (f *fakePartition) active() bool { return f.IsActive } + +func (f *fakePartition) clean() error { + return nil +} diff --git a/memory_partition.go b/memory_partition.go index 2f13ee5..b5932bc 100644 --- a/memory_partition.go +++ b/memory_partition.go @@ -155,6 +155,12 @@ func (m *memoryPartition) active() bool { return m.maxTimestamp()-m.minTimestamp()+1 < m.partitionDuration } +func (m *memoryPartition) clean() error { + // What all data managed by memoryPartition is on heap that is automatically removed by GC. + // So do nothing. + return nil +} + // memoryMetric has a list of ordered data points that belong to the memoryMetric type memoryMetric struct { name string diff --git a/partition.go b/partition.go index 6adc5f2..fce0d6e 100644 --- a/partition.go +++ b/partition.go @@ -16,6 +16,8 @@ type partition interface { // If data points older than its min timestamp were given, they won't be // ingested, instead, gave back as a first returned value. insertRows(rows []Row) (outdatedRows []Row, err error) + // clean removes everything managed by this partition. + clean() error // Read operations // diff --git a/partition_list.go b/partition_list.go index e553db1..247a2de 100644 --- a/partition_list.go +++ b/partition_list.go @@ -98,6 +98,9 @@ func (p *partitionListImpl) remove(target partition) error { } // remove the current node. + if err := current.value().clean(); err != nil { + return fmt.Errorf("failed to clean resources managed by partition to be removed: %w", err) + } iterator.next() next = iterator.currentNode()