Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
milvus
提交
36cb2479
milvus
项目概览
BaiXuePrincess
/
milvus
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
milvus
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
36cb2479
编写于
7月 04, 2020
作者:
S
shengjun.li
提交者:
GitHub
7月 04, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Let codec singleton (#2742)
Signed-off-by:
N
shengjun.li
<
shengjun.li@zilliz.com
>
上级
004c2011
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
64 addition
and
110 deletion
+64
-110
core/src/codecs/Codec.h
core/src/codecs/Codec.h
+19
-19
core/src/codecs/VectorIndexFormat.h
core/src/codecs/VectorIndexFormat.h
+2
-2
core/src/codecs/default/DefaultAttrsFormat.cpp
core/src/codecs/default/DefaultAttrsFormat.cpp
+0
-8
core/src/codecs/default/DefaultAttrsFormat.h
core/src/codecs/default/DefaultAttrsFormat.h
+0
-3
core/src/codecs/default/DefaultAttrsIndexFormat.cpp
core/src/codecs/default/DefaultAttrsIndexFormat.cpp
+0
-4
core/src/codecs/default/DefaultAttrsIndexFormat.h
core/src/codecs/default/DefaultAttrsIndexFormat.h
+0
-3
core/src/codecs/default/DefaultCodec.cpp
core/src/codecs/default/DefaultCodec.cpp
+6
-0
core/src/codecs/default/DefaultCodec.h
core/src/codecs/default/DefaultCodec.h
+5
-1
core/src/codecs/default/DefaultDeletedDocsFormat.cpp
core/src/codecs/default/DefaultDeletedDocsFormat.cpp
+0
-6
core/src/codecs/default/DefaultDeletedDocsFormat.h
core/src/codecs/default/DefaultDeletedDocsFormat.h
+0
-3
core/src/codecs/default/DefaultIdBloomFilterFormat.cpp
core/src/codecs/default/DefaultIdBloomFilterFormat.cpp
+0
-4
core/src/codecs/default/DefaultIdBloomFilterFormat.h
core/src/codecs/default/DefaultIdBloomFilterFormat.h
+0
-3
core/src/codecs/default/DefaultVectorIndexFormat.cpp
core/src/codecs/default/DefaultVectorIndexFormat.cpp
+8
-13
core/src/codecs/default/DefaultVectorIndexFormat.h
core/src/codecs/default/DefaultVectorIndexFormat.h
+4
-9
core/src/codecs/default/DefaultVectorsFormat.cpp
core/src/codecs/default/DefaultVectorsFormat.cpp
+0
-10
core/src/codecs/default/DefaultVectorsFormat.h
core/src/codecs/default/DefaultVectorsFormat.h
+0
-3
core/src/segment/SegmentReader.cpp
core/src/segment/SegmentReader.cpp
+11
-11
core/src/segment/SegmentWriter.cpp
core/src/segment/SegmentWriter.cpp
+9
-8
未找到文件。
core/src/codecs/Codec.h
浏览文件 @
36cb2479
...
...
@@ -24,6 +24,7 @@
#include "IdIndexFormat.h"
#include "VectorIndexFormat.h"
#include "VectorsFormat.h"
#include "utils/Exception.h"
namespace
milvus
{
namespace
codec
{
...
...
@@ -31,35 +32,34 @@ namespace codec {
class
Codec
{
public:
virtual
VectorsFormatPtr
GetVectorsFormat
()
=
0
;
GetVectorsFormat
()
{
throw
Exception
(
SERVER_UNSUPPORTED_ERROR
,
"vectors not supported"
);
}
virtual
AttrsFormatPtr
GetAttrsFormat
()
=
0
;
GetAttrsFormat
()
{
throw
Exception
(
SERVER_UNSUPPORTED_ERROR
,
"attr not supported"
);
}
virtual
VectorIndexFormatPtr
GetVectorIndexFormat
()
=
0
;
GetVectorIndexFormat
()
{
throw
Exception
(
SERVER_UNSUPPORTED_ERROR
,
"vectors index not supported"
);
}
virtual
AttrsIndexFormatPtr
GetAttrsIndexFormat
()
=
0
;
GetAttrsIndexFormat
()
{
throw
Exception
(
SERVER_UNSUPPORTED_ERROR
,
"attr index not supported"
);
}
virtual
DeletedDocsFormatPtr
GetDeletedDocsFormat
()
=
0
;
GetDeletedDocsFormat
()
{
throw
Exception
(
SERVER_UNSUPPORTED_ERROR
,
"delete doc index not supported"
);
}
virtual
IdBloomFilterFormatPtr
GetIdBloomFilterFormat
()
=
0
;
// TODO(zhiru)
/*
virtual AttrsFormat
GetAttrsFormat() = 0;
virtual AttrsIndexFormat
GetAttrsIndexFormat() = 0;
virtual IdIndexFormat
GetIdIndexFormat() = 0;
*/
GetIdBloomFilterFormat
()
{
throw
Exception
(
SERVER_UNSUPPORTED_ERROR
,
"id bloom filter not supported"
);
}
};
}
// namespace codec
...
...
core/src/codecs/VectorIndexFormat.h
浏览文件 @
36cb2479
...
...
@@ -36,8 +36,8 @@ class VectorIndexFormat {
const
segment
::
VectorIndexPtr
&
vector_index
)
=
0
;
virtual
void
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
location
,
knowhere
::
BinaryPtr
raw_data
,
segment
::
VectorIndexPtr
&
vector_index
)
{
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
location
,
const
std
::
string
&
extern_key
,
const
knowhere
::
BinaryPtr
&
extern_data
,
segment
::
VectorIndexPtr
&
vector_index
)
{
}
};
...
...
core/src/codecs/default/DefaultAttrsFormat.cpp
浏览文件 @
36cb2479
...
...
@@ -78,8 +78,6 @@ DefaultAttrsFormat::read_uids_internal(const storage::FSHandlerPtr& fs_ptr, cons
void
DefaultAttrsFormat
::
read
(
const
milvus
::
storage
::
FSHandlerPtr
&
fs_ptr
,
milvus
::
segment
::
AttrsPtr
&
attrs_read
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
auto
is_directory
=
boost
::
filesystem
::
is_directory
(
dir_path
);
fiu_do_on
(
"read_id_directory_false"
,
is_directory
=
false
);
...
...
@@ -120,8 +118,6 @@ DefaultAttrsFormat::read(const milvus::storage::FSHandlerPtr& fs_ptr, milvus::se
void
DefaultAttrsFormat
::
write
(
const
milvus
::
storage
::
FSHandlerPtr
&
fs_ptr
,
const
milvus
::
segment
::
AttrsPtr
&
attrs_ptr
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
TimeRecorder
rc
(
"write attributes"
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
...
...
@@ -195,8 +191,6 @@ DefaultAttrsFormat::write(const milvus::storage::FSHandlerPtr& fs_ptr, const mil
void
DefaultAttrsFormat
::
read_attrs
(
const
milvus
::
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
field_name
,
off_t
offset
,
size_t
num_bytes
,
std
::
vector
<
uint8_t
>&
raw_attrs
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
if
(
!
boost
::
filesystem
::
is_directory
(
dir_path
))
{
std
::
string
err_msg
=
"Directory: "
+
dir_path
+
"does not exist"
;
...
...
@@ -222,8 +216,6 @@ DefaultAttrsFormat::read_attrs(const milvus::storage::FSHandlerPtr& fs_ptr, cons
void
DefaultAttrsFormat
::
read_uids
(
const
milvus
::
storage
::
FSHandlerPtr
&
fs_ptr
,
std
::
vector
<
int64_t
>&
uids
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
auto
is_directory
=
boost
::
filesystem
::
is_directory
(
dir_path
);
fiu_do_on
(
"is_directory_false"
,
is_directory
=
false
);
...
...
core/src/codecs/default/DefaultAttrsFormat.h
浏览文件 @
36cb2479
...
...
@@ -17,7 +17,6 @@
#pragma once
#include <mutex>
#include <string>
#include <vector>
...
...
@@ -62,8 +61,6 @@ class DefaultAttrsFormat : public AttrsFormat {
read_uids_internal
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
,
std
::
vector
<
int64_t
>&
);
private:
std
::
mutex
mutex_
;
const
std
::
string
raw_attr_extension_
=
".ra"
;
const
std
::
string
user_id_extension_
=
".uid"
;
};
...
...
core/src/codecs/default/DefaultAttrsIndexFormat.cpp
浏览文件 @
36cb2479
...
...
@@ -139,8 +139,6 @@ DefaultAttrsIndexFormat::read_internal(const milvus::storage::FSHandlerPtr& fs_p
void
DefaultAttrsIndexFormat
::
read
(
const
milvus
::
storage
::
FSHandlerPtr
&
fs_ptr
,
milvus
::
segment
::
AttrsIndexPtr
&
attrs_index
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
if
(
!
boost
::
filesystem
::
is_directory
(
dir_path
))
{
std
::
string
err_msg
=
"Directory: "
+
dir_path
+
"does not exist"
;
...
...
@@ -170,8 +168,6 @@ DefaultAttrsIndexFormat::read(const milvus::storage::FSHandlerPtr& fs_ptr,
void
DefaultAttrsIndexFormat
::
write
(
const
milvus
::
storage
::
FSHandlerPtr
&
fs_ptr
,
const
milvus
::
segment
::
AttrsIndexPtr
&
attrs_index
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
milvus
::
TimeRecorder
recorder
(
"write_index"
);
recorder
.
RecordSection
(
"Start"
);
...
...
core/src/codecs/default/DefaultAttrsIndexFormat.h
浏览文件 @
36cb2479
...
...
@@ -18,7 +18,6 @@
#pragma once
#include <src/db/meta/MetaTypes.h>
#include <mutex>
#include <string>
#include <vector>
...
...
@@ -56,8 +55,6 @@ class DefaultAttrsIndexFormat : public AttrsIndexFormat {
create_structured_index
(
const
engine
::
meta
::
hybrid
::
DataType
data_type
);
private:
std
::
mutex
mutex_
;
const
std
::
string
attr_index_extension_
=
".idx"
;
};
...
...
core/src/codecs/default/DefaultCodec.cpp
浏览文件 @
36cb2479
...
...
@@ -29,6 +29,12 @@
namespace
milvus
{
namespace
codec
{
DefaultCodec
&
DefaultCodec
::
instance
()
{
static
DefaultCodec
s_instance
;
return
s_instance
;
}
DefaultCodec
::
DefaultCodec
()
{
vectors_format_ptr_
=
std
::
make_shared
<
DefaultVectorsFormat
>
();
attrs_format_ptr_
=
std
::
make_shared
<
DefaultAttrsFormat
>
();
...
...
core/src/codecs/default/DefaultCodec.h
浏览文件 @
36cb2479
...
...
@@ -24,7 +24,8 @@ namespace codec {
class
DefaultCodec
:
public
Codec
{
public:
DefaultCodec
();
static
DefaultCodec
&
instance
();
VectorsFormatPtr
GetVectorsFormat
()
override
;
...
...
@@ -44,6 +45,9 @@ class DefaultCodec : public Codec {
IdBloomFilterFormatPtr
GetIdBloomFilterFormat
()
override
;
private:
DefaultCodec
();
private:
VectorsFormatPtr
vectors_format_ptr_
;
AttrsFormatPtr
attrs_format_ptr_
;
...
...
core/src/codecs/default/DefaultDeletedDocsFormat.cpp
浏览文件 @
36cb2479
...
...
@@ -36,8 +36,6 @@ namespace codec {
void
DefaultDeletedDocsFormat
::
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
segment
::
DeletedDocsPtr
&
deleted_docs
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
const
std
::
string
del_file_path
=
dir_path
+
"/"
+
deleted_docs_filename_
;
...
...
@@ -76,8 +74,6 @@ DefaultDeletedDocsFormat::read(const storage::FSHandlerPtr& fs_ptr, segment::Del
void
DefaultDeletedDocsFormat
::
write
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
segment
::
DeletedDocsPtr
&
deleted_docs
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
const
std
::
string
del_file_path
=
dir_path
+
"/"
+
deleted_docs_filename_
;
...
...
@@ -148,8 +144,6 @@ DefaultDeletedDocsFormat::write(const storage::FSHandlerPtr& fs_ptr, const segme
void
DefaultDeletedDocsFormat
::
readSize
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
size_t
&
size
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
const
std
::
string
del_file_path
=
dir_path
+
"/"
+
deleted_docs_filename_
;
...
...
core/src/codecs/default/DefaultDeletedDocsFormat.h
浏览文件 @
36cb2479
...
...
@@ -17,7 +17,6 @@
#pragma once
#include <mutex>
#include <string>
#include "codecs/DeletedDocsFormat.h"
...
...
@@ -48,8 +47,6 @@ class DefaultDeletedDocsFormat : public DeletedDocsFormat {
operator
=
(
DefaultDeletedDocsFormat
&&
)
=
delete
;
private:
std
::
mutex
mutex_
;
const
std
::
string
deleted_docs_filename_
=
"deleted_docs"
;
};
...
...
core/src/codecs/default/DefaultIdBloomFilterFormat.cpp
浏览文件 @
36cb2479
...
...
@@ -32,8 +32,6 @@ constexpr double bloom_filter_error_rate = 0.01;
void
DefaultIdBloomFilterFormat
::
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
segment
::
IdBloomFilterPtr
&
id_bloom_filter_ptr
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
const
std
::
string
bloom_filter_file_path
=
dir_path
+
"/"
+
bloom_filter_filename_
;
scaling_bloom_t
*
bloom_filter
=
...
...
@@ -51,8 +49,6 @@ DefaultIdBloomFilterFormat::read(const storage::FSHandlerPtr& fs_ptr, segment::I
void
DefaultIdBloomFilterFormat
::
write
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
segment
::
IdBloomFilterPtr
&
id_bloom_filter_ptr
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
const
std
::
string
bloom_filter_file_path
=
dir_path
+
"/"
+
bloom_filter_filename_
;
if
(
scaling_bloom_flush
(
id_bloom_filter_ptr
->
GetBloomFilter
())
==
-
1
)
{
...
...
core/src/codecs/default/DefaultIdBloomFilterFormat.h
浏览文件 @
36cb2479
...
...
@@ -17,7 +17,6 @@
#pragma once
#include <mutex>
#include <string>
#include "codecs/IdBloomFilterFormat.h"
...
...
@@ -50,8 +49,6 @@ class DefaultIdBloomFilterFormat : public IdBloomFilterFormat {
operator
=
(
DefaultIdBloomFilterFormat
&&
)
=
delete
;
private:
std
::
mutex
mutex_
;
const
std
::
string
bloom_filter_filename_
=
"bloom_filter"
;
};
...
...
core/src/codecs/default/DefaultVectorIndexFormat.cpp
浏览文件 @
36cb2479
...
...
@@ -32,7 +32,7 @@ namespace codec {
knowhere
::
VecIndexPtr
DefaultVectorIndexFormat
::
read_internal
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
path
,
knowhere
::
BinaryPtr
raw
_data
)
{
const
std
::
string
&
extern_key
,
const
knowhere
::
BinaryPtr
&
extern
_data
)
{
milvus
::
TimeRecorder
recorder
(
"read_index"
);
knowhere
::
BinarySet
load_data_list
;
...
...
@@ -92,10 +92,10 @@ DefaultVectorIndexFormat::read_internal(const storage::FSHandlerPtr& fs_ptr, con
auto
index
=
vec_index_factory
.
CreateVecIndex
(
knowhere
::
OldIndexTypeToStr
(
current_type
),
knowhere
::
IndexMode
::
MODE_CPU
);
if
(
index
!=
nullptr
)
{
if
(
raw
_data
!=
nullptr
)
{
LOG_ENGINE_DEBUG_
<<
"load index with
row data "
<<
raw
_data
->
size
;
load_data_list
.
Append
(
RAW_DATA
,
raw
_data
);
length
+=
raw
_data
->
size
;
if
(
extern
_data
!=
nullptr
)
{
LOG_ENGINE_DEBUG_
<<
"load index with
"
<<
extern_key
<<
" "
<<
extern
_data
->
size
;
load_data_list
.
Append
(
extern_key
,
extern
_data
);
length
+=
extern
_data
->
size
;
}
index
->
Load
(
load_data_list
);
...
...
@@ -110,8 +110,6 @@ DefaultVectorIndexFormat::read_internal(const storage::FSHandlerPtr& fs_ptr, con
void
DefaultVectorIndexFormat
::
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
location
,
segment
::
VectorIndexPtr
&
vector_index
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
if
(
!
boost
::
filesystem
::
is_directory
(
dir_path
))
{
std
::
string
err_msg
=
"Directory: "
+
dir_path
+
"does not exist"
;
...
...
@@ -125,9 +123,8 @@ DefaultVectorIndexFormat::read(const storage::FSHandlerPtr& fs_ptr, const std::s
void
DefaultVectorIndexFormat
::
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
location
,
knowhere
::
BinaryPtr
raw_data
,
segment
::
VectorIndexPtr
&
vector_index
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
const
std
::
string
&
extern_key
,
const
knowhere
::
BinaryPtr
&
extern_data
,
segment
::
VectorIndexPtr
&
vector_index
)
{
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
if
(
!
boost
::
filesystem
::
is_directory
(
dir_path
))
{
std
::
string
err_msg
=
"Directory: "
+
dir_path
+
"does not exist"
;
...
...
@@ -135,15 +132,13 @@ DefaultVectorIndexFormat::read(const storage::FSHandlerPtr& fs_ptr, const std::s
throw
Exception
(
SERVER_INVALID_ARGUMENT
,
err_msg
);
}
knowhere
::
VecIndexPtr
index
=
read_internal
(
fs_ptr
,
location
,
raw
_data
);
knowhere
::
VecIndexPtr
index
=
read_internal
(
fs_ptr
,
location
,
extern_key
,
extern
_data
);
vector_index
->
SetVectorIndex
(
index
);
}
void
DefaultVectorIndexFormat
::
write
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
location
,
const
segment
::
VectorIndexPtr
&
vector_index
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
milvus
::
TimeRecorder
recorder
(
"write_index"
);
knowhere
::
VecIndexPtr
index
=
vector_index
->
GetVectorIndex
();
...
...
core/src/codecs/default/DefaultVectorIndexFormat.h
浏览文件 @
36cb2479
...
...
@@ -17,7 +17,6 @@
#pragma once
#include <mutex>
#include <string>
#include "codecs/VectorIndexFormat.h"
...
...
@@ -34,8 +33,8 @@ class DefaultVectorIndexFormat : public VectorIndexFormat {
segment
::
VectorIndexPtr
&
vector_index
)
override
;
void
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
location
,
knowhere
::
BinaryPtr
raw_data
,
segment
::
VectorIndexPtr
&
vector_index
)
override
;
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
location
,
const
std
::
string
&
extern_key
,
const
knowhere
::
BinaryPtr
&
extern_data
,
segment
::
VectorIndexPtr
&
vector_index
)
override
;
void
write
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
location
,
...
...
@@ -52,12 +51,8 @@ class DefaultVectorIndexFormat : public VectorIndexFormat {
private:
knowhere
::
VecIndexPtr
read_internal
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
path
,
knowhere
::
BinaryPtr
raw_data
=
nullptr
);
private:
std
::
mutex
mutex_
;
const
std
::
string
vector_index_extension_
=
""
;
read_internal
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
std
::
string
&
path
,
const
std
::
string
&
extern_key
=
""
,
const
knowhere
::
BinaryPtr
&
extern_data
=
nullptr
);
};
}
// namespace codec
...
...
core/src/codecs/default/DefaultVectorsFormat.cpp
浏览文件 @
36cb2479
...
...
@@ -98,8 +98,6 @@ DefaultVectorsFormat::read_uids_internal(const storage::FSHandlerPtr& fs_ptr, co
void
DefaultVectorsFormat
::
read
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
segment
::
VectorsPtr
&
vectors_read
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
if
(
!
boost
::
filesystem
::
is_directory
(
dir_path
))
{
std
::
string
err_msg
=
"Directory: "
+
dir_path
+
"does not exist"
;
...
...
@@ -127,8 +125,6 @@ DefaultVectorsFormat::read(const storage::FSHandlerPtr& fs_ptr, segment::Vectors
void
DefaultVectorsFormat
::
write
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
const
segment
::
VectorsPtr
&
vectors
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
const
std
::
string
rv_file_path
=
dir_path
+
"/"
+
vectors
->
GetName
()
+
raw_vector_extension_
;
...
...
@@ -164,8 +160,6 @@ DefaultVectorsFormat::write(const storage::FSHandlerPtr& fs_ptr, const segment::
void
DefaultVectorsFormat
::
read_uids
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
std
::
vector
<
segment
::
doc_id_t
>&
uids
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
if
(
!
boost
::
filesystem
::
is_directory
(
dir_path
))
{
std
::
string
err_msg
=
"Directory: "
+
dir_path
+
"does not exist"
;
...
...
@@ -189,8 +183,6 @@ DefaultVectorsFormat::read_uids(const storage::FSHandlerPtr& fs_ptr, std::vector
void
DefaultVectorsFormat
::
read_vectors
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
knowhere
::
BinaryPtr
&
raw_vectors
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
if
(
!
boost
::
filesystem
::
is_directory
(
dir_path
))
{
std
::
string
err_msg
=
"Directory: "
+
dir_path
+
"does not exist"
;
...
...
@@ -215,8 +207,6 @@ DefaultVectorsFormat::read_vectors(const storage::FSHandlerPtr& fs_ptr, knowhere
void
DefaultVectorsFormat
::
read_vectors
(
const
storage
::
FSHandlerPtr
&
fs_ptr
,
off_t
offset
,
size_t
num_bytes
,
std
::
vector
<
uint8_t
>&
raw_vectors
)
{
const
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
string
dir_path
=
fs_ptr
->
operation_ptr_
->
GetDirectory
();
if
(
!
boost
::
filesystem
::
is_directory
(
dir_path
))
{
std
::
string
err_msg
=
"Directory: "
+
dir_path
+
"does not exist"
;
...
...
core/src/codecs/default/DefaultVectorsFormat.h
浏览文件 @
36cb2479
...
...
@@ -17,7 +17,6 @@
#pragma once
#include <mutex>
#include <string>
#include <vector>
...
...
@@ -70,8 +69,6 @@ class DefaultVectorsFormat : public VectorsFormat {
std
::
vector
<
segment
::
doc_id_t
>&
uids
);
private:
std
::
mutex
mutex_
;
const
std
::
string
raw_vector_extension_
=
".rv"
;
const
std
::
string
user_id_extension_
=
".uid"
;
};
...
...
core/src/segment/SegmentReader.cpp
浏览文件 @
36cb2479
...
...
@@ -21,6 +21,7 @@
#include "Vectors.h"
#include "codecs/default/DefaultCodec.h"
#include "knowhere/index/vector_index/VecIndex.h"
#include "storage/disk/DiskIOReader.h"
#include "storage/disk/DiskIOWriter.h"
#include "storage/disk/DiskOperation.h"
...
...
@@ -45,9 +46,8 @@ SegmentReader::LoadCache(bool& in_cache) {
Status
SegmentReader
::
Load
()
{
// TODO(zhiru)
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetVectorsFormat
()
->
read
(
fs_ptr_
,
segment_ptr_
->
vectors_ptr_
);
default_codec
.
GetAttrsFormat
()
->
read
(
fs_ptr_
,
segment_ptr_
->
attrs_ptr_
);
...
...
@@ -62,8 +62,8 @@ SegmentReader::Load() {
Status
SegmentReader
::
LoadVectors
(
off_t
offset
,
size_t
num_bytes
,
std
::
vector
<
uint8_t
>&
raw_vectors
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetVectorsFormat
()
->
read_vectors
(
fs_ptr_
,
offset
,
num_bytes
,
raw_vectors
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -77,8 +77,8 @@ SegmentReader::LoadVectors(off_t offset, size_t num_bytes, std::vector<uint8_t>&
Status
SegmentReader
::
LoadAttrs
(
const
std
::
string
&
field_name
,
off_t
offset
,
size_t
num_bytes
,
std
::
vector
<
uint8_t
>&
raw_attrs
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetAttrsFormat
()
->
read_attrs
(
fs_ptr_
,
field_name
,
offset
,
num_bytes
,
raw_attrs
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -91,8 +91,8 @@ SegmentReader::LoadAttrs(const std::string& field_name, off_t offset, size_t num
Status
SegmentReader
::
LoadUids
(
std
::
vector
<
doc_id_t
>&
uids
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetVectorsFormat
()
->
read_uids
(
fs_ptr_
,
uids
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -111,8 +111,8 @@ SegmentReader::GetSegment(SegmentPtr& segment_ptr) {
Status
SegmentReader
::
LoadVectorIndex
(
const
std
::
string
&
location
,
segment
::
VectorIndexPtr
&
vector_index_ptr
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetVectorIndexFormat
()
->
read
(
fs_ptr_
,
location
,
vector_index_ptr
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -125,12 +125,12 @@ SegmentReader::LoadVectorIndex(const std::string& location, segment::VectorIndex
Status
SegmentReader
::
LoadVectorIndexWithRawData
(
const
std
::
string
&
location
,
segment
::
VectorIndexPtr
&
vector_index_ptr
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
knowhere
::
BinaryPtr
raw_data
=
nullptr
;
default_codec
.
GetVectorsFormat
()
->
read_vectors
(
fs_ptr_
,
raw_data
);
default_codec
.
GetVectorIndexFormat
()
->
read
(
fs_ptr_
,
location
,
raw_data
,
vector_index_ptr
);
default_codec
.
GetVectorIndexFormat
()
->
read
(
fs_ptr_
,
location
,
RAW_DATA
,
raw_data
,
vector_index_ptr
);
}
catch
(
std
::
exception
&
e
)
{
std
::
string
err_msg
=
"Failed to load vector index with row data: "
+
std
::
string
(
e
.
what
());
LOG_ENGINE_ERROR_
<<
err_msg
;
...
...
@@ -141,8 +141,8 @@ SegmentReader::LoadVectorIndexWithRawData(const std::string& location, segment::
Status
SegmentReader
::
LoadBloomFilter
(
segment
::
IdBloomFilterPtr
&
id_bloom_filter_ptr
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetIdBloomFilterFormat
()
->
read
(
fs_ptr_
,
id_bloom_filter_ptr
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -155,8 +155,8 @@ SegmentReader::LoadBloomFilter(segment::IdBloomFilterPtr& id_bloom_filter_ptr) {
Status
SegmentReader
::
LoadDeletedDocs
(
segment
::
DeletedDocsPtr
&
deleted_docs_ptr
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetDeletedDocsFormat
()
->
read
(
fs_ptr_
,
deleted_docs_ptr
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -169,8 +169,8 @@ SegmentReader::LoadDeletedDocs(segment::DeletedDocsPtr& deleted_docs_ptr) {
Status
SegmentReader
::
ReadDeletedDocsSize
(
size_t
&
size
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetDeletedDocsFormat
()
->
readSize
(
fs_ptr_
,
size
);
}
catch
(
std
::
exception
&
e
)
{
...
...
core/src/segment/SegmentWriter.cpp
浏览文件 @
36cb2479
...
...
@@ -150,8 +150,8 @@ SegmentWriter::Serialize() {
Status
SegmentWriter
::
WriteVectors
()
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetVectorsFormat
()
->
write
(
fs_ptr_
,
segment_ptr_
->
vectors_ptr_
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -166,8 +166,8 @@ SegmentWriter::WriteVectors() {
Status
SegmentWriter
::
WriteAttrs
()
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetAttrsFormat
()
->
write
(
fs_ptr_
,
segment_ptr_
->
attrs_ptr_
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -186,8 +186,8 @@ SegmentWriter::WriteVectorIndex(const std::string& location) {
return
Status
(
SERVER_WRITE_ERROR
,
"Invalid parameter of WriteVectorIndex"
);
}
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetVectorIndexFormat
()
->
write
(
fs_ptr_
,
location
,
segment_ptr_
->
vector_index_ptr_
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -202,8 +202,8 @@ SegmentWriter::WriteVectorIndex(const std::string& location) {
Status
SegmentWriter
::
WriteAttrsIndex
()
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetAttrsIndexFormat
()
->
write
(
fs_ptr_
,
segment_ptr_
->
attrs_index_ptr_
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -218,8 +218,9 @@ SegmentWriter::WriteAttrsIndex() {
Status
SegmentWriter
::
WriteBloomFilter
()
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
TimeRecorder
recorder
(
"SegmentWriter::WriteBloomFilter"
);
...
...
@@ -250,8 +251,8 @@ SegmentWriter::WriteBloomFilter() {
Status
SegmentWriter
::
WriteDeletedDocs
()
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
DeletedDocsPtr
deleted_docs_ptr
=
std
::
make_shared
<
DeletedDocs
>
();
default_codec
.
GetDeletedDocsFormat
()
->
write
(
fs_ptr_
,
deleted_docs_ptr
);
...
...
@@ -267,8 +268,8 @@ SegmentWriter::WriteDeletedDocs() {
Status
SegmentWriter
::
WriteDeletedDocs
(
const
DeletedDocsPtr
&
deleted_docs
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetDeletedDocsFormat
()
->
write
(
fs_ptr_
,
deleted_docs
);
}
catch
(
std
::
exception
&
e
)
{
...
...
@@ -283,8 +284,8 @@ SegmentWriter::WriteDeletedDocs(const DeletedDocsPtr& deleted_docs) {
Status
SegmentWriter
::
WriteBloomFilter
(
const
IdBloomFilterPtr
&
id_bloom_filter_ptr
)
{
codec
::
DefaultCodec
default_codec
;
try
{
auto
&
default_codec
=
codec
::
DefaultCodec
::
instance
();
fs_ptr_
->
operation_ptr_
->
CreateDirectory
();
default_codec
.
GetIdBloomFilterFormat
()
->
write
(
fs_ptr_
,
id_bloom_filter_ptr
);
}
catch
(
std
::
exception
&
e
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录