mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
XL/PutObject: Calculate size if not provided by the client and update xl.json with the correct size. (#1844)
This commit is contained in:
parent
fb95c1fad3
commit
b00ac40c35
@ -28,7 +28,7 @@ import (
|
|||||||
// erasureCreateFile - writes an entire stream by erasure coding to
|
// erasureCreateFile - writes an entire stream by erasure coding to
|
||||||
// all the disks, writes also calculate individual block's checksum
|
// all the disks, writes also calculate individual block's checksum
|
||||||
// for future bit-rot protection.
|
// for future bit-rot protection.
|
||||||
func erasureCreateFile(disks []StorageAPI, volume string, path string, partName string, data io.Reader, eInfos []erasureInfo) (newEInfos []erasureInfo, err error) {
|
func erasureCreateFile(disks []StorageAPI, volume string, path string, partName string, data io.Reader, eInfos []erasureInfo) (newEInfos []erasureInfo, size int64, err error) {
|
||||||
// Allocated blockSized buffer for reading.
|
// Allocated blockSized buffer for reading.
|
||||||
buf := make([]byte, blockSizeV1)
|
buf := make([]byte, blockSizeV1)
|
||||||
hashWriters := newHashWriters(len(disks))
|
hashWriters := newHashWriters(len(disks))
|
||||||
@ -44,17 +44,18 @@ func erasureCreateFile(disks []StorageAPI, volume string, path string, partName
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err != nil && err != io.ErrUnexpectedEOF {
|
if err != nil && err != io.ErrUnexpectedEOF {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
size += int64(n)
|
||||||
var blocks [][]byte
|
var blocks [][]byte
|
||||||
// Returns encoded blocks.
|
// Returns encoded blocks.
|
||||||
blocks, err = encodeData(buf[:n], eInfo.DataBlocks, eInfo.ParityBlocks)
|
blocks, err = encodeData(buf[:n], eInfo.DataBlocks, eInfo.ParityBlocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
err = appendFile(disks, volume, path, blocks, eInfo.Distribution, hashWriters)
|
err = appendFile(disks, volume, path, blocks, eInfo.Distribution, hashWriters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ func erasureCreateFile(disks []StorageAPI, volume string, path string, partName
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return newEInfos.
|
// Return newEInfos.
|
||||||
return newEInfos, nil
|
return newEInfos, size, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// encodeData - encodes incoming data buffer into
|
// encodeData - encodes incoming data buffer into
|
||||||
|
@ -337,11 +337,13 @@ func (xl xlObjects) putObjectPart(bucket string, object string, uploadID string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Erasure code data and write across all disks.
|
// Erasure code data and write across all disks.
|
||||||
newEInfos, err := erasureCreateFile(onlineDisks, minioMetaBucket, tmpPartPath, partSuffix, teeReader, eInfos)
|
newEInfos, n, err := erasureCreateFile(onlineDisks, minioMetaBucket, tmpPartPath, partSuffix, teeReader, eInfos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", toObjectErr(err, minioMetaBucket, tmpPartPath)
|
return "", toObjectErr(err, minioMetaBucket, tmpPartPath)
|
||||||
}
|
}
|
||||||
|
if size == -1 {
|
||||||
|
size = n
|
||||||
|
}
|
||||||
// Calculate new md5sum.
|
// Calculate new md5sum.
|
||||||
newMD5Hex := hex.EncodeToString(md5Writer.Sum(nil))
|
newMD5Hex := hex.EncodeToString(md5Writer.Sum(nil))
|
||||||
if md5Hex != "" {
|
if md5Hex != "" {
|
||||||
|
@ -296,11 +296,13 @@ func (xl xlObjects) PutObject(bucket string, object string, size int64, data io.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Erasure code and write across all disks.
|
// Erasure code and write across all disks.
|
||||||
newEInfos, err := erasureCreateFile(onlineDisks, minioMetaBucket, tempErasureObj, "object1", teeReader, eInfos)
|
newEInfos, n, err := erasureCreateFile(onlineDisks, minioMetaBucket, tempErasureObj, "object1", teeReader, eInfos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", toObjectErr(err, minioMetaBucket, tempErasureObj)
|
return "", toObjectErr(err, minioMetaBucket, tempErasureObj)
|
||||||
}
|
}
|
||||||
|
if size == -1 {
|
||||||
|
size = n
|
||||||
|
}
|
||||||
// Save additional erasureMetadata.
|
// Save additional erasureMetadata.
|
||||||
modTime := time.Now().UTC()
|
modTime := time.Now().UTC()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user