loadHintFile loads a single hint file and rebuilds indexes
(fid int64)
| 651 | |
| 652 | // loadHintFile loads a single hint file and rebuilds indexes |
| 653 | func (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). |
no test coverage detected