Skip to content

Commit

Permalink
for now, add duplicate stale refs to the keep set
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Sep 28, 2023
1 parent 0dbe63e commit 7a2f105
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 7 additions & 0 deletions bgs/bgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ func (bgs *BGS) StartWithListener(listen net.Listener) error {
sendHeader = false
}

if strings.HasPrefix(ctx.Path(), "/admin/") {
return ctx.JSON(500, map[string]any{
"error": err.Error(),
})

}

log.Warnf("HANDLER ERROR: (%s) %s", ctx.Path(), err)

if sendHeader {
Expand Down
21 changes: 18 additions & 3 deletions carstore/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
cbor "github.com/ipfs/go-ipld-cbor"
ipld "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-libipfs/blocks"
logging "github.com/ipfs/go-log"
car "github.com/ipld/go-car"
carutil "github.com/ipld/go-car/util"
cbg "github.com/whyrusleeping/cbor-gen"
Expand All @@ -31,6 +32,8 @@ import (
"gorm.io/gorm"
)

var log = logging.Logger("carstore")

const MaxSliceLength = 2 << 20

type CarStore struct {
Expand Down Expand Up @@ -1180,6 +1183,7 @@ type CompactionStats struct {
SkippedShards int `json:"skippedShards"`
ShardsDeleted int `json:"shardsDeleted"`
RefsDeleted int `json:"refsDeleted"`
DupeCount int `json:"dupeCount"`
}

func (cs *CarStore) CompactUserShards(ctx context.Context, user models.Uid) (*CompactionStats, error) {
Expand Down Expand Up @@ -1214,13 +1218,16 @@ func (cs *CarStore) CompactUserShards(ctx context.Context, user models.Uid) (*Co
}

stale := make(map[cid.Cid]bool)
var dupes []cid.Cid
var hasDirtyDupes bool
for _, br := range staleRefs {
if stale[br.Cid.CID] {
delete(stale, br.Cid.CID) // remove dupes from stale list, see comment below
hasDirtyDupes = true
break
dupes = append(dupes, br.Cid.CID)
} else {
stale[br.Cid.CID] = true
}
stale[br.Cid.CID] = true
}

if hasDirtyDupes {
Expand All @@ -1233,7 +1240,10 @@ func (cs *CarStore) CompactUserShards(ctx context.Context, user models.Uid) (*Co
// focus on compacting everything else. it leaves *some* dirty blocks
// still around but we're doing that anyways since compaction isnt a
// perfect process
return nil, fmt.Errorf("WIP: not currently handling this case")

log.Warnw("repo has dirty dupes", "count", len(dupes), "uid", user, "staleRefs", len(staleRefs), "blockRefs", len(brefs))

//return nil, fmt.Errorf("WIP: not currently handling this case")
}

keep := make(map[cid.Cid]bool)
Expand All @@ -1243,6 +1253,10 @@ func (cs *CarStore) CompactUserShards(ctx context.Context, user models.Uid) (*Co
}
}

for _, dupe := range dupes {
keep[dupe] = true
}

results := aggrRefs(brefs, shardsById, stale)
var sum int
for _, r := range results {
Expand Down Expand Up @@ -1335,6 +1349,7 @@ func (cs *CarStore) CompactUserShards(ctx context.Context, user models.Uid) (*Co
}

stats.RefsDeleted = num
stats.DupeCount = len(dupes)

return stats, nil
}
Expand Down

0 comments on commit 7a2f105

Please sign in to comment.