Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gc: invoke CollectGarbage() on badger to reclaim disk space #41

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
return err
}

deleteBlocks:

Check warning on line 17 in gc.go

View check run for this annotation

Codecov / codecov/patch

gc.go#L17

Added line #L17 was not covered by tests
for todelete > 0 {
select {
case k, ok := <-keys:
if !ok {
return nil
break deleteBlocks

Check warning on line 22 in gc.go

View check run for this annotation

Codecov / codecov/patch

gc.go#L22

Added line #L22 was not covered by tests
}

size, err := nd.blockstore.GetSize(ctx, k)
Expand All @@ -32,5 +37,12 @@
}
}

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

Check warning on line 44 in gc.go

View check run for this annotation

Codecov / codecov/patch

gc.go#L40-L44

Added lines #L40 - L44 were not covered by tests
}

return nil
}
Loading