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

Method loadHintFile

db.go:653–752  ·  view source on GitHub ↗

loadHintFile loads a single hint file and rebuilds indexes

(fid int64)

Source from the content-addressed store, hash-verified

651
652// loadHintFile loads a single hint file and rebuilds indexes
653func (db *DB) loadHintFile(fid int64) (bool, error) {
654 hintPath := getHintPath(fid, db.opt.Dir)
655
656 // Check if hint file exists
657 if _, err := os.Stat(hintPath); os.IsNotExist(err) {
658 return false, nil // Hint file doesn't exist, need to scan data file
659 }
660
661 reader := &HintFileReader{}
662 if err := reader.Open(hintPath); err != nil {
663 return false, nil
664 }
665 defer func() {
666 if err := reader.Close(); err != nil {
667 // Log error but don't fail the operation
668 utils.GetLogger().Printf("Warning: failed to close hint file reader: %v", err)
669 }
670 }()
671
672 // Read all hint entries and build indexes
673 for {
674 hintEntry, err := reader.Read()
675 if err != nil {
676 if err == io.EOF {
677 break // End of file
678 }
679 return false, nil
680 }
681
682 if hintEntry == nil {
683 continue
684 }
685
686 // Check if bucket exists
687 bucketId := hintEntry.BucketId
688 if _, err := db.bucketMgr.GetBucketById(bucketId); errors.Is(err, ErrBucketNotExist) {
689 continue // Skip if bucket doesn't exist
690 }
691
692 // Create a record from hint entry
693 record := core.NewRecord()
694 record.WithKey(hintEntry.Key).
695 WithFileId(hintEntry.FileID).
696 WithDataPos(hintEntry.DataPos).
697 WithValueSize(hintEntry.ValueSize).
698 WithTimestamp(hintEntry.Timestamp).
699 WithTTL(hintEntry.TTL).
700 WithTxID(0) // TxID is not stored in hint file
701
702 // Create an entry from hint entry
703 entry := core.NewEntry()
704 entry.WithKey(hintEntry.Key)
705
706 // Create metadata
707 meta := core.NewMetaData()
708 meta.WithBucketId(hintEntry.BucketId).
709 WithKeySize(hintEntry.KeySize).
710 WithValueSize(hintEntry.ValueSize).

Callers 1

parseDataFilesMethod · 0.95

Calls 15

OpenMethod · 0.95
CloseMethod · 0.95
ReadMethod · 0.95
WithKeyMethod · 0.95
WithKeyMethod · 0.95
WithBucketIdMethod · 0.95
WithMetaMethod · 0.95
getValueByRecordMethod · 0.95
WithValueMethod · 0.95
WithValueMethod · 0.95
buildIdxesMethod · 0.95
GetLoggerFunction · 0.92

Tested by

no test coverage detected