Skip to content

Commit

Permalink
gc: invoke CollectGarbage() on badger to reclaim disk space
Browse files Browse the repository at this point in the history
  • Loading branch information
ns4plabs authored and aschmahmann committed Dec 12, 2023
1 parent dec8d5a commit 060bcc7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions gc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package main

import "context"
import (
"context"

badger4 "github.com/ipfs/go-ds-badger4"
)

// GC is a really stupid simple algorithm where we just delete things until
// weve deleted enough things
Expand All @@ -10,11 +14,12 @@ func (nd *Node) GC(ctx context.Context, todelete int64) error {
return err
}

deleteBlocks:
for todelete > 0 {
select {
case k, ok := <-keys:
if !ok {
return nil
break deleteBlocks
}

size, err := nd.blockstore.GetSize(ctx, k)
Expand All @@ -32,5 +37,12 @@ func (nd *Node) GC(ctx context.Context, todelete int64) error {
}
}

if ds, ok := nd.datastore.(*badger4.Datastore); ok {
err = ds.CollectGarbage(ctx)
if err != nil {
return err
}
}

return nil
}

0 comments on commit 060bcc7

Please sign in to comment.