Skip to content

Commit

Permalink
Merge pull request #1420 from 0chain/test/store-error
Browse files Browse the repository at this point in the history
Fix file not found in temp dir under load
  • Loading branch information
dabasov committed May 15, 2024
2 parents 5617353 + 8cebc6b commit 3bcb469
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
10 changes: 2 additions & 8 deletions code/go/0chain.net/blobbercore/filestore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (fs *FileStore) WriteFile(allocID, conID string, fileData *FileInputData, i
_ = os.Remove(tempFilePath)
return nil, common.NewError("file_size_mismatch", "File size is greater than expected")
}
logging.Logger.Info("temp_file_write: ", zap.String("filePath", fileData.Path), zap.Int64("currentSize", currentSize), zap.Int64("initialSize", initialSize), zap.Int64("writtenSize", writtenSize), zap.Int64("offset", fileData.UploadOffset), zap.Bool("ChunkUploaded", fileRef.ChunkUploaded))
logging.Logger.Info("temp_file_write: ", zap.String("filePath", fileData.Path), zap.Int64("currentSize", currentSize), zap.Int64("initialSize", initialSize), zap.Int64("writtenSize", writtenSize), zap.Int64("offset", fileData.UploadOffset), zap.String("tempFilePath", tempFilePath))
fileRef.Size = writtenSize
fileRef.Name = fileData.Name
fileRef.Path = fileData.Path
Expand Down Expand Up @@ -182,12 +182,6 @@ func (fs *FileStore) DeletePreCommitDir(allocID string) error {
if err != nil {
return common.NewError("pre_commit_dir_deletion_error", err.Error())
}
tempDir := fs.getAllocTempDir(allocID)
err = os.RemoveAll(tempDir)
if err != nil {
return common.NewError("temp_dir_deletion_error", err.Error())
}

return nil
}

Expand Down Expand Up @@ -398,7 +392,7 @@ func (fs *FileStore) DeleteTempFile(allocID, conID string, fd *FileInputData) er
return common.NewError("invalid_allocation_id", "Allocation id cannot be empty")
}
fileObjectPath := fs.getTempPathForFile(allocID, fd.Name, encryption.Hash(fd.Path), conID)

logging.Logger.Info("deleting_temp_file", zap.String("fileObjectPath", fileObjectPath), zap.String("allocation_id", allocID), zap.String("connection_id", conID))
finfo, err := os.Stat(fileObjectPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ func (c *CommitHasher) Start(ctx context.Context, connID, allocID, fileName, fil
tempFilePath := GetFileStore().GetTempFilePath(allocID, connID, fileName, filePathHash)
f, err := os.Open(tempFilePath)
if err != nil {
logging.Logger.Error("hasher_open", zap.Error(err), zap.String("tempFilePath", tempFilePath))
c.hashErr = err
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
return nil, common.NewError("chain_length_exceeded", "Chain length exceeded")
}

err = writemarkerEntity.VerifyMarker(ctx, allocationObj, connectionObj)
err = writemarkerEntity.VerifyMarker(ctx, allocationObj, connectionObj, latestWriteMarkerEntity)
if err != nil {
result.AllocationRoot = allocationObj.AllocationRoot
result.ErrorMessage = "Verification of write marker failed: " + err.Error()
Expand Down
12 changes: 8 additions & 4 deletions code/go/0chain.net/blobbercore/writemarker/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ type CommitConnection struct {
ChainData []byte `json:"chain_data"`
}

const timeGap = 180

// VerifyMarker verify WriteMarker's hash and check allocation_root if it is unique
func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *allocation.Allocation, co *allocation.AllocationChangeCollector) error {
func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *allocation.Allocation, co *allocation.AllocationChangeCollector, latestWM *WriteMarkerEntity) error {
if wme == nil {
return common.NewError("invalid_write_marker", "No Write Marker was found")
}
Expand Down Expand Up @@ -92,9 +94,11 @@ func (wme *WriteMarkerEntity) VerifyMarker(ctx context.Context, dbAllocation *al
}

currTime := common.Now()
// blobber clock is allowed to be 60 seconds behind the current time
if wme.WM.Timestamp > currTime+60 {
return common.NewError("write_marker_validation_failed", "Write Marker timestamp is in the future")
// blobber clock is allowed to be 180 seconds behind the current time
if wme.WM.Timestamp > currTime+timeGap {
if latestWM == nil || wme.WM.Timestamp > latestWM.WM.Timestamp+timeGap {
return common.NewError("write_marker_validation_failed", "Write Marker timestamp is in the future")
}
}

hashData := wme.WM.GetHashData()
Expand Down

0 comments on commit 3bcb469

Please sign in to comment.