Skip to content

Commit

Permalink
Merge pull request #1664 from 0chain/hotfix/repair-change
Browse files Browse the repository at this point in the history
Repair fix
  • Loading branch information
dabasov authored Nov 7, 2024
2 parents 4cb7621 + 2ae83de commit 2383cd8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
14 changes: 13 additions & 1 deletion wasmsdk/blobber.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,19 @@ func repairAllocation(allocationID, callbackFuncName string) error {
return err
}
wg.Wait()
return statusBar.err
if statusBar.err != nil {
fmt.Println("Error in repair allocation: ", statusBar.err)
return statusBar.err
}
status, _, err := alloc.CheckAllocStatus()
if err != nil {
return err
}
if status == sdk.Repair || status == sdk.Broken {
fmt.Println("allocation repair failed")
return errors.New("allocation repair failed")
}
return nil
}

// checkAllocStatus check the status of the allocation, either it is ok, needs repair or broken
Expand Down
1 change: 1 addition & 0 deletions zboxcore/sdk/chunked_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ func (su *ChunkedUpload) process() error {
su.statusCallback.Started(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, int(su.fileMeta.ActualSize)+int(su.fileMeta.ActualThumbnailSize))
}
su.startProcessor()
defer su.chunkReader.Release()
defer su.chunkReader.Close()
defer su.ctxCncl(nil)
for {
Expand Down
7 changes: 6 additions & 1 deletion zboxcore/sdk/chunked_upload_chunk_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type ChunkedUploadChunkReader interface {
GetFileHash() (string, error)
//Reset reset offset
Reset()
//Release Buffer
Release()
}

// chunkedUploadChunkReader read chunk bytes from io.Reader. see detail on https://github.com/0chain/blobber/wiki/Protocols#what-is-fixedmerkletree
Expand Down Expand Up @@ -315,7 +317,6 @@ func (r *chunkedUploadChunkReader) Close() {
r.closeOnce.Do(func() {
close(r.hasherDataChan)
r.hasherWG.Wait()
uploadPool.Put(r.fileShardsDataBuffer)
})

}
Expand All @@ -328,6 +329,10 @@ func (r *chunkedUploadChunkReader) GetFileHash() (string, error) {
return r.hasher.GetFileHash()
}

func (r *chunkedUploadChunkReader) Release() {
uploadPool.Put(r.fileShardsDataBuffer)
}

func (r *chunkedUploadChunkReader) hashData() {
defer r.hasherWG.Done()
for data := range r.hasherDataChan {
Expand Down
3 changes: 2 additions & 1 deletion zboxcore/sdk/downloadworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func (req *DownloadRequest) processDownload() {
req.bufferMap[blobberIdx] = zboxutil.NewDownloadBufferWithChan(sz, bufBlocks, req.effectiveBlockSize)
} else {
bufMask := zboxutil.NewDownloadBufferWithMask(sz, bufBlocks, req.effectiveBlockSize)
bufMask.SetNumBlocks(int(numBlocks))
bufMask.SetNumBlocks(int(bufBlocks))
req.bufferMap[blobberIdx] = bufMask
}
}
Expand Down Expand Up @@ -996,6 +996,7 @@ func (req *DownloadRequest) errorCB(err error, remotePathCB string) {
return
}
req.skip = true
logger.Logger.Error("Download failed: ", err, " remotefilepath: ", remotePathCB)
if req.localFilePath != "" {
if info, err := req.fileHandler.Stat(); err == nil && info.Size() == 0 {
os.Remove(req.localFilePath) //nolint: errcheck
Expand Down
4 changes: 4 additions & 0 deletions zboxcore/sdk/repairworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func (r *RepairRequest) processRepair(ctx context.Context, a *Allocation) {
SetSingleClietnMode(true)
defer SetSingleClietnMode(false)
}
if shouldSaveProgress {
SetSaveProgress(false)
defer SetSaveProgress(true)
}
r.iterateDir(a, r.listDir)
if r.statusCB != nil {
r.statusCB.RepairCompleted(r.filesRepaired)
Expand Down

0 comments on commit 2383cd8

Please sign in to comment.