MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / getValueByPosition

Method getValueByPosition

engine/db.go:321–345  ·  view source on GitHub ↗

getValueByPosition Get the corresponding value based on the location index information

(logRecordPst *data2.LogRecordPst)

Source from the content-addressed store, hash-verified

319
320// getValueByPosition Get the corresponding value based on the location index information
321func (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
348func (db *DB) Delete(key []byte) error {

Callers 3

GetMethod · 0.95
FoldMethod · 0.95
ValueMethod · 0.80

Calls 1

ReadLogRecordMethod · 0.95

Tested by

no test coverage detected