empty source and auto append supports

This commit is contained in:
lionsoul2014 2026-03-12 11:23:43 +08:00
parent 1a29562c2d
commit c63b1dc5db
1 changed files with 21 additions and 6 deletions

View File

@ -89,9 +89,15 @@ type Maker struct {
func NewMaker(version *Version, policy IndexPolicy, srcFile string, dstFile string, fields []int) (*Maker, error) { func NewMaker(version *Version, policy IndexPolicy, srcFile string, dstFile string, fields []int) (*Maker, error) {
// open the source file with READONLY mode // open the source file with READONLY mode
srcHandle, err := os.OpenFile(srcFile, os.O_RDONLY, 0600) var err error
if err != nil { var srcHandle *os.File
return nil, fmt.Errorf("open source file `%s`: %w", srcFile, err) if srcFile == "" {
srcHandle = nil
} else {
srcHandle, err = os.OpenFile(srcFile, os.O_RDONLY, 0600)
if err != nil {
return nil, fmt.Errorf("open source file `%s`: %w", srcFile, err)
}
} }
// open the destination file with Read/Write mode // open the destination file with Read/Write mode
@ -224,14 +230,23 @@ func (m *Maker) Init() error {
} }
// load all the segments // load all the segments
err = m.loadSegments() if m.srcHandle == nil {
if err != nil { // do nothing here
return fmt.Errorf("load segments: %w", err) } else {
err = m.loadSegments()
if err != nil {
return fmt.Errorf("load segments: %w", err)
}
} }
return nil return nil
} }
// Append a new segment
func (m *Maker) Append(seg *Segment) {
m.segments = append(m.segments, seg)
}
// refresh the vector index of the specified ip // refresh the vector index of the specified ip
func (m *Maker) setVectorIndex(ip []byte, ptr uint32) { func (m *Maker) setVectorIndex(ip []byte, ptr uint32) {
var segIdxSize = uint32(m.version.SegmentIndexSize) var segIdxSize = uint32(m.version.SegmentIndexSize)