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) {
// open the source file with READONLY mode
srcHandle, err := os.OpenFile(srcFile, os.O_RDONLY, 0600)
if err != nil {
return nil, fmt.Errorf("open source file `%s`: %w", srcFile, err)
var err error
var srcHandle *os.File
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
@ -224,14 +230,23 @@ func (m *Maker) Init() error {
}
// load all the segments
err = m.loadSegments()
if err != nil {
return fmt.Errorf("load segments: %w", err)
if m.srcHandle == nil {
// do nothing here
} else {
err = m.loadSegments()
if err != nil {
return fmt.Errorf("load segments: %w", err)
}
}
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
func (m *Maker) setVectorIndex(ip []byte, ptr uint32) {
var segIdxSize = uint32(m.version.SegmentIndexSize)