Skip to content

Commit

Permalink
Merge pull request #1473 from 0chain/feat/init-free
Browse files Browse the repository at this point in the history
Init free read
  • Loading branch information
dabasov authored May 5, 2024
2 parents a676513 + a82bd51 commit f83a9d8
Showing 1 changed file with 12 additions and 6 deletions.
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

0 comments on commit f83a9d8

Please sign in to comment.