Load the index from the hint file
()
| 267 | |
| 268 | // Load the index from the hint file |
| 269 | func (db *DB) loadIndexFromHintFile() error { |
| 270 | // Check whether the hint file exists |
| 271 | hintFileName := filepath.Join(db.options.DirPath, data2.HintFileSuffix) |
| 272 | if _, err := os.Stat(hintFileName); os.IsNotExist(err) { |
| 273 | return nil |
| 274 | } |
| 275 | |
| 276 | // Open hint file |
| 277 | hintFile, err := data2.OpenHintFile(db.options.DirPath, db.options.DataFileSize, db.options.FIOType) |
| 278 | if err != nil { |
| 279 | return err |
| 280 | } |
| 281 | |
| 282 | // Read the index in the file |
| 283 | var offset int64 = 0 |
| 284 | for { |
| 285 | logRecord, size, err := hintFile.ReadLogRecord(offset) |
| 286 | if err != nil { |
| 287 | if err == io.EOF { |
| 288 | break |
| 289 | } |
| 290 | return err |
| 291 | } |
| 292 | |
| 293 | // Decode to get the actual index location |
| 294 | pst := data2.DecodeLogRecordPst(logRecord.Value) |
| 295 | db.index.Put(logRecord.Key, pst) |
| 296 | offset += size |
| 297 | } |
| 298 | return nil |
| 299 | } |
no test coverage detected