Skip to content

Commit

Permalink
*: migrate to SEARCH with strict equality comparator
Browse files Browse the repository at this point in the history
Close #3670

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
  • Loading branch information
AliceInHunterland committed Nov 21, 2024
1 parent e03e902 commit f9bed27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 14 additions & 5 deletions cli/util/upload_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const (
uploadBatchSize = 10000
// Number of objects to search in a batch.
// If it is larger than uploadBatchSize, it may lead to many duplicate uploads.
searchBatchSize = uploadBatchSize
// We need to search with EQ filter to avoid partially-completed SEARCH responses.
searchBatchSize = 1
// Size of object ID.
oidSize = sha256.Size
)
Expand Down Expand Up @@ -215,8 +216,12 @@ func fetchLatestMissingBlockIndex(ctx context.Context, p *pool.Pool, containerID

prm := client.PrmObjectSearch{}
filters := object.NewSearchFilters()
filters.AddFilter(attributeKey, fmt.Sprintf("%d", startIndex), object.MatchNumGE)
filters.AddFilter(attributeKey, fmt.Sprintf("%d", endIndex), object.MatchNumLT)
if endIndex == startIndex+1 {
filters.AddFilter(attributeKey, fmt.Sprintf("%d", startIndex), object.MatchStringEqual)
} else {
filters.AddFilter(attributeKey, fmt.Sprintf("%d", startIndex), object.MatchNumGE)
filters.AddFilter(attributeKey, fmt.Sprintf("%d", endIndex), object.MatchNumLT)
}

Check warning on line 224 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L219-L224

Added lines #L219 - L224 were not covered by tests
prm.SetFilters(filters)
var (
objectIDs []oid.ID
Expand Down Expand Up @@ -529,8 +534,12 @@ func searchObjects(ctx context.Context, p *pool.Pool, containerID cid.ID, accoun
if len(additionalFilters) != 0 {
filters = additionalFilters[0]
}
filters.AddFilter(blockAttributeKey, fmt.Sprintf("%d", start), object.MatchNumGE)
filters.AddFilter(blockAttributeKey, fmt.Sprintf("%d", end), object.MatchNumLT)
if end == start+1 {
filters.AddFilter(blockAttributeKey, fmt.Sprintf("%d", start), object.MatchStringEqual)
} else {
filters.AddFilter(blockAttributeKey, fmt.Sprintf("%d", start), object.MatchNumGE)
filters.AddFilter(blockAttributeKey, fmt.Sprintf("%d", end), object.MatchNumLT)
}

Check warning on line 542 in cli/util/upload_bin.go

View check run for this annotation

Codecov / codecov/patch

cli/util/upload_bin.go#L534-L542

Added lines #L534 - L542 were not covered by tests
prm.SetFilters(filters)

var objIDs []oid.ID
Expand Down
10 changes: 8 additions & 2 deletions pkg/services/blockfetcher/blockfetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func (bfs *Service) oidDownloader() {

var err error
if bfs.cfg.SkipIndexFilesSearch {
//We need to search with EQ filter to avoid partially-completed SEARCH responses.
bfs.cfg.OIDBatchSize = 1

Check warning on line 183 in pkg/services/blockfetcher/blockfetcher.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/blockfetcher/blockfetcher.go#L182-L183

Added lines #L182 - L183 were not covered by tests
err = bfs.fetchOIDsBySearch()
} else {
err = bfs.fetchOIDsFromIndexFiles()
Expand Down Expand Up @@ -351,8 +353,12 @@ func (bfs *Service) fetchOIDsBySearch() error {
default:
prm := client.PrmObjectSearch{}
filters := object.NewSearchFilters()
filters.AddFilter(bfs.cfg.BlockAttribute, fmt.Sprintf("%d", startIndex), object.MatchNumGE)
filters.AddFilter(bfs.cfg.BlockAttribute, fmt.Sprintf("%d", startIndex+batchSize-1), object.MatchNumLE)
if startIndex == startIndex+batchSize-1 {
filters.AddFilter(bfs.cfg.BlockAttribute, fmt.Sprintf("%d", startIndex), object.MatchStringEqual)
} else {
filters.AddFilter(bfs.cfg.BlockAttribute, fmt.Sprintf("%d", startIndex), object.MatchNumGE)
filters.AddFilter(bfs.cfg.BlockAttribute, fmt.Sprintf("%d", startIndex+batchSize-1), object.MatchNumLE)
}

Check warning on line 361 in pkg/services/blockfetcher/blockfetcher.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/blockfetcher/blockfetcher.go#L356-L361

Added lines #L356 - L361 were not covered by tests
prm.SetFilters(filters)
ctx, cancel := context.WithTimeout(bfs.ctx, bfs.cfg.Timeout)
blockOids, err := bfs.objectSearch(ctx, prm)
Expand Down

0 comments on commit f9bed27

Please sign in to comment.