Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init free read #1473

Merged
merged 3 commits into from
May 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions zboxcore/sdk/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ type Allocation struct {
repairRequestInProgress *RepairRequest
initialized bool
checkStatus bool
readFree bool
// conseususes
consensusThreshold int
fullconsensus int
Expand Down Expand Up @@ -315,6 +316,15 @@ func (a *Allocation) InitAllocation() {
for _, blobber := range a.Blobbers {
zboxutil.SetHostClient(blobber.ID, blobber.Baseurl)
}
a.readFree = true
if a.ReadPriceRange.Max > 0 {
for _, blobberDetail := range a.BlobberDetails {
if blobberDetail.Terms.ReadPrice > 0 {
a.readFree = false
break
}
}
}
a.startWorker(a.ctx)
InitCommitWorker(a.Blobbers)
InitBlockDownloader(a.Blobbers, downloadWorkerCount)
Expand Down Expand Up @@ -1170,17 +1180,13 @@ func (a *Allocation) processReadMarker(drs []*DownloadRequest) {
blobberMap := make(map[uint64]int64)
mpLock := sync.Mutex{}
wg := sync.WaitGroup{}
var isReadFree bool
if a.ReadPriceRange.Max == 0 && a.ReadPriceRange.Min == 0 {
isReadFree = true
}
now := time.Now()

for _, dr := range drs {
wg.Add(1)
go func(dr *DownloadRequest) {
defer wg.Done()
if isReadFree {
if a.readFree {
dr.freeRead = true
}
dr.processDownloadRequest()
Expand All @@ -1199,7 +1205,7 @@ func (a *Allocation) processReadMarker(drs []*DownloadRequest) {
elapsedProcessDownloadRequest := time.Since(now)

// Do not send readmarkers for free reads
if isReadFree {
if a.readFree {
for _, dr := range drs {
if dr.skip {
continue
Expand Down