Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
milvus
milvus
提交
cff80c9e
M
milvus
项目概览
milvus
/
milvus
大约 1 年 前同步成功
通知
261
Star
22476
Fork
2472
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cff80c9e
编写于
10月 09, 2020
作者:
G
groot
提交者:
GitHub
10月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine query code (#3913)
Signed-off-by:
N
groot
<
yihua.mo@zilliz.com
>
上级
dd5078ad
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
42 addition
and
61 deletion
+42
-61
core/src/db/DBImpl.cpp
core/src/db/DBImpl.cpp
+7
-53
core/src/db/SnapshotHandlers.cpp
core/src/db/SnapshotHandlers.cpp
+26
-3
core/src/db/SnapshotHandlers.h
core/src/db/SnapshotHandlers.h
+3
-1
core/src/db/SnapshotUtils.cpp
core/src/db/SnapshotUtils.cpp
+2
-1
core/src/db/SnapshotVisitor.cpp
core/src/db/SnapshotVisitor.cpp
+2
-2
core/src/db/SnapshotVisitor.h
core/src/db/SnapshotVisitor.h
+2
-1
未找到文件。
core/src/db/DBImpl.cpp
浏览文件 @
cff80c9e
...
...
@@ -20,7 +20,6 @@
#include "db/merge/MergeTask.h"
#include "db/snapshot/CompoundOperations.h"
#include "db/snapshot/EventExecutor.h"
#include "db/snapshot/IterateHandler.h"
#include "db/snapshot/OperationExecutor.h"
#include "db/snapshot/ResourceHelper.h"
#include "db/snapshot/ResourceTypes.h"
...
...
@@ -38,7 +37,6 @@
#include "segment/Utils.h"
#include "server/ValidationUtil.h"
#include "utils/Exception.h"
#include "utils/StringHelpFunctions.h"
#include "utils/TimeRecorder.h"
#include <fiu/fiu-local.h>
...
...
@@ -649,46 +647,10 @@ DBImpl::Query(const server::ContextPtr& context, const query::QueryPtr& query_pt
snapshot
::
ScopedSnapshotT
ss
;
STATUS_CHECK
(
snapshot
::
Snapshots
::
GetInstance
().
GetSnapshot
(
ss
,
query_ptr
->
collection_id
));
/* collect all valid segment */
std
::
vector
<
SegmentVisitor
::
Ptr
>
segment_visitors
;
auto
exec
=
[
&
](
const
snapshot
::
Segment
::
Ptr
&
segment
,
snapshot
::
SegmentIterator
*
handler
)
->
Status
{
auto
p_id
=
segment
->
GetPartitionId
();
auto
p_ptr
=
ss
->
GetResource
<
snapshot
::
Partition
>
(
p_id
);
auto
&
p_name
=
p_ptr
->
GetName
();
/* check partition match pattern */
bool
match
=
false
;
if
(
query_ptr
->
partitions
.
empty
())
{
match
=
true
;
}
else
{
for
(
auto
&
pattern
:
query_ptr
->
partitions
)
{
if
(
StringHelpFunctions
::
IsRegexMatch
(
p_name
,
pattern
))
{
match
=
true
;
break
;
}
}
}
if
(
match
)
{
auto
visitor
=
SegmentVisitor
::
Build
(
ss
,
segment
->
GetID
());
if
(
!
visitor
)
{
return
Status
(
milvus
::
SS_ERROR
,
"Cannot build segment visitor"
);
}
segment_visitors
.
push_back
(
visitor
);
}
return
Status
::
OK
();
};
auto
segment_iter
=
std
::
make_shared
<
snapshot
::
SegmentIterator
>
(
ss
,
exec
);
segment_iter
->
Iterate
();
STATUS_CHECK
(
segment_iter
->
GetStatus
());
LOG_ENGINE_DEBUG_
<<
LogOut
(
"Engine query begin, segment count: %ld"
,
segment_visitors
.
size
());
engine
::
snapshot
::
IDS_TYPE
segment_ids
;
for
(
auto
&
sv
:
segment_visitors
)
{
segment_ids
.
emplace_back
(
sv
->
GetSegment
()
->
GetID
());
}
SnapshotVisitor
ss_visitor
(
ss
);
snapshot
::
IDS_TYPE
segment_ids
;
STATUS_CHECK
(
ss_visitor
.
SegmentsToSearch
(
query_ptr
->
partitions
,
segment_ids
));
LOG_ENGINE_DEBUG_
<<
LogOut
(
"Engine query begin, segment count: %ld"
,
segment_ids
.
size
());
scheduler
::
SearchJobPtr
job
=
std
::
make_shared
<
scheduler
::
SearchJob
>
(
nullptr
,
ss
,
options_
,
query_ptr
,
segment_ids
);
...
...
@@ -760,17 +722,6 @@ DBImpl::ListIDInSegment(const std::string& collection_name, int64_t segment_id,
// remove delete id from the id list
segment
::
DeletedDocsPtr
deleted_docs_ptr
;
segment_reader
->
LoadDeletedDocs
(
deleted_docs_ptr
);
// if (deleted_docs_ptr) {
// const std::vector<offset_t>& delete_ids = deleted_docs_ptr->GetDeletedDocs();
// std::vector<offset_t> temp_ids;
// temp_ids.reserve(delete_ids.size());
// std::copy(delete_ids.begin(), delete_ids.end(), std::back_inserter(temp_ids));
// std::sort(temp_ids.begin(), temp_ids.end(), std::greater<>());
// for (auto offset : temp_ids) {
// entity_ids.erase(entity_ids.begin() + offset, entity_ids.begin() + offset + 1);
// }
// }
if
(
deleted_docs_ptr
)
{
// sorted-merge entities id and deleted offsets
const
std
::
vector
<
offset_t
>&
delete_offsets
=
deleted_docs_ptr
->
GetDeletedDocs
();
...
...
@@ -880,6 +831,7 @@ DBImpl::Compact(const std::shared_ptr<server::Context>& context, const std::stri
continue
;
// no deleted docs, no need to compact
}
// the segment row count is zero, drop it
auto
segment_commit
=
latest_ss
->
GetSegmentCommitBySegmentId
(
segment_id
);
auto
row_count
=
segment_commit
->
GetRowCount
();
if
(
row_count
==
0
)
{
...
...
@@ -895,11 +847,13 @@ DBImpl::Compact(const std::shared_ptr<server::Context>& context, const std::stri
continue
;
}
// delete rate less than threshold, skip compact
auto
deleted_count
=
deleted_docs
->
GetCount
();
if
(
double
(
deleted_count
)
/
(
row_count
+
deleted_count
)
<
threshold
)
{
continue
;
// no need to compact
}
// compact segment, the compact action is same as merge
snapshot
::
IDS_TYPE
ids
=
{
segment_id
};
MergeTask
merge_task
(
options_
,
latest_ss
,
ids
);
status
=
merge_task
.
Execute
();
...
...
core/src/db/SnapshotHandlers.cpp
浏览文件 @
cff80c9e
...
...
@@ -20,6 +20,7 @@
#include "db/snapshot/Snapshot.h"
#include "knowhere/index/vector_index/helpers/IndexParameter.h"
#include "segment/SegmentReader.h"
#include "utils/StringHelpFunctions.h"
#include <unordered_map>
#include <utility>
...
...
@@ -28,13 +29,35 @@ namespace milvus {
namespace
engine
{
///////////////////////////////////////////////////////////////////////////////
SegmentsToSearchCollector
::
SegmentsToSearchCollector
(
snapshot
::
ScopedSnapshotT
ss
,
snapshot
::
IDS_TYPE
&
segment_ids
)
:
BaseT
(
ss
),
segment_ids_
(
segment_ids
)
{
SegmentsToSearchCollector
::
SegmentsToSearchCollector
(
snapshot
::
ScopedSnapshotT
ss
,
const
std
::
vector
<
std
::
string
>&
partitions
,
snapshot
::
IDS_TYPE
&
segment_ids
)
:
BaseT
(
ss
),
partitions_
(
partitions
),
segment_ids_
(
segment_ids
)
{
}
Status
SegmentsToSearchCollector
::
Handle
(
const
snapshot
::
SegmentCommitPtr
&
segment_commit
)
{
segment_ids_
.
push_back
(
segment_commit
->
GetSegmentId
());
auto
p_id
=
segment_commit
->
GetPartitionId
();
auto
p_ptr
=
ss_
->
GetResource
<
snapshot
::
Partition
>
(
p_id
);
auto
&
p_name
=
p_ptr
->
GetName
();
/* check partition match pattern */
bool
match
=
false
;
if
(
partitions_
.
empty
())
{
match
=
true
;
}
else
{
for
(
auto
&
pattern
:
partitions_
)
{
if
(
StringHelpFunctions
::
IsRegexMatch
(
p_name
,
pattern
))
{
match
=
true
;
break
;
}
}
}
if
(
match
)
{
segment_ids_
.
push_back
(
segment_commit
->
GetSegmentId
());
}
return
Status
::
OK
();
}
...
...
core/src/db/SnapshotHandlers.h
浏览文件 @
cff80c9e
...
...
@@ -30,11 +30,13 @@ namespace engine {
struct
SegmentsToSearchCollector
:
public
snapshot
::
SegmentCommitIterator
{
using
ResourceT
=
snapshot
::
SegmentCommit
;
using
BaseT
=
snapshot
::
IterateHandler
<
ResourceT
>
;
SegmentsToSearchCollector
(
snapshot
::
ScopedSnapshotT
ss
,
snapshot
::
IDS_TYPE
&
segment_ids
);
SegmentsToSearchCollector
(
snapshot
::
ScopedSnapshotT
ss
,
const
std
::
vector
<
std
::
string
>&
partitions
,
snapshot
::
IDS_TYPE
&
segment_ids
);
Status
Handle
(
const
typename
ResourceT
::
Ptr
&
)
override
;
std
::
vector
<
std
::
string
>
partitions_
;
snapshot
::
IDS_TYPE
&
segment_ids_
;
};
...
...
core/src/db/SnapshotUtils.cpp
浏览文件 @
cff80c9e
...
...
@@ -200,7 +200,8 @@ GetSnapshotInfo(const std::string& collection_name, milvus::json& json_info) {
// just ensure segments listed in id order
snapshot
::
IDS_TYPE
segment_ids
;
auto
handler
=
std
::
make_shared
<
SegmentsToSearchCollector
>
(
ss
,
segment_ids
);
std
::
vector
<
std
::
string
>
partition_tags
;
auto
handler
=
std
::
make_shared
<
SegmentsToSearchCollector
>
(
ss
,
partition_tags
,
segment_ids
);
handler
->
Iterate
();
std
::
sort
(
segment_ids
.
begin
(),
segment_ids
.
end
());
...
...
core/src/db/SnapshotVisitor.cpp
浏览文件 @
cff80c9e
...
...
@@ -33,10 +33,10 @@ SnapshotVisitor::SnapshotVisitor(snapshot::ID_TYPE collection_id) {
}
Status
SnapshotVisitor
::
SegmentsToSearch
(
snapshot
::
IDS_TYPE
&
segment_ids
)
{
SnapshotVisitor
::
SegmentsToSearch
(
const
std
::
vector
<
std
::
string
>&
partitions
,
snapshot
::
IDS_TYPE
&
segment_ids
)
{
STATUS_CHECK
(
status_
);
auto
handler
=
std
::
make_shared
<
SegmentsToSearchCollector
>
(
ss_
,
segment_ids
);
auto
handler
=
std
::
make_shared
<
SegmentsToSearchCollector
>
(
ss_
,
partitions
,
segment_ids
);
handler
->
Iterate
();
return
handler
->
GetStatus
();
...
...
core/src/db/SnapshotVisitor.h
浏览文件 @
cff80c9e
...
...
@@ -17,6 +17,7 @@
#include <memory>
#include <set>
#include <string>
#include <vector>
namespace
milvus
{
namespace
engine
{
...
...
@@ -28,7 +29,7 @@ class SnapshotVisitor {
explicit
SnapshotVisitor
(
snapshot
::
ID_TYPE
collection_id
);
Status
SegmentsToSearch
(
snapshot
::
IDS_TYPE
&
segment_ids
);
SegmentsToSearch
(
const
std
::
vector
<
std
::
string
>&
partitions
,
snapshot
::
IDS_TYPE
&
segment_ids
);
Status
SegmentsToIndex
(
const
std
::
string
&
field_name
,
snapshot
::
IDS_TYPE
&
segment_ids
,
bool
force_build
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录