Use metadata reader in ReadVersion (#12942)

Use `readMetadata` when reading version 
information without data requested. 

Reduces IO on inlined data.

Bonus: Inline compressed data as well when 
compression is enabled.
This commit is contained in:
Klaus Post 2021-08-12 19:05:24 +02:00 committed by GitHub
parent a526ad2e80
commit 3eac02f676
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -869,6 +869,15 @@ func (er erasureObjects) putObject(ctx context.Context, bucket string, object st
} else if shardFileSize < smallFileThreshold/8 { } else if shardFileSize < smallFileThreshold/8 {
inlineBuffers = make([]*bytes.Buffer, len(onlineDisks)) inlineBuffers = make([]*bytes.Buffer, len(onlineDisks))
} }
} else {
// If compressed, use actual size to determine.
if sz := erasure.ShardFileSize(data.ActualSize()); sz > 0 {
if !opts.Versioned && sz < smallFileThreshold {
inlineBuffers = make([]*bytes.Buffer, len(onlineDisks))
} else if sz < smallFileThreshold/8 {
inlineBuffers = make([]*bytes.Buffer, len(onlineDisks))
}
}
} }
for i, disk := range onlineDisks { for i, disk := range onlineDisks {
if disk == nil { if disk == nil {
@ -876,7 +885,11 @@ func (er erasureObjects) putObject(ctx context.Context, bucket string, object st
} }
if len(inlineBuffers) > 0 { if len(inlineBuffers) > 0 {
inlineBuffers[i] = bytes.NewBuffer(make([]byte, 0, shardFileSize)) sz := shardFileSize
if sz < 0 {
sz = data.ActualSize()
}
inlineBuffers[i] = bytes.NewBuffer(make([]byte, 0, sz))
writers[i] = newStreamingBitrotWriterBuffer(inlineBuffers[i], DefaultBitrotAlgorithm, erasure.ShardSize()) writers[i] = newStreamingBitrotWriterBuffer(inlineBuffers[i], DefaultBitrotAlgorithm, erasure.ShardSize())
continue continue
} }

View File

@ -1068,8 +1068,20 @@ func (s *xlStorage) ReadVersion(ctx context.Context, volume, path, versionID str
if err != nil { if err != nil {
return fi, err return fi, err
} }
var buf []byte
buf, err := s.ReadAll(ctx, volume, pathJoin(path, xlStorageFormatFile)) if readData {
buf, err = s.ReadAll(ctx, volume, pathJoin(path, xlStorageFormatFile))
} else {
buf, err = s.readMetadata(pathJoin(volumeDir, path, xlStorageFormatFile))
if err != nil {
if osIsNotExist(err) {
if err = Access(volumeDir); err != nil && osIsNotExist(err) {
return fi, errVolumeNotFound
}
}
err = osErrToFileErr(err)
}
}
if err != nil { if err != nil {
if err == errFileNotFound { if err == errFileNotFound {
if err = s.renameLegacyMetadata(volumeDir, path); err != nil { if err = s.renameLegacyMetadata(volumeDir, path); err != nil {