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

Hotfix repair after update #1357

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions zboxcore/sdk/allocation_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,32 +647,32 @@ func TestAllocation_RepairFile(t *testing.T) {
ClientKey: mockClientKey,
}

// setupHttpResponses := func(t *testing.T, testName string, numBlobbers, numCorrect int) {
// require.True(t, numBlobbers >= numCorrect)
// for i := 0; i < numBlobbers; i++ {
// var hash string
// if i < numCorrect {
// hash = mockActualHash
// }
// frName := mockFileRefName + strconv.Itoa(i)
// url := "http://TestAllocation_RepairFile" + testName + mockBlobberUrl + strconv.Itoa(i) + "/v1/file/meta"
// mockClient.On("Do", mock.MatchedBy(func(req *http.Request) bool {
// return strings.HasPrefix(req.URL.String(), url)
// })).Return(&http.Response{
// StatusCode: http.StatusOK,
// Body: func(fileRefName, hash string) io.ReadCloser {
// jsonFR, err := json.Marshal(&fileref.FileRef{
// ActualFileHash: hash,
// Ref: fileref.Ref{
// Name: fileRefName,
// },
// })
// require.NoError(t, err)
// return ioutil.NopCloser(bytes.NewReader([]byte(jsonFR)))
// }(frName, hash),
// }, nil)
// }
// }
setupHttpResponses := func(t *testing.T, testName string, numBlobbers, numCorrect int) {
require.True(t, numBlobbers >= numCorrect)
for i := 0; i < numBlobbers; i++ {
var hash string
if i < numCorrect {
hash = mockActualHash
}
frName := mockFileRefName + strconv.Itoa(i)
url := "http://TestAllocation_RepairFile" + testName + mockBlobberUrl + strconv.Itoa(i) + "/v1/file/meta"
mockClient.On("Do", mock.MatchedBy(func(req *http.Request) bool {
return strings.HasPrefix(req.URL.String(), url)
})).Return(&http.Response{
StatusCode: http.StatusOK,
Body: func(fileRefName, hash string) io.ReadCloser {
jsonFR, err := json.Marshal(&fileref.FileRef{
ActualFileHash: hash,
Ref: fileref.Ref{
Name: fileRefName,
},
})
require.NoError(t, err)
return ioutil.NopCloser(bytes.NewReader([]byte(jsonFR)))
}(frName, hash),
}, nil)
}
}

setupHttpResponsesWithUpload := func(t *testing.T, testName string, numBlobbers, numCorrect int) {
require.True(t, numBlobbers >= numCorrect)
Expand Down Expand Up @@ -813,17 +813,17 @@ func TestAllocation_RepairFile(t *testing.T) {
wantRepair bool
errMsg string
}{
// {
// name: "Test_Repair_Not_Required_Failed",
// parameters: parameters{
// localPath: mockLocalPath,
// remotePath: "/",
// },
// numBlobbers: 4,
// numCorrect: 4,
// setup: setupHttpResponses,
// wantRepair: false,
// },
{
name: "Test_Repair_Not_Required_Failed",
parameters: parameters{
localPath: mockLocalPath,
remotePath: "/",
},
numBlobbers: 4,
numCorrect: 4,
setup: setupHttpResponses,
wantRepair: false,
},
{
name: "Test_Repair_Required_Success",
parameters: parameters{
Expand Down
5 changes: 4 additions & 1 deletion zboxcore/sdk/listworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ func (req *ListRequest) GetListFromBlobbers() (*ListResult, error) {
if req.forRepair {
for _, child := range childResultMap {
if child.consensus < child.fullconsensus {
result.Children = append(result.Children, child)
if _, ok := selected[child.LookupHash]; !ok {
result.Children = append(result.Children, child)
selected[child.LookupHash] = child
}
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions zboxcore/sdk/repairworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ func (r *RepairRequest) iterateDir(a *Allocation, dir *ListResult) []OperationRe
}
case fileref.FILE:
// this returns op object and mask
op := r.repairFile(a, dir)
if op != nil {
ops = append(ops, *op)
repairOps := r.repairFile(a, dir)
if repairOps != nil {
ops = append(ops, repairOps...)
}

default:
Expand All @@ -139,8 +139,8 @@ func (r *RepairRequest) iterateDir(a *Allocation, dir *ListResult) []OperationRe
return ops
}

func (r *RepairRequest) repairFile(a *Allocation, file *ListResult) *OperationRequest {
var op *OperationRequest
func (r *RepairRequest) repairFile(a *Allocation, file *ListResult) []OperationRequest {
ops := make([]OperationRequest, 0)
if r.checkForCancel(a) {
return nil
}
Expand All @@ -162,16 +162,16 @@ func (r *RepairRequest) repairFile(a *Allocation, file *ListResult) *OperationRe

if deleteMask.CountOnes() > 0 {
l.Logger.Info("Deleting minority shards for the path :", zap.Any("path", file.Path))
// consensus := deleteMask.CountOnes()
// err := a.deleteFile(file.Path, 0, consensus, deleteMask)
op = &OperationRequest{
op := OperationRequest{
OperationType: constants.FileOperationDelete,
RemotePath: file.Path,
Mask: &deleteMask,
}
ops = append(ops, op)
}
wg.Add(1)
localPath := r.getLocalPath(file)
var op *OperationRequest
if !checkFileExists(localPath) {
if r.checkForCancel(a) {
return nil
Expand All @@ -190,27 +190,29 @@ func (r *RepairRequest) repairFile(a *Allocation, file *ListResult) *OperationRe
}
op = a.RepairFile(f, file.Path, statusCB, found, ref)
}

ops = append(ops, *op)
if r.checkForCancel(a) {
return nil
}
} else {
l.Logger.Info("Repair by delete", zap.Any("path", file.Path))
op = &OperationRequest{
op := OperationRequest{
OperationType: constants.FileOperationDelete,
RemotePath: file.Path,
Mask: &found,
}
ops = append(ops, op)
}
} else if deleteMask.CountOnes() > 0 {
l.Logger.Info("Deleting minority shards for the path :", zap.Any("path", file.Path))
op = &OperationRequest{
op := OperationRequest{
OperationType: constants.FileOperationDelete,
RemotePath: file.Path,
Mask: &deleteMask,
}
ops = append(ops, op)
}
return op
return ops
}

func (r *RepairRequest) repairOperation(a *Allocation, ops []OperationRequest) {
Expand Down
Loading