milvus/internal/util/segcore/segment_interface.go
congqixia 0a208d7224
enhance: Move segment loading logic from Go layer to segcore for self-managed loading (#45488)
Related to #45060

Refactor segment loading architecture to make segments autonomously
manage their own loading process, moving the orchestration logic from Go
(segment_loader.go) to C++ (segcore).

**C++ Layer (segcore):**
- Added `SetLoadInfo()` and `Load()` methods to `SegmentInterface` and
implementations
- Implemented `ChunkedSegmentSealedImpl::Load()` with parallel loading
strategy:
  - Separates indexed fields from non-indexed fields
  - Loads indexes concurrently using thread pools
  - Loads field data for non-indexed fields in parallel
- Implemented `SegmentGrowingImpl::Load()` to convert and load field
data
- Extracted `LoadIndexData()` as a reusable utility function in
`Utils.cpp`
- Added `SegmentLoad()` C binding in `segment_c.cpp`

**Go Layer:**
- Added `Load()` method to segment interfaces
- Updated mock implementations and test interfaces
- Integrated new C++ `SegmentLoad()` binding in Go segment wrapper

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
2025-11-14 11:21:37 +08:00

89 lines
2.7 KiB
Go

package segcore
/*
#cgo pkg-config: milvus_core
#include "common/type_c.h"
*/
import "C"
import "context"
// CSegment is the interface of a segcore segment.
// TODO: We should separate the interface of CGrowingSegment and CSealedSegment,
// Because they have different implementations, GrowingSegment will only be used at streamingnode, SealedSegment will only be used at querynode.
// But currently, we just use the same interface to represent them to keep compatible with querynode LocalSegment.
type CSegment interface {
GrowingSegment
SealedSegment
}
// GrowingSegment is the interface of a growing segment.
type GrowingSegment interface {
basicSegmentMethodSet
// Insert inserts data into the segment.
Insert(ctx context.Context, request *InsertRequest) (*InsertResult, error)
}
// SealedSegment is the interface of a sealed segment.
type SealedSegment interface {
basicSegmentMethodSet
// LoadFieldData loads field data into the segment.
LoadFieldData(ctx context.Context, request *LoadFieldDataRequest) (*LoadFieldDataResult, error)
// AddFieldDataInfo adds field data info into the segment.
AddFieldDataInfo(ctx context.Context, request *AddFieldDataInfoRequest) (*AddFieldDataInfoResult, error)
// DropIndex drops the index of the segment.
DropIndex(ctx context.Context, fieldID int64) error
DropJSONIndex(ctx context.Context, fieldID int64, nestedPath string) error
}
// basicSegmentMethodSet is the basic method set of a segment.
type basicSegmentMethodSet interface {
// ID returns the ID of the segment.
ID() int64
// RawPointer returns the raw pointer of the segment.
// TODO: should be removed in future.
RawPointer() CSegmentInterface
// RawPointer returns the raw pointer of the segment.
RowNum() int64
// MemSize returns the memory size of the segment.
MemSize() int64
// HasRawData checks if the segment has raw data.
HasRawData(fieldID int64) bool
// HasFieldData checks if the segment has field data.
HasFieldData(fieldID int64) bool
// Search requests a search on the segment.
Search(ctx context.Context, searchReq *SearchRequest) (*SearchResult, error)
// Retrieve retrieves entities from the segment.
Retrieve(ctx context.Context, plan *RetrievePlan) (*RetrieveResult, error)
// RetrieveByOffsets retrieves entities from the segment by offsets.
RetrieveByOffsets(ctx context.Context, plan *RetrievePlanWithOffsets) (*RetrieveResult, error)
// Delete deletes data from the segment.
Delete(ctx context.Context, request *DeleteRequest) (*DeleteResult, error)
// FinishLoad wraps up the load process and let segcore do the leftover jobs.
FinishLoad() error
// Load invokes segment managed loading.
Load(ctx context.Context) error
// Release releases the segment.
Release()
}