未验证 提交 36cb2479 编写于 作者: S shengjun.li 提交者: GitHub

Let codec singleton (#2742)

Signed-off-by: Nshengjun.li <shengjun.li@zilliz.com>
上级 004c2011
......@@ -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
......
......@@ -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) {
}
};
......
......@@ -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);
......
......@@ -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";
};
......
......@@ -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");
......
......@@ -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";
};
......
......@@ -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>();
......
......@@ -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_;
......
......@@ -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_;
......
......@@ -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";
};
......
......@@ -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) {
......
......@@ -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";
};
......
......@@ -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();
......
......@@ -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
......
......@@ -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";
......
......@@ -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";
};
......
......@@ -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) {
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册