Skip to content

Commit 6b68d45

Browse files
authored
Merge pull request #1549 from 0chain/fix/notfound-ref
fix ref not found and add log for copy error
2 parents 3c4e283 + accd6d3 commit 6b68d45

File tree

9 files changed

+30
-9
lines changed

9 files changed

+30
-9
lines changed

zboxcore/allocationchange/deletefile.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type DeleteFileChange struct {
1313
FileMetaRef fileref.RefEntity
1414
}
1515

16+
var ErrRefNotFound = errors.New("ref_not_found", "Ref not found")
17+
1618
func (ch *DeleteFileChange) ProcessChange(rootRef *fileref.Ref, _ map[string]string) (err error) {
1719

1820
if ch.FileMetaRef.GetPath() == "/" {
@@ -39,7 +41,7 @@ func (ch *DeleteFileChange) ProcessChange(rootRef *fileref.Ref, _ map[string]str
3941
}
4042

4143
if !found {
42-
err = errors.New("invalid_reference_path", "Invalid reference path from the blobber")
44+
err = ErrRefNotFound
4345
return
4446
}
4547
}

zboxcore/sdk/allocation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul
946946
operation, newConnectionID, err = NewUploadOperation(mo.ctx, op.Workdir, mo.allocationObj, mo.connectionID, op.FileMeta, op.FileReader, true, op.IsWebstreaming, op.IsRepair, op.DownloadFile, op.StreamUpload, op.Opts...)
947947

948948
case constants.FileOperationCreateDir:
949-
operation = NewDirOperation(op.RemotePath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx)
949+
operation = NewDirOperation(op.RemotePath, op.FileMeta.CustomMeta, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx)
950950

951951
default:
952952
return errors.New("invalid_operation", "Operation is not valid")

zboxcore/sdk/chunked_upload_form_builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (b *chunkedUploadFormBuilder) Build(
8888
Size: shardSize,
8989
EncryptedKeyPoint: encryptedKeyPoint,
9090
EncryptedKey: encryptedKey,
91+
CustomMeta: fileMeta.CustomMeta,
9192
}
9293

9394
for i := 0; i < numBodies; i++ {

zboxcore/sdk/chunked_upload_model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ type FileMeta struct {
119119
RemoteName string
120120
// RemotePath remote path
121121
RemotePath string
122+
// CustomMeta custom meta data
123+
CustomMeta string
122124
}
123125

124126
// FileID generate id of progress on local cache

zboxcore/sdk/commitworker.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,13 @@ func (commitreq *CommitRequest) processCommit() {
193193
for _, change := range commitreq.changes {
194194
err = change.ProcessChange(rootRef, fileIDMeta)
195195
if err != nil {
196-
commitreq.result = ErrorCommitResult(err.Error())
197-
return
196+
if !errors.Is(err, allocationchange.ErrRefNotFound) {
197+
commitreq.result = ErrorCommitResult(err.Error())
198+
return
199+
}
200+
} else {
201+
size += change.GetSize()
198202
}
199-
size += change.GetSize()
200203
}
201204
rootRef.CalculateHash()
202205
var chainHash string

zboxcore/sdk/copyworker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (req *CopyRequest) ProcessWithBlobbers() ([]fileref.RefEntity, []error) {
178178
refEntity, err := req.copyBlobberObject(req.blobbers[blobberIdx], blobberIdx)
179179
if err != nil {
180180
blobberErrors[blobberIdx] = err
181-
l.Logger.Error(err.Error())
181+
l.Logger.Debug(err.Error())
182182
return
183183
}
184184
objectTreeRefs[blobberIdx] = refEntity
@@ -324,6 +324,7 @@ func (co *CopyOperation) Process(allocObj *Allocation, connectionID string) ([]f
324324
objectTreeRefs, blobberErrors := cR.ProcessWithBlobbers()
325325

326326
if !cR.isConsensusOk() {
327+
l.Logger.Error("copy failed: ", cR.remotefilepath, cR.destPath)
327328
err := zboxutil.MajorError(blobberErrors)
328329
if err != nil {
329330
return nil, cR.copyMask, errors.New("copy_failed", fmt.Sprintf("Copy failed. %s", err.Error()))

zboxcore/sdk/dirworker.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type DirRequest struct {
4343
connectionID string
4444
timestamp int64
4545
alreadyExists map[uint64]bool
46+
customMeta string
4647
Consensus
4748
}
4849

@@ -177,6 +178,13 @@ func (req *DirRequest) createDirInBlobber(blobber *blockchain.StorageNode, pos u
177178
return err, false
178179
}
179180

181+
if req.customMeta != "" {
182+
err = formWriter.WriteField("custom_meta", req.customMeta)
183+
if err != nil {
184+
return err, false
185+
}
186+
}
187+
180188
formWriter.Close()
181189
httpreq, err := zboxutil.NewCreateDirRequest(blobber.Baseurl, req.allocationID, req.allocationTx, body)
182190
if err != nil {
@@ -238,12 +246,12 @@ func (req *DirRequest) createDirInBlobber(blobber *blockchain.StorageNode, pos u
238246
latestStatusCode = resp.StatusCode
239247

240248
msg = string(respBody)
241-
l.Logger.Error(blobber.Baseurl, " Response: ", msg)
242249
if strings.Contains(msg, DirectoryExists) {
243250
req.Consensus.Done()
244251
alreadyExists = true
245252
return
246253
}
254+
l.Logger.Error(blobber.Baseurl, " Response: ", msg)
247255

248256
err = errors.New("response_error", msg)
249257
return
@@ -271,6 +279,7 @@ type DirOperation struct {
271279
ctxCncl context.CancelFunc
272280
dirMask zboxutil.Uint128
273281
maskMU *sync.Mutex
282+
customMeta string
274283
alreadyExists map[uint64]bool
275284

276285
Consensus
@@ -290,6 +299,7 @@ func (dirOp *DirOperation) Process(allocObj *Allocation, connectionID string) ([
290299
mu: dirOp.maskMU,
291300
wg: &sync.WaitGroup{},
292301
alreadyExists: make(map[uint64]bool),
302+
customMeta: dirOp.customMeta,
293303
}
294304
dR.Consensus = Consensus{
295305
RWMutex: &sync.RWMutex{},
@@ -347,13 +357,14 @@ func (dirOp *DirOperation) Error(allocObj *Allocation, consensus int, err error)
347357

348358
}
349359

350-
func NewDirOperation(remotePath string, dirMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh int, fullConsensus int, ctx context.Context) *DirOperation {
360+
func NewDirOperation(remotePath, customMeta string, dirMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh int, fullConsensus int, ctx context.Context) *DirOperation {
351361
dirOp := &DirOperation{}
352362
dirOp.remotePath = zboxutil.RemoteClean(remotePath)
353363
dirOp.dirMask = dirMask
354364
dirOp.maskMU = maskMU
355365
dirOp.consensusThresh = consensusTh
356366
dirOp.fullconsensus = fullConsensus
367+
dirOp.customMeta = customMeta
357368
dirOp.ctx, dirOp.ctxCncl = context.WithCancel(ctx)
358369
dirOp.alreadyExists = make(map[uint64]bool)
359370
return dirOp

zboxcore/sdk/downloadworker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse)
12071207
fRef.ActualFileHashSignature+fRef.ValidationRoot,
12081208
)
12091209
if err != nil {
1210-
l.Logger.Error(err)
1210+
l.Logger.Error(err, "allocOwnerPubKey: ", req.allocOwnerPubKey, " validationRootSignature: ", fRef.ValidationRootSignature, " actualFileHashSignature: ", fRef.ActualFileHashSignature, " validationRoot: ", fRef.ValidationRoot)
12111211
continue
12121212
}
12131213
if !isValid {

zboxcore/sdk/filerefsworker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ type SimilarField struct {
227227
MimeType string `json:"mimetype"`
228228
ActualThumbnailSize int64 `json:"actual_thumbnail_size"`
229229
ActualThumbnailHash string `json:"actual_thumbnail_hash"`
230+
CustomMeta string `json:"custom_meta"`
230231
}
231232

232233
type RecentlyAddedRefRequest struct {

0 commit comments

Comments
 (0)