mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 07:57:30 +08:00
gc: add events for profiling GC
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
21
pin/gc/gc.go
21
pin/gc/gc.go
@ -9,10 +9,13 @@ import (
|
|||||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||||
pin "github.com/ipfs/go-ipfs/pin"
|
pin "github.com/ipfs/go-ipfs/pin"
|
||||||
|
|
||||||
|
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||||
cid "gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
|
cid "gx/ipfs/QmTprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS/go-cid"
|
||||||
node "gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
|
node "gx/ipfs/QmYNyRZJBUYPNrLszFmrBrPJbsBh2vMsefz5gnDpB5M1P6/go-ipld-format"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = logging.Logger("gc")
|
||||||
|
|
||||||
// Result represents an incremental output from a garbage collection
|
// Result represents an incremental output from a garbage collection
|
||||||
// run. It contains either an error, or the cid of a removed object.
|
// run. It contains either an error, or the cid of a removed object.
|
||||||
type Result struct {
|
type Result struct {
|
||||||
@ -31,7 +34,13 @@ type Result struct {
|
|||||||
// deletes any block that is not found in the marked set.
|
// deletes any block that is not found in the marked set.
|
||||||
//
|
//
|
||||||
func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.Pinner, bestEffortRoots []*cid.Cid) <-chan Result {
|
func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.Pinner, bestEffortRoots []*cid.Cid) <-chan Result {
|
||||||
|
|
||||||
|
elock := log.EventBegin(ctx, "GC.lockWait")
|
||||||
unlocker := bs.GCLock()
|
unlocker := bs.GCLock()
|
||||||
|
elock.Done()
|
||||||
|
elock = log.EventBegin(ctx, "GC.locked")
|
||||||
|
emark := log.EventBegin(ctx, "GC.mark")
|
||||||
|
|
||||||
ls = ls.GetOfflineLinkService()
|
ls = ls.GetOfflineLinkService()
|
||||||
|
|
||||||
output := make(chan Result, 128)
|
output := make(chan Result, 128)
|
||||||
@ -39,12 +48,18 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
|
|||||||
go func() {
|
go func() {
|
||||||
defer close(output)
|
defer close(output)
|
||||||
defer unlocker.Unlock()
|
defer unlocker.Unlock()
|
||||||
|
defer elock.Done()
|
||||||
|
|
||||||
gcs, err := ColoredSet(ctx, pn, ls, bestEffortRoots, output)
|
gcs, err := ColoredSet(ctx, pn, ls, bestEffortRoots, output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
output <- Result{Error: err}
|
output <- Result{Error: err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
emark.Append(logging.LoggableMap{
|
||||||
|
"blackSetSize": fmt.Sprintf("%d", gcs.Len()),
|
||||||
|
})
|
||||||
|
emark.Done()
|
||||||
|
esweep := log.EventBegin(ctx, "GC.sweep")
|
||||||
|
|
||||||
keychan, err := bs.AllKeysChan(ctx)
|
keychan, err := bs.AllKeysChan(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -53,6 +68,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
|
|||||||
}
|
}
|
||||||
|
|
||||||
errors := false
|
errors := false
|
||||||
|
var removed uint64
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
@ -63,6 +79,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
|
|||||||
}
|
}
|
||||||
if !gcs.Has(k) {
|
if !gcs.Has(k) {
|
||||||
err := bs.DeleteBlock(k)
|
err := bs.DeleteBlock(k)
|
||||||
|
removed++
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors = true
|
errors = true
|
||||||
output <- Result{Error: &CannotDeleteBlockError{k, err}}
|
output <- Result{Error: &CannotDeleteBlockError{k, err}}
|
||||||
@ -80,6 +97,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
|
|||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
esweep.Append(logging.LoggableMap{
|
||||||
|
"whiteSetSize": fmt.Sprintf("%d", removed),
|
||||||
|
})
|
||||||
|
esweep.Done()
|
||||||
if errors {
|
if errors {
|
||||||
output <- Result{Error: ErrCannotDeleteSomeBlocks}
|
output <- Result{Error: ErrCannotDeleteSomeBlocks}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user