Skip to content

Commit b796876

Browse files
authored
Replace segment index file path with index file id within segment index meta (milvus-io#19866)
Signed-off-by: yun.zhang <[email protected]> Signed-off-by: yun.zhang <[email protected]>
1 parent 99df2d9 commit b796876

29 files changed

+1520
-1551
lines changed

Diff for: cmd/tools/migration/meta/210_to_220.go

+26-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package meta
33
import (
44
"fmt"
55
"sort"
6+
"strings"
67

78
"github.com/milvus-io/milvus/internal/util/typeutil"
89

@@ -142,21 +143,32 @@ func combineToSegmentIndexesMeta220(segmentIndexes SegmentIndexesMeta210, indexB
142143
if !ok {
143144
return nil, fmt.Errorf("index build meta not found, segment id: %d, index id: %d, index build id: %d", segID, indexID, record.GetBuildID())
144145
}
146+
147+
fileKeys := make([]string, len(buildMeta.GetIndexFilePaths()))
148+
for i, filePath := range buildMeta.GetIndexFilePaths() {
149+
parts := strings.Split(filePath, "/")
150+
if len(parts) == 0 {
151+
return nil, fmt.Errorf("invaild index file path: %s", filePath)
152+
}
153+
154+
fileKeys[i] = parts[len(parts)-1]
155+
}
156+
145157
segmentIndexModel := &model.SegmentIndex{
146-
SegmentID: segID,
147-
CollectionID: record.GetCollectionID(),
148-
PartitionID: record.GetPartitionID(),
149-
NumRows: buildMeta.GetReq().GetNumRows(),
150-
IndexID: indexID,
151-
BuildID: record.GetBuildID(),
152-
NodeID: buildMeta.GetNodeID(),
153-
IndexVersion: buildMeta.GetIndexVersion(),
154-
IndexState: buildMeta.GetState(),
155-
FailReason: buildMeta.GetFailReason(),
156-
IsDeleted: buildMeta.GetMarkDeleted(),
157-
CreateTime: record.GetCreateTime(),
158-
IndexFilePaths: buildMeta.GetIndexFilePaths(),
159-
IndexSize: buildMeta.GetSerializeSize(),
158+
SegmentID: segID,
159+
CollectionID: record.GetCollectionID(),
160+
PartitionID: record.GetPartitionID(),
161+
NumRows: buildMeta.GetReq().GetNumRows(),
162+
IndexID: indexID,
163+
BuildID: record.GetBuildID(),
164+
NodeID: buildMeta.GetNodeID(),
165+
IndexVersion: buildMeta.GetIndexVersion(),
166+
IndexState: buildMeta.GetState(),
167+
FailReason: buildMeta.GetFailReason(),
168+
IsDeleted: buildMeta.GetMarkDeleted(),
169+
CreateTime: record.GetCreateTime(),
170+
IndexFileKeys: fileKeys,
171+
IndexSize: buildMeta.GetSerializeSize(),
160172
}
161173
segmentIndexModels.AddRecord(segID, indexID, segmentIndexModel)
162174
}

Diff for: internal/indexcoord/garbage_collector.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"sync"
2323
"time"
2424

25+
"github.com/milvus-io/milvus/internal/util/metautil"
26+
2527
"go.uber.org/zap"
2628

2729
"github.com/milvus-io/milvus-proto/go-api/commonpb"
@@ -241,16 +243,18 @@ func (gc *garbageCollector) recycleUnusedIndexFiles() {
241243
continue
242244
}
243245
log.Ctx(gc.ctx).Info("index meta can be recycled, recycle index files", zap.Int64("buildID", buildID))
244-
canRecycle, indexFilePaths := gc.metaTable.GetIndexFilePathByBuildID(buildID)
246+
canRecycle, segIdx := gc.metaTable.GetSegmentIndexByBuildID(buildID)
245247
if !canRecycle {
246248
// Even if the index is marked as deleted, the index file will not be recycled, wait for the next gc,
247249
// and delete all index files about the buildID at one time.
248250
log.Ctx(gc.ctx).Warn("IndexCoord garbageCollector can not recycle index files", zap.Int64("buildID", buildID))
249251
continue
250252
}
251-
filesMap := make(map[string]bool)
252-
for _, file := range indexFilePaths {
253-
filesMap[file] = true
253+
filesMap := make(map[string]struct{})
254+
for _, fileID := range segIdx.IndexFileKeys {
255+
filepath := metautil.BuildSegmentIndexFilePath(gc.chunkManager.RootPath(), segIdx.BuildID, segIdx.IndexVersion,
256+
segIdx.PartitionID, segIdx.SegmentID, fileID)
257+
filesMap[filepath] = struct{}{}
254258
}
255259
files, _, err := gc.chunkManager.ListWithPrefix(gc.ctx, key, true)
256260
if err != nil {

0 commit comments

Comments
 (0)