Skip to content

Commit

Permalink
xlmeta: Recover corrupted metadata (minio#13205)
Browse files Browse the repository at this point in the history
When unable to load existing metadata new versions 
would not be written. This would leave objects in a 
permanently unrecoverable state

Instead, start with clean metadata and write the incoming data.
  • Loading branch information
klauspost authored Sep 14, 2021
1 parent af78c39 commit bf5bfe5
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cmd/xl-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ func (s *xlStorage) WriteMetadata(ctx context.Context, volume, path string, fi F

var xlMeta xlMetaV2
if !isXL2V1Format(buf) {
// This is both legacy and without proper version.
err = xlMeta.AddVersion(fi)
if err != nil {
logger.LogIf(ctx, err)
Expand All @@ -1006,7 +1007,8 @@ func (s *xlStorage) WriteMetadata(ctx context.Context, volume, path string, fi F
} else {
if err = xlMeta.Load(buf); err != nil {
logger.LogIf(ctx, err)
return err
// Corrupted data, reset and write.
xlMeta = xlMetaV2{}
}

if err = xlMeta.AddVersion(fi); err != nil {
Expand Down Expand Up @@ -1982,21 +1984,22 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
if isXL2V1Format(dstBuf) {
if err = xlMeta.Load(dstBuf); err != nil {
logger.LogIf(s.ctx, err)
return err
// Data appears corrupt. Drop data.
xlMeta = xlMetaV2{}
}
} else {
// This code-path is to preserve the legacy data.
xlMetaLegacy := &xlMetaV1Object{}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(dstBuf, xlMetaLegacy); err != nil {
logger.LogIf(s.ctx, err)
return errFileCorrupt
}
if err = xlMeta.AddLegacy(xlMetaLegacy); err != nil {
logger.LogIf(s.ctx, err)
return errFileCorrupt
// Data appears corrupt. Drop data.
} else {
if err = xlMeta.AddLegacy(xlMetaLegacy); err != nil {
logger.LogIf(s.ctx, err)
}
legacyPreserved = true
}
legacyPreserved = true
}
} else {
s.RLock()
Expand Down

0 comments on commit bf5bfe5

Please sign in to comment.