initialize store reader, reads index block(keys,offset etc.), then caches it.
()
| 120 | |
| 121 | // initialize store reader, reads index block(keys,offset etc.), then caches it. |
| 122 | func (r *storeMMapReader) initialize() error { |
| 123 | // decode footer |
| 124 | footerStart := len(r.fullBlock) - sstFileFooterSize |
| 125 | // validate magic-number |
| 126 | if uint64Func(r.fullBlock[footerStart+magicNumberAtFooter:]) != magicNumberOffsetFile { |
| 127 | return fmt.Errorf("verify magic-number of sstfile:%s failure", r.path) |
| 128 | } |
| 129 | posOfOffset := int(binary.LittleEndian.Uint32(r.fullBlock[footerStart : footerStart+4])) |
| 130 | posOfKeys := int(binary.LittleEndian.Uint32(r.fullBlock[footerStart+4 : footerStart+8])) |
| 131 | if !intsAreSortedFunc([]int{ |
| 132 | 0, posOfOffset, posOfKeys, footerStart, |
| 133 | }) { |
| 134 | return fmt.Errorf("bad footer data, posOfOffsets: %d posOfKeys: %d,"+ |
| 135 | " footerStart: %d", posOfOffset, posOfKeys, footerStart) |
| 136 | } |
| 137 | // decode offsets |
| 138 | offsetsBlock := r.fullBlock[posOfOffset:posOfKeys] |
| 139 | r.offsets = encoding.NewFixedOffsetDecoder() |
| 140 | if err := unmarshalFixedOffsetFunc(r.offsets, offsetsBlock); err != nil { |
| 141 | return fmt.Errorf("unmarshal fixed-offsets decoder with error: %s", err) |
| 142 | } |
| 143 | // decode keys |
| 144 | if _, err := encoding.BitmapUnmarshal(r.keys, r.fullBlock[posOfKeys:]); err != nil { |
| 145 | return fmt.Errorf("unmarshal keys data from file[%s] error:%s", r.path, err) |
| 146 | } |
| 147 | // validate keys and offsets |
| 148 | if r.offsets.Size() != int(r.keys.GetCardinality()) { |
| 149 | return fmt.Errorf("num. of keys != num. of offsets in file[%s]", r.path) |
| 150 | } |
| 151 | // read entries block |
| 152 | r.entriesBlock = r.fullBlock[:posOfOffset] |
| 153 | return nil |
| 154 | } |
| 155 | |
| 156 | func unmarshalFixedOffset(decoder *encoding.FixedOffsetDecoder, data []byte) error { |
| 157 | _, err := decoder.Unmarshal(data) |
no test coverage detected