mirror of
https://github.com/minio/minio.git
synced 2025-11-22 10:37:42 -05:00
xl: Change fileMetadata to xlMetadata. (#1404)
Finalized backend format
```
{
"version": "1.0.0",
"stat": {
"size": 24256,
"modTime": "2016-04-28T00:11:37.843Z"
},
"erasure": {
"data": 5,
"parity": 5,
"blockSize": 4194304
],
"minio": {
"release": "RELEASE.2016-04-28T00-09-47Z"
}
}
```
This commit is contained in:
committed by
Anand Babu (AB) Periasamy
parent
41b35cff7b
commit
a1a667ae5d
@@ -17,7 +17,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
slashpath "path"
|
||||
"path/filepath"
|
||||
@@ -37,27 +36,11 @@ func highestInt(intSlice []int64) (highestInteger int64) {
|
||||
}
|
||||
|
||||
// Extracts file versions from partsMetadata slice and returns version slice.
|
||||
func listFileVersions(partsMetadata []fileMetadata, errs []error) (versions []int64, err error) {
|
||||
func listFileVersions(partsMetadata []xlMetaV1, errs []error) (versions []int64, err error) {
|
||||
versions = make([]int64, len(partsMetadata))
|
||||
for index, metadata := range partsMetadata {
|
||||
if errs[index] == nil {
|
||||
var version int64
|
||||
version, err = metadata.GetFileVersion()
|
||||
if err == errMetadataKeyNotExist {
|
||||
log.WithFields(logrus.Fields{
|
||||
"metadata": metadata,
|
||||
}).Errorf("Missing 'file.version', %s", errMetadataKeyNotExist)
|
||||
versions[index] = 0
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
log.WithFields(logrus.Fields{
|
||||
"metadata": metadata,
|
||||
}).Errorf("'file.version' decoding failed with %s", err)
|
||||
// Unexpected, return error.
|
||||
return nil, err
|
||||
}
|
||||
versions[index] = version
|
||||
versions[index] = metadata.Stat.Version
|
||||
} else {
|
||||
versions[index] = -1
|
||||
}
|
||||
@@ -67,10 +50,10 @@ func listFileVersions(partsMetadata []fileMetadata, errs []error) (versions []in
|
||||
|
||||
// Returns slice of online disks needed.
|
||||
// - slice returing readable disks.
|
||||
// - fileMetadata
|
||||
// - xlMetaV1
|
||||
// - bool value indicating if healing is needed.
|
||||
// - error if any.
|
||||
func (xl XL) listOnlineDisks(volume, path string) (onlineDisks []StorageAPI, mdata fileMetadata, heal bool, err error) {
|
||||
func (xl XL) listOnlineDisks(volume, path string) (onlineDisks []StorageAPI, mdata xlMetaV1, heal bool, err error) {
|
||||
partsMetadata, errs := xl.getPartsMetadata(volume, path)
|
||||
notFoundCount := 0
|
||||
// FIXME: take care of the situation when a disk has failed and been removed
|
||||
@@ -82,8 +65,8 @@ func (xl XL) listOnlineDisks(volume, path string) (onlineDisks []StorageAPI, mda
|
||||
notFoundCount++
|
||||
// If we have errors with file not found greater than allowed read
|
||||
// quorum we return err as errFileNotFound.
|
||||
if notFoundCount > xl.readQuorum {
|
||||
return nil, fileMetadata{}, false, errFileNotFound
|
||||
if notFoundCount > len(xl.storageDisks)-xl.readQuorum {
|
||||
return nil, xlMetaV1{}, false, errFileNotFound
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +79,7 @@ func (xl XL) listOnlineDisks(volume, path string) (onlineDisks []StorageAPI, mda
|
||||
"volume": volume,
|
||||
"path": path,
|
||||
}).Errorf("Extracting file versions failed with %s", err)
|
||||
return nil, fileMetadata{}, false, err
|
||||
return nil, xlMetaV1{}, false, err
|
||||
}
|
||||
|
||||
// Get highest file version.
|
||||
@@ -130,31 +113,31 @@ func (xl XL) listOnlineDisks(volume, path string) (onlineDisks []StorageAPI, mda
|
||||
"onlineDiskCount": onlineDiskCount,
|
||||
"readQuorumCount": xl.readQuorum,
|
||||
}).Errorf("%s", errReadQuorum)
|
||||
return nil, fileMetadata{}, false, errReadQuorum
|
||||
return nil, xlMetaV1{}, false, errReadQuorum
|
||||
}
|
||||
}
|
||||
return onlineDisks, mdata, heal, nil
|
||||
}
|
||||
|
||||
// Get parts.json metadata as a map slice.
|
||||
// Get xl.json metadata as a map slice.
|
||||
// Returns error slice indicating the failed metadata reads.
|
||||
// Read lockNS() should be done by caller.
|
||||
func (xl XL) getPartsMetadata(volume, path string) ([]fileMetadata, []error) {
|
||||
func (xl XL) getPartsMetadata(volume, path string) ([]xlMetaV1, []error) {
|
||||
errs := make([]error, len(xl.storageDisks))
|
||||
metadataArray := make([]fileMetadata, len(xl.storageDisks))
|
||||
metadataFilePath := slashpath.Join(path, metadataFile)
|
||||
metadataArray := make([]xlMetaV1, len(xl.storageDisks))
|
||||
xlMetaV1FilePath := slashpath.Join(path, xlMetaV1File)
|
||||
for index, disk := range xl.storageDisks {
|
||||
offset := int64(0)
|
||||
metadataReader, err := disk.ReadFile(volume, metadataFilePath, offset)
|
||||
metadataReader, err := disk.ReadFile(volume, xlMetaV1FilePath, offset)
|
||||
if err != nil {
|
||||
errs[index] = err
|
||||
continue
|
||||
}
|
||||
defer metadataReader.Close()
|
||||
|
||||
metadata, err := fileMetadataDecode(metadataReader)
|
||||
metadata, err := xlMetaV1Decode(metadataReader)
|
||||
if err != nil {
|
||||
// Unable to parse parts.json, set error.
|
||||
// Unable to parse xl.json, set error.
|
||||
errs[index] = err
|
||||
continue
|
||||
}
|
||||
@@ -163,38 +146,30 @@ func (xl XL) getPartsMetadata(volume, path string) ([]fileMetadata, []error) {
|
||||
return metadataArray, errs
|
||||
}
|
||||
|
||||
// Writes/Updates `parts.json` for given file. updateParts carries
|
||||
// index of disks where `parts.json` needs to be updated.
|
||||
// Writes/Updates `xl.json` for given file. updateParts carries
|
||||
// index of disks where `xl.json` needs to be updated.
|
||||
//
|
||||
// Returns collection of errors, indexed in accordance with input
|
||||
// updateParts order.
|
||||
// Write lockNS() should be done by caller.
|
||||
func (xl XL) setPartsMetadata(volume, path string, metadata fileMetadata, updateParts []bool) []error {
|
||||
metadataFilePath := filepath.Join(path, metadataFile)
|
||||
func (xl XL) setPartsMetadata(volume, path string, metadata xlMetaV1, updateParts []bool) []error {
|
||||
xlMetaV1FilePath := filepath.Join(path, xlMetaV1File)
|
||||
errs := make([]error, len(xl.storageDisks))
|
||||
|
||||
for index := range updateParts {
|
||||
errs[index] = errors.New("Metadata not updated")
|
||||
}
|
||||
|
||||
metadataBytes, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
for index := range updateParts {
|
||||
errs[index] = err
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
for index, shouldUpdate := range updateParts {
|
||||
if !shouldUpdate {
|
||||
continue
|
||||
}
|
||||
writer, err := xl.storageDisks[index].CreateFile(volume, metadataFilePath)
|
||||
writer, err := xl.storageDisks[index].CreateFile(volume, xlMetaV1FilePath)
|
||||
errs[index] = err
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_, err = writer.Write(metadataBytes)
|
||||
err = metadata.Write(writer)
|
||||
if err != nil {
|
||||
errs[index] = err
|
||||
safeCloseAndRemove(writer)
|
||||
|
||||
Reference in New Issue
Block a user