Skip to content

Commit

Permalink
Add interface to clean partition resources
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Jul 11, 2021
1 parent e8b5751 commit b1bbbaf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions disk_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions fake_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ func (f *fakePartition) size() int {
func (f *fakePartition) active() bool {
return f.IsActive
}

func (f *fakePartition) clean() error {
return nil
}
6 changes: 6 additions & 0 deletions memory_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
3 changes: 3 additions & 0 deletions partition_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b1bbbaf

Please sign in to comment.