2023-03-27 00:42:00 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package pkoracle
|
|
|
|
|
|
|
|
import (
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
2023-03-27 00:42:00 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2023-03-27 00:42:00 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Candidate is the interface for pk oracle candidate.
|
|
|
|
type Candidate interface {
|
|
|
|
// MayPkExist checks whether primary key could exists in this candidate.
|
enhance: Use Blocked Bloom Filter instead of basic bloom fitler impl. (#33405)
issue: #32995
To speed up the construction and querying of Bloom filters, we chose a
blocked Bloom filter instead of a basic Bloom filter implementation.
WARN: This PR is compatible with old version bf impl, but if fall back
to old milvus version, it may causes bloom filter deserialize failed.
In single Bloom filter test cases with a capacity of 1,000,000 and a
false positive rate (FPR) of 0.001, the blocked Bloom filter is 5 times
faster than the basic Bloom filter in both querying and construction, at
the cost of a 30% increase in memory usage.
- Block BF construct time {"time": "54.128131ms"}
- Block BF size {"size": 3021578}
- Block BF Test cost {"time": "55.407352ms"}
- Basic BF construct time {"time": "210.262183ms"}
- Basic BF size {"size": 2396308}
- Basic BF Test cost {"time": "192.596229ms"}
In multi Bloom filter test cases with a capacity of 100,000, an FPR of
0.001, and 100 Bloom filters, we reuse the primary key locations for all
Bloom filters to avoid repeated hash computations. As a result, the
blocked Bloom filter is also 5 times faster than the basic Bloom filter
in querying.
- Block BF TestLocation cost {"time": "529.97183ms"}
- Basic BF TestLocation cost {"time": "3.197430181s"}
---------
Signed-off-by: Wei Liu <wei.liu@zilliz.com>
2024-05-31 17:49:45 +08:00
|
|
|
MayPkExist(lc *storage.LocationsCache) bool
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
ID() int64
|
|
|
|
Partition() int64
|
|
|
|
Type() commonpb.SegmentState
|
|
|
|
}
|
|
|
|
|
|
|
|
type candidateWithWorker struct {
|
|
|
|
Candidate
|
|
|
|
workerID int64
|
|
|
|
}
|
|
|
|
|
|
|
|
// CandidateFilter filter type for candidate.
|
|
|
|
type CandidateFilter func(candidate candidateWithWorker) bool
|
|
|
|
|
|
|
|
// WithSegmentType returns CandiateFilter with provided segment type.
|
|
|
|
func WithSegmentType(typ commonpb.SegmentState) CandidateFilter {
|
|
|
|
return func(candidate candidateWithWorker) bool {
|
|
|
|
return candidate.Type() == typ
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithWorkerID returns CandidateFilter with provided worker id.
|
|
|
|
func WithWorkerID(workerID int64) CandidateFilter {
|
|
|
|
return func(candidate candidateWithWorker) bool {
|
|
|
|
return candidate.workerID == workerID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithSegmentIDs returns CandidateFilter with provided segment ids.
|
|
|
|
func WithSegmentIDs(segmentIDs ...int64) CandidateFilter {
|
|
|
|
set := typeutil.NewSet[int64]()
|
|
|
|
set.Insert(segmentIDs...)
|
|
|
|
return func(candidate candidateWithWorker) bool {
|
|
|
|
return set.Contain(candidate.ID())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithPartitionID returns CandidateFilter with provided partitionID.
|
|
|
|
func WithPartitionID(partitionID int64) CandidateFilter {
|
|
|
|
return func(candidate candidateWithWorker) bool {
|
2024-03-20 19:01:05 +08:00
|
|
|
return candidate.Partition() == partitionID || partitionID == common.AllPartitionsID
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
}
|