mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-03 04:19:18 +08:00
c373b44c2c
issue: #18120 /kind enhancement Signed-off-by: Yuchen Gao <yuchen.gao@zilliz.com> Signed-off-by: Yuchen Gao <yuchen.gao@zilliz.com>
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package segmentutil
|
|
|
|
import (
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// ReCalcRowCount re-calculates number of rows of `oldSeg` based on its bin log count, and correct its value in its
|
|
// cloned copy, which is `newSeg`.
|
|
// Note that `segCloned` should be a copied version of `seg`.
|
|
func ReCalcRowCount(seg, segCloned *datapb.SegmentInfo) {
|
|
// `segment` is not mutated but only cloned above and is safe to be referred here.
|
|
if newCount := CalcRowCountFromBinLog(seg); newCount != seg.GetNumOfRows() {
|
|
log.Warn("segment row number meta inconsistent with bin log row count and will be corrected",
|
|
zap.Int64("segment ID", seg.GetID()),
|
|
zap.Int64("segment meta row count (wrong)", seg.GetNumOfRows()),
|
|
zap.Int64("segment bin log row count (correct)", newCount))
|
|
// Update the corrected row count.
|
|
segCloned.NumOfRows = newCount
|
|
}
|
|
}
|
|
|
|
// CalcRowCountFromBinLog calculates # of rows of a segment from bin logs
|
|
func CalcRowCountFromBinLog(seg *datapb.SegmentInfo) int64 {
|
|
var rowCt int64
|
|
if len(seg.GetBinlogs()) > 0 {
|
|
for _, ct := range seg.GetBinlogs()[0].GetBinlogs() {
|
|
rowCt += ct.GetEntriesNum()
|
|
}
|
|
}
|
|
return rowCt
|
|
}
|