diff --git a/indexer/meta_data.go b/indexer/meta_data.go index aa30d646..b74cddaa 100644 --- a/indexer/meta_data.go +++ b/indexer/meta_data.go @@ -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. @@ -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)) @@ -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))