MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / parseDataFiles

Method parseDataFiles

db.go:532–650  ·  view source on GitHub ↗
(dataFileIds []int64)

Source from the content-addressed store, hash-verified

530}
531
532func (db *DB) parseDataFiles(dataFileIds []int64) (err error) {
533 var (
534 off int64
535 f *fileRecovery
536 fID int64
537 dataInTx core.DataInTx
538 )
539
540 parseDataInTx := func() error {
541 for _, entry := range dataInTx.Es {
542 // if this bucket is not existed in bucket manager right now
543 // its because it already deleted in the feature WAL utils.GetLogger().
544 // so we can just ignore here.
545 bucketId := entry.Meta.BucketId
546 if _, err := db.bucketMgr.GetBucketById(bucketId); errors.Is(err, ErrBucketNotExist) {
547 continue
548 }
549
550 record := db.createRecordByModeWithFidAndOff(entry.Fid, uint64(entry.Off), &entry.Entry)
551
552 if err = db.buildIdxes(record, &entry.Entry); err != nil {
553 return err
554 }
555
556 db.KeyCount++
557
558 }
559 return nil
560 }
561
562 readEntriesFromFile := func() error {
563 for {
564 entry, err := f.readEntry(off)
565 if err != nil {
566 // whatever which logic branch it will choose, we will release the fd.
567 _ = f.release()
568 if errors.Is(err, io.EOF) || errors.Is(err, ErrIndexOutOfBound) || errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, ErrEntryZero) || errors.Is(err, core.ErrHeaderSizeOutOfBounds) {
569 break
570 }
571 if off >= db.opt.SegmentSize {
572 break
573 }
574
575 return err
576 }
577
578 if entry == nil {
579 break
580 }
581
582 entryWhenRecovery := &core.EntryWhenRecovery{
583 Entry: *entry,
584 Fid: fID,
585 Off: off,
586 }
587 if dataInTx.TxId == 0 {
588 dataInTx.AppendEntry(entryWhenRecovery)
589 dataInTx.TxId = entry.Meta.TxID

Callers 1

buildIndexesMethod · 0.95

Calls 13

buildIdxesMethod · 0.95
loadHintFileMethod · 0.95
getRecordCountMethod · 0.95
getDataPathFunction · 0.85
newFileRecoveryFunction · 0.85
GetBucketByIdMethod · 0.80
readEntryMethod · 0.80
AppendEntryMethod · 0.80
IsSameTxMethod · 0.80
SizeMethod · 0.65
releaseMethod · 0.45

Tested by

no test coverage detected