Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions indexer/meta_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import (
"github.com/ozontech/seq-db/tokenizer"
)

const (
metaDataVersion1 uint16 = 1 // milliseconds MID support (no longer supported)
metaDataVersion2 uint16 = 2 // nanoseconds MID support

metaDataVersion = metaDataVersion2
)

type MetaData struct {
ID seq.ID
// Size of an uncompressed document in bytes.
Expand All @@ -35,8 +42,7 @@ func (m *MetaData) MarshalBinaryTo(b []byte) []byte {
b = binary.LittleEndian.AppendUint16(b, metadataMagic)

// Append current binary version of the metadata.
const version = 2
b = binary.LittleEndian.AppendUint16(b, version)
b = binary.LittleEndian.AppendUint16(b, metaDataVersion)

// Encode seq.ID.
b = binary.LittleEndian.AppendUint64(b, uint64(m.ID.MID))
Expand Down Expand Up @@ -65,29 +71,15 @@ func (m *MetaData) UnmarshalBinary(b []byte) error {
b = b[2:]

switch version {
case 1:
// Version 1 meta stores MID in milliseconds
return m.unmarshalVersion1(b)
case 2:
// Version 2 meta stores MID in nanoseconds
return m.unmarshalVersion2(b)
case metaDataVersion1:
return fmt.Errorf("version: %d no longer supported", version)
case metaDataVersion2:
return m.unmarshal(b)
default:
return fmt.Errorf("unimplemented metadata version: %d", version)
}
}

func (m *MetaData) unmarshalVersion1(b []byte) error {
if err := m.unmarshal(b); err != nil {
return err
}
m.ID.MID = seq.MillisToMID(uint64(m.ID.MID))
return nil
}

func (m *MetaData) unmarshalVersion2(b []byte) error {
return m.unmarshal(b)
}

func (m *MetaData) unmarshal(b []byte) error {
// Decode seq.ID.
m.ID.MID = seq.MID(binary.LittleEndian.Uint64(b))
Expand Down
Loading