getValueByPosition Get the corresponding value based on the location index information
(logRecordPst *data2.LogRecordPst)
| 319 | |
| 320 | // getValueByPosition Get the corresponding value based on the location index information |
| 321 | func (db *DB) getValueByPosition(logRecordPst *data2.LogRecordPst) ([]byte, error) { |
| 322 | // Find the corresponding data file according to the file id |
| 323 | var dataFile *data2.DataFile |
| 324 | if logRecordPst.Fid == db.activeFile.FileID { |
| 325 | dataFile = db.activeFile |
| 326 | } else { |
| 327 | dataFile = db.olderFiles[logRecordPst.Fid] |
| 328 | } |
| 329 | |
| 330 | // The data file is empty |
| 331 | if dataFile == nil { |
| 332 | return nil, _const.ErrDataFailNotFound |
| 333 | } |
| 334 | |
| 335 | // The corresponding data is read according to the offset |
| 336 | logRecord, _, err := dataFile.ReadLogRecord(logRecordPst.Offset) |
| 337 | if err != nil { |
| 338 | return nil, nil |
| 339 | } |
| 340 | if logRecord.Type == data2.LogRecordDeleted { |
| 341 | return nil, _const.ErrKeyNotFound |
| 342 | } |
| 343 | |
| 344 | return logRecord.Value, nil |
| 345 | } |
| 346 | |
| 347 | // Delete data according to the key |
| 348 | func (db *DB) Delete(key []byte) error { |
no test coverage detected