mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
Improve performance on multiple versions (#13573)
Existing:
```go
type xlMetaV2 struct {
Versions []xlMetaV2Version `json:"Versions" msg:"Versions"`
}
```
Serialized as regular MessagePack.
```go
//msgp:tuple xlMetaV2VersionHeader
type xlMetaV2VersionHeader struct {
VersionID [16]byte
ModTime int64
Type VersionType
Flags xlFlags
}
```
Serialize as streaming MessagePack, format:
```
int(headerVersion)
int(xlmetaVersion)
int(nVersions)
for each version {
binary blob, xlMetaV2VersionHeader, serialized
binary blob, xlMetaV2Version, serialized.
}
```
xlMetaV2VersionHeader is <= 30 bytes serialized. Deserialized struct
can easily be reused and does not contain pointers, so efficient as a
slice (single allocation)
This allows quickly parsing everything as slices of bytes (no copy).
Versions are always *saved* sorted by modTime, newest *first*.
No more need to sort on load.
* Allows checking if a version exists.
* Allows reading single version without unmarshal all.
* Allows reading latest version of type without unmarshal all.
* Allows reading latest version without unmarshal of all.
* Allows checking if the latest is deleteMarker by reading first entry.
* Allows adding/updating/deleting a version with only header deserialization.
* Reduces allocations on conversion to FileInfo(s).
This commit is contained in:
@@ -18,11 +18,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cespare/xxhash/v2"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/minio/minio/internal/logger"
|
||||
)
|
||||
@@ -205,6 +207,27 @@ func (m *xlMetaV1Object) ToFileInfo(volume, path string) (FileInfo, error) {
|
||||
return fi, nil
|
||||
}
|
||||
|
||||
// Signature will return a signature that is expected to be the same across all disks.
|
||||
func (m *xlMetaV1Object) Signature() [4]byte {
|
||||
// Shallow copy
|
||||
c := *m
|
||||
// Zero unimportant fields
|
||||
c.Erasure.Index = 0
|
||||
c.Minio.Release = ""
|
||||
crc := hashDeterministicString(c.Meta)
|
||||
c.Meta = nil
|
||||
|
||||
if bts, err := c.MarshalMsg(metaDataPoolGet()); err == nil {
|
||||
crc ^= xxhash.Sum64(bts)
|
||||
metaDataPoolPut(bts)
|
||||
}
|
||||
|
||||
// Combine upper and lower part
|
||||
var tmp [4]byte
|
||||
binary.LittleEndian.PutUint32(tmp[:], uint32(crc^(crc>>32)))
|
||||
return tmp
|
||||
}
|
||||
|
||||
// XL metadata constants.
|
||||
const (
|
||||
// XL meta version.
|
||||
|
||||
Reference in New Issue
Block a user