Skip to content

Commit

Permalink
use background contexts for repo compaction admin routes
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Sep 28, 2023
1 parent c764642 commit ee8aa7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bgs/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/bluesky-social/indigo/models"
"github.com/labstack/echo/v4"
dto "github.com/prometheus/client_model/go"
"go.opentelemetry.io/otel"
"golang.org/x/time/rate"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -397,7 +398,8 @@ func (bgs *BGS) handleAdminChangePDSCrawlLimit(e echo.Context) error {
}

func (bgs *BGS) handleAdminCompactRepo(e echo.Context) error {
ctx := e.Request().Context()
ctx, span := otel.Tracer("bgs").Start(context.Background(), "adminCompactRepo")
defer span.End()

did := e.QueryParam("did")
if did == "" {
Expand All @@ -421,7 +423,8 @@ func (bgs *BGS) handleAdminCompactRepo(e echo.Context) error {
}

func (bgs *BGS) handleAdminCompactAllRepos(e echo.Context) error {
ctx := e.Request().Context()
ctx, span := otel.Tracer("bgs").Start(context.Background(), "adminCompactAllRepos")
defer span.End()

if err := bgs.runRepoCompaction(ctx); err != nil {
return fmt.Errorf("compaction run failed: %w", err)
Expand Down
7 changes: 7 additions & 0 deletions carstore/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,13 @@ func (cs *CarStore) compactBucket(ctx context.Context, user models.Uid, b *compB
}

if err := cs.putShard(ctx, &shard, nbrefs, nil, true); err != nil {
// if writing the shard fails, we should also delete the file
_ = fi.Close()

if err2 := os.Remove(fi.Name()); err2 != nil {
log.Errorf("failed to remove shard file (%s) after failed db transaction: %w", fi.Name(), err2)
}

return err
}
return nil
Expand Down

0 comments on commit ee8aa7a

Please sign in to comment.