empty source and auto append supports
This commit is contained in:
parent
1a29562c2d
commit
c63b1dc5db
|
|
@ -89,10 +89,16 @@ 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
|
||||||
|
var srcHandle *os.File
|
||||||
|
if srcFile == "" {
|
||||||
|
srcHandle = nil
|
||||||
|
} else {
|
||||||
|
srcHandle, err = os.OpenFile(srcFile, os.O_RDONLY, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("open source file `%s`: %w", srcFile, err)
|
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
|
||||||
dstHandle, err := os.OpenFile(dstFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
dstHandle, err := os.OpenFile(dstFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||||
|
|
@ -224,14 +230,23 @@ func (m *Maker) Init() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// load all the segments
|
// load all the segments
|
||||||
|
if m.srcHandle == nil {
|
||||||
|
// do nothing here
|
||||||
|
} else {
|
||||||
err = m.loadSegments()
|
err = m.loadSegments()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("load segments: %w", err)
|
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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue