blockstore: add GarbageCollect method to GCBlockstore interface
- Dominant language
- Go
- Stars
- 316
- Forks
- 163
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 8
Description
This is a short proposal to extend the `GCBlockstore` interface to add a method for performing garbage collection on the store. This is motivated by [this issue](https://github.com/ipfs/go-ipfs/issues/8870) which aims to enable alternate garbage collection algorithms to be used in go-ipfs.
I propose to add a single method `GarbageCollect` with the following signature
```Go
GarbageCollect(ctx context.Context, keep *cid.Set, goal int64, results chan<- GCResult)
```
When called the blockstore should attempt to remove unneeded or low value blocks in order to reclaim space. Since GC may be time consuming this method uses a channel to report progress and is intended to be run asynchronously.
The `keep` argument specified a set of CIDs of blocks that must be retained.
The `goal` argument is a hint to the blockstore for the amount of space that should be freed. It is informative not prescriptive. The blockstore should attempt to free at least this amount of space and may free more.
The method should return information about each block removed or errors encountered using the `results` argument.
GCResult is a struct that may hold information about a block that was removed or an error that was encountered while doing so
```Go
type GCResult struct {
KeyRemoved cid.Cid
Error error
}
```
Note that this interface change is a breaking change, however almost all applications that use GCBlockstore use the in-built implementation created using `NewGCBlockstore` and this can be adjusted to return a type that satisfies the modified interface . An alternate approach is to create a new interface that embeds `GCBlockstore` and the new method.
I have created an implementation of the proposed change: https://github.com/ipfs/go-ipfs-blockstore/pull/104
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.