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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create dir in repair #1262

Merged
merged 2 commits into from Oct 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions zboxcore/sdk/allocation.go
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -1616,6 +1617,44 @@ func (a *Allocation) deleteFile(path string, threshConsensus, fullConsensus int,
return err
}

func (a *Allocation) createDir(remotePath string, threshConsensus, fullConsensus int, mask zboxutil.Uint128) error {
if !a.isInitialized() {
return notInitialized
}

if remotePath == "" {
return errors.New("invalid_name", "Invalid name for dir")
}

if !path.IsAbs(remotePath) {
return errors.New("invalid_path", "Path is not absolute")
}

remotePath = zboxutil.RemoteClean(remotePath)
timestamp := int64(common.Now())
req := DirRequest{
allocationObj: a,
allocationID: a.ID,
allocationTx: a.Tx,
blobbers: a.Blobbers,
mu: &sync.Mutex{},
dirMask: mask,
connectionID: zboxutil.NewConnectionId(),
remotePath: remotePath,
wg: &sync.WaitGroup{},
timestamp: timestamp,
Consensus: Consensus{
RWMutex: &sync.RWMutex{},
consensusThresh: threshConsensus,
fullconsensus: fullConsensus,
},
}
req.ctx, req.ctxCncl = context.WithCancel(a.ctx)

err := req.ProcessDir(a)
return err
}

func (a *Allocation) GetAuthTicketForShare(
path, filename, referenceType, refereeClientID string) (string, error) {

Expand Down
19 changes: 0 additions & 19 deletions zboxcore/sdk/dirworker.go
Expand Up @@ -96,25 +96,6 @@ func (req *DirRequest) ProcessDir(a *Allocation) error {
}
defer writeMarkerMU.Unlock(req.ctx, req.dirMask,
a.Blobbers, time.Minute, req.connectionID) //nolint: errcheck
//Check if the allocation is to be repaired or rolled back
status, err := req.allocationObj.CheckAllocStatus()
l.Logger.Info("Allocation status: ", status)
if err != nil {
l.Logger.Error("Error checking allocation status: ", err)
return fmt.Errorf("directory creation failed: %s", err.Error())
}

if status == Repair {
l.Logger.Info("Repairing allocation")
//TODO: Need status callback to call repair allocation
// err = req.allocationObj.RepairAlloc()
// if err != nil {
// return err
// }
}
if status != Commit {
return ErrRetryOperation
}

return req.commitRequest(existingDirCount)
}
Expand Down
15 changes: 15 additions & 0 deletions zboxcore/sdk/repairworker.go
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/0chain/gosdk/core/sys"
"github.com/0chain/gosdk/zboxcore/fileref"
l "github.com/0chain/gosdk/zboxcore/logger"
"github.com/0chain/gosdk/zboxcore/zboxutil"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -88,6 +89,20 @@ func (r *RepairRequest) iterateDir(a *Allocation, dir *ListResult) {
err := a.deleteFile(dir.Path, 0, consensus, dir.deleteMask)
if err != nil {
l.Logger.Error("repair_file_failed", zap.Error(err))
if r.statusCB != nil {
r.statusCB.Error(a.ID, dir.Path, OpRepair, err)
}
return
}
r.filesRepaired++
} else if consensus < len(a.Blobbers) {
createMask := dir.deleteMask.Not().And(zboxutil.NewUint128(1).Lsh(uint64(len(a.Blobbers))).Sub64(1))
err := a.createDir(dir.Path, 0, createMask.CountOnes(), createMask)
if err != nil {
l.Logger.Error("repair_file_failed", zap.Error(err))
if r.statusCB != nil {
r.statusCB.Error(a.ID, dir.Path, OpRepair, err)
}
return
}
r.filesRepaired++
Expand Down