Skip to content

Commit

Permalink
Dedup the blobmetadata from the blobstore (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix authored Nov 14, 2023
1 parent 998f329 commit b8c1514
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions disperser/dataapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@ func (s *server) FetchNonSigners(c *gin.Context) {

func (s *server) getBlobMetadataByBatchesWithLimit(ctx context.Context, limit int) ([]*Batch, []*disperser.BlobMetadata, error) {
var (
blobMetadatas = make([]*disperser.BlobMetadata, 0)
batches = make([]*Batch, 0)
blobMetadatas = make([]*disperser.BlobMetadata, 0)
batches = make([]*Batch, 0)
blobKeyPresence = make(map[string]struct{})
batchPresence = make(map[string]struct{})
)

for skip := 0; len(blobMetadatas) < limit && skip < limit; skip += maxQueryBatchesLimit {
Expand All @@ -383,13 +385,29 @@ func (s *server) getBlobMetadataByBatchesWithLimit(ctx context.Context, limit in
s.logger.Error("Failed to convert batch header hash to hex string", "error", err)
continue
}
batchKey := string(batchHeaderHash[:])
if _, found := batchPresence[batchKey]; !found {
batchPresence[batchKey] = struct{}{}
} else {
// The batch has processed, skip it.
s.logger.Error("Getting duplicate batch from the graph", "batch header hash", batchKey)
continue
}

metadatas, err := s.blobstore.GetAllBlobMetadataByBatch(ctx, batchHeaderHash)
if err != nil {
s.logger.Error("Failed to get blob metadata", "error", err)
continue
}
blobMetadatas = append(blobMetadatas, metadatas...)
for _, bm := range metadatas {
blobKey := bm.GetBlobKey().String()
if _, found := blobKeyPresence[blobKey]; !found {
blobKeyPresence[blobKey] = struct{}{}
blobMetadatas = append(blobMetadatas, bm)
} else {
s.logger.Error("Getting duplicate blob key from the blobstore", "blobkey", blobKey)
}
}
batches = append(batches, batch)
if len(blobMetadatas) >= limit {
break
Expand Down

0 comments on commit b8c1514

Please sign in to comment.