# Interruptable garbage collection

**URL:** <https://discuss.dgraph.io/t/interruptable-garbage-collection/8734>\
**Category:** Issues\
**Tags:** badger, kind:enhancement, status:accepted\
**Created:** [May 6, 2020, 8:32pm UTC](https://discuss.dgraph.io/t/interruptable-garbage-collection/8734 "2020-05-06T20:32:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 6, 2020, 8:32pm UTC](https://discuss.dgraph.io/t/interruptable-garbage-collection/8734/1 "2020-05-06T20:32:58Z")

</div>

**Moved from GitHub [badger/1324](https://github.com/dgraph-io/badger/issues/1324)**

_Posted by_ [Stebalien](https://github.com/Stebalien):

### What version of Go are you using (`go version`)?

```
$ go version
go version go1.14.2 amd64/linux
```

### What operating system are you using?

Linux

### What version of Badger are you using?

v1.6.1

### Description

`RunValueLogGC` cannot be interrupted and can potentially run for minutes on a large enough datastore. This can be a problem if garbage collection is running on shutdown.

It would be nice to be able to pass a context to `RunValueLogGC` to cancel the process early. Alternatively, allowing a concurrent call to `Close` to interrupt a GC run would fix this. However, at the moment, close can’t be called concurrently with anything else.

Would a new `RunValueLogGCWithContext` function be considered if a patch were proposed?

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 9, 2020, 7:42am UTC](https://discuss.dgraph.io/t/interruptable-garbage-collection/8734/2 "2020-05-09T07:42:21Z")

</div>

[jarifibrahim](https://github.com/jarifibrahim) _commented_ :

This looks like a useful enhancement since GC could take minutes at times to complete.The GC has two steps. The first sampling step can be exited at any time.  
[badger/value.go at 536fed1846d0f4db9579bcff6797614e134eadfa · dgraph-io/badger · GitHub](https://github.com/dgraph-io/badger/blob/536fed1846d0f4db9579bcff6797614e134eadfa/value.go#L1628) The second step is where we rewrite the value log file. I’m wondering if there would be any side effects of stopping the rewrite while it’s running [badger/value.go at 536fed1846d0f4db9579bcff6797614e134eadfa · dgraph-io/badger · GitHub](https://github.com/dgraph-io/badger/blob/536fed1846d0f4db9579bcff6797614e134eadfa/value.go#L499)
