diff --git a/core/src/db/wal/WalBuffer.h b/core/src/db/wal/WalBuffer.h index ca4b7066c8..4834bce7f9 100644 --- a/core/src/db/wal/WalBuffer.h +++ b/core/src/db/wal/WalBuffer.h @@ -48,7 +48,7 @@ struct MXLogBufferHandler { uint8_t buf_idx; }; -using BufferPtr = std::shared_ptr; +using BufferPtr = std::shared_ptr; class MXLogBuffer { public: diff --git a/core/src/db/wal/WalFileHandler.cpp b/core/src/db/wal/WalFileHandler.cpp index 3d0afdb848..c5719cc248 100644 --- a/core/src/db/wal/WalFileHandler.cpp +++ b/core/src/db/wal/WalFileHandler.cpp @@ -41,7 +41,8 @@ MXLogFileHandler::Load(char* buf, uint32_t data_offset) { if (file_size > data_offset) { read_size = file_size - data_offset; fseek(p_file_, data_offset, SEEK_SET); - fread(buf, 1, read_size, p_file_); + auto ret = fread(buf, 1, read_size, p_file_); + __glibcxx_assert(ret == read_size); } } return read_size; @@ -56,7 +57,8 @@ MXLogFileHandler::Load(char* buf, uint32_t data_offset, uint32_t data_size) { } fseek(p_file_, data_offset, SEEK_SET); - fread(buf, 1, data_size, p_file_); + auto ret = fread(buf, 1, data_size, p_file_); + __glibcxx_assert(ret == data_size); } return true; } diff --git a/core/src/index/archive/VecIndex.cpp b/core/src/index/archive/VecIndex.cpp index 875c8f56fc..1e7a9e10a0 100644 --- a/core/src/index/archive/VecIndex.cpp +++ b/core/src/index/archive/VecIndex.cpp @@ -100,8 +100,7 @@ read_index(const std::string& location) { rp += bin_length; reader_ptr->seekg(rp); - auto binptr = std::make_shared(); - binptr.reset(bin); + std::shared_ptr binptr(bin); load_data_list.Append(std::string(meta, meta_length), binptr, bin_length); delete[] meta; } diff --git a/core/src/index/knowhere/knowhere/common/BinarySet.h b/core/src/index/knowhere/knowhere/common/BinarySet.h index e4acb99cef..ca9df76ab6 100644 --- a/core/src/index/knowhere/knowhere/common/BinarySet.h +++ b/core/src/index/knowhere/knowhere/common/BinarySet.h @@ -22,7 +22,7 @@ namespace milvus { namespace knowhere { struct Binary { - std::shared_ptr data; + std::shared_ptr data; int64_t size = 0; }; using BinaryPtr = std::shared_ptr; @@ -47,7 +47,7 @@ class BinarySet { } void - Append(const std::string& name, std::shared_ptr data, int64_t size) { + Append(const std::string& name, std::shared_ptr data, int64_t size) { auto binary = std::make_shared(); binary->data = data; binary->size = size; diff --git a/core/src/index/knowhere/knowhere/index/vector_index/FaissBaseBinaryIndex.cpp b/core/src/index/knowhere/knowhere/index/vector_index/FaissBaseBinaryIndex.cpp index 5915b0cd8b..568b70457f 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/FaissBaseBinaryIndex.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/FaissBaseBinaryIndex.cpp @@ -25,8 +25,7 @@ FaissBaseBinaryIndex::SerializeImpl(const IndexType& type) { MemoryIOWriter writer; faiss::write_index_binary(index, &writer); - auto data = std::make_shared(); - data.reset(writer.data_); + std::shared_ptr data(writer.data_); BinarySet res_set; res_set.Append("BinaryIVF", data, writer.rp); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/FaissBaseIndex.cpp b/core/src/index/knowhere/knowhere/index/vector_index/FaissBaseIndex.cpp index 18bff724f0..f0a6facefc 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/FaissBaseIndex.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/FaissBaseIndex.cpp @@ -28,8 +28,7 @@ FaissBaseIndex::SerializeImpl(const IndexType& type) { MemoryIOWriter writer; faiss::write_index(index, &writer); - auto data = std::make_shared(); - data.reset(writer.data_); + std::shared_ptr data(writer.data_); BinarySet res_set; // TODO(linxj): use virtual func Name() instead of raw string. diff --git a/core/src/index/knowhere/knowhere/index/vector_index/IndexAnnoy.cpp b/core/src/index/knowhere/knowhere/index/vector_index/IndexAnnoy.cpp index 7f7d774829..04c8390a43 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/IndexAnnoy.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/IndexAnnoy.cpp @@ -35,22 +35,19 @@ IndexAnnoy::Serialize(const Config& config) { KNOWHERE_THROW_MSG("index not initialize or trained"); } - BinarySet res_set; auto metric_type_length = metric_type_.length(); - uint8_t* p = new uint8_t[metric_type_length]; - std::shared_ptr metric_type(p, [](uint8_t* p) { delete[] p; }); - memcpy(p, metric_type_.data(), metric_type_.length()); + std::shared_ptr metric_type(new uint8_t[metric_type_length]); + memcpy(metric_type.get(), metric_type_.data(), metric_type_.length()); - uint8_t* p_dim = new uint8_t[sizeof(uint64_t)]; - std::shared_ptr dim_data(p_dim, [](uint8_t* p_dim) { delete[] p_dim; }); auto dim = Dim(); - memcpy(p_dim, &dim, sizeof(uint64_t)); + std::shared_ptr dim_data(new uint8_t[sizeof(uint64_t)]); + memcpy(dim_data.get(), &dim, sizeof(uint64_t)); auto index_length = index_->get_index_length(); - uint8_t* q = new uint8_t[index_length]; - std::shared_ptr index_data(q, [](uint8_t* q) { delete[] q; }); - memcpy(q, index_->get_index(), (size_t)index_length); + std::shared_ptr index_data(new uint8_t[index_length]); + memcpy(index_data.get(), index_->get_index(), (size_t)index_length); + BinarySet res_set; res_set.Append("annoy_metric_type", metric_type, metric_type_length); res_set.Append("annoy_dim", dim_data, sizeof(uint64_t)); res_set.Append("annoy_index_data", index_data, index_length); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/IndexHNSW.cpp b/core/src/index/knowhere/knowhere/index/vector_index/IndexHNSW.cpp index 6a1a445288..3f744cdb4a 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/IndexHNSW.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/IndexHNSW.cpp @@ -45,8 +45,7 @@ IndexHNSW::Serialize(const Config& config) { try { MemoryIOWriter writer; index_->saveIndex(writer); - auto data = std::make_shared(); - data.reset(writer.data_); + std::shared_ptr data(writer.data_); BinarySet res_set; res_set.Append("HNSW", data, writer.total); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/IndexNSG.cpp b/core/src/index/knowhere/knowhere/index/vector_index/IndexNSG.cpp index 47b5e7b7df..f437bee3c0 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/IndexNSG.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/IndexNSG.cpp @@ -44,8 +44,7 @@ NSG::Serialize(const Config& config) { MemoryIOWriter writer; impl::write_index(index, writer); - auto data = std::make_shared(); - data.reset(writer.data_); + std::shared_ptr data(writer.data_); BinarySet res_set; res_set.Append("NSG", data, writer.total); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/IndexSPTAG.cpp b/core/src/index/knowhere/knowhere/index/vector_index/IndexSPTAG.cpp index 51d3a1baf8..f457eb9bc1 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/IndexSPTAG.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/IndexSPTAG.cpp @@ -60,19 +60,19 @@ CPUSPTAGRNG::Serialize(const Config& config) { snprintf(cstr, length, "%s", index_config.c_str()); BinarySet binary_set; - auto sample = std::make_shared(); + std::shared_ptr sample; sample.reset(static_cast(index_blobs[0].Data())); - auto tree = std::make_shared(); + std::shared_ptr tree; tree.reset(static_cast(index_blobs[1].Data())); - auto graph = std::make_shared(); + std::shared_ptr graph; graph.reset(static_cast(index_blobs[2].Data())); - auto deleteid = std::make_shared(); + std::shared_ptr deleteid; deleteid.reset(static_cast(index_blobs[3].Data())); - auto metadata1 = std::make_shared(); + std::shared_ptr metadata1; metadata1.reset(static_cast(index_blobs[4].Data())); - auto metadata2 = std::make_shared(); + std::shared_ptr metadata2; metadata2.reset(static_cast(index_blobs[5].Data())); - auto x_cfg = std::make_shared(); + std::shared_ptr x_cfg; x_cfg.reset(static_cast((void*)cstr)); binary_set.Append("samples", sample, index_blobs[0].Length()); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIDMAP.cpp b/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIDMAP.cpp index c976520527..c2778c28b1 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIDMAP.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIDMAP.cpp @@ -52,8 +52,7 @@ GPUIDMAP::SerializeImpl(const IndexType& type) { faiss::write_index(host_index, &writer); delete host_index; } - auto data = std::make_shared(); - data.reset(writer.data_); + std::shared_ptr data(writer.data_); BinarySet res_set; res_set.Append("IVF", data, writer.rp); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp b/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp index 19f8229f6c..599f602fd7 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexGPUIVF.cpp @@ -102,8 +102,7 @@ GPUIVF::SerializeImpl(const IndexType& type) { faiss::write_index(host_index, &writer); delete host_index; } - auto data = std::make_shared(); - data.reset(writer.data_); + std::shared_ptr data(writer.data_); BinarySet res_set; res_set.Append("IVF", data, writer.rp); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp b/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp index edd6db1c6f..10db0c327f 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/gpu/IndexIVFSQHybrid.cpp @@ -227,8 +227,7 @@ IVFSQHybrid::SerializeImpl(const IndexType& type) { MemoryIOWriter writer; faiss::write_index(index_.get(), &writer); - auto data = std::make_shared(); - data.reset(writer.data_); + std::shared_ptr data(writer.data_); BinarySet res_set; res_set.Append("IVF", data, writer.rp); diff --git a/core/src/index/knowhere/knowhere/index/vector_index/helpers/FaissIO.cpp b/core/src/index/knowhere/knowhere/index/vector_index/helpers/FaissIO.cpp index 58142508a7..645d4f9064 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/helpers/FaissIO.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/helpers/FaissIO.cpp @@ -35,7 +35,7 @@ MemoryIOWriter::operator()(const void* ptr, size_t size, size_t nitems) { total = total_need * magic_num; auto new_data = new uint8_t[total]; memcpy((void*)new_data, (void*)data_, rp); - delete data_; + delete[] data_; data_ = new_data; memcpy((void*)(data_ + rp), ptr, size * nitems); diff --git a/core/src/index/unittest/test_binaryidmap.cpp b/core/src/index/unittest/test_binaryidmap.cpp index 2188068f35..5cd35f372a 100644 --- a/core/src/index/unittest/test_binaryidmap.cpp +++ b/core/src/index/unittest/test_binaryidmap.cpp @@ -112,8 +112,7 @@ TEST_P(BinaryIDMAPTest, binaryidmap_serialize) { serialize(filename, bin, load_data); binaryset.clear(); - auto data = std::make_shared(); - data.reset(load_data); + std::shared_ptr data(load_data); binaryset.Append("BinaryIVF", data, bin->size); index_->Load(binaryset); diff --git a/core/src/index/unittest/test_binaryivf.cpp b/core/src/index/unittest/test_binaryivf.cpp index 9dc5acd115..60b7e932a3 100644 --- a/core/src/index/unittest/test_binaryivf.cpp +++ b/core/src/index/unittest/test_binaryivf.cpp @@ -134,8 +134,7 @@ TEST_P(BinaryIVFTest, binaryivf_serialize) { serialize(filename, bin, load_data); binaryset.clear(); - auto data = std::make_shared(); - data.reset(load_data); + std::shared_ptr data(load_data); binaryset.Append("BinaryIVF", data, bin->size); index_->Load(binaryset); diff --git a/core/src/index/unittest/test_idmap.cpp b/core/src/index/unittest/test_idmap.cpp index 0a13a2528c..c884b979e3 100644 --- a/core/src/index/unittest/test_idmap.cpp +++ b/core/src/index/unittest/test_idmap.cpp @@ -126,8 +126,7 @@ TEST_F(IDMAPTest, idmap_serialize) { serialize(filename, bin, load_data); binaryset.clear(); - auto data = std::make_shared(); - data.reset(load_data); + std::shared_ptr data(load_data); binaryset.Append("IVF", data, bin->size); index_->Load(binaryset); diff --git a/core/src/index/unittest/test_ivf.cpp b/core/src/index/unittest/test_ivf.cpp index f318952725..a57b66ec1b 100644 --- a/core/src/index/unittest/test_ivf.cpp +++ b/core/src/index/unittest/test_ivf.cpp @@ -165,8 +165,7 @@ TEST_P(IVFTest, ivf_serialize) { serialize(filename, bin, load_data); binaryset.clear(); - auto data = std::make_shared(); - data.reset(load_data); + std::shared_ptr data(load_data); binaryset.Append("IVF", data, bin->size); index_->Load(binaryset); diff --git a/core/src/index/unittest/test_sptag.cpp b/core/src/index/unittest/test_sptag.cpp index a7a51ef1b0..42d257e3c5 100644 --- a/core/src/index/unittest/test_sptag.cpp +++ b/core/src/index/unittest/test_sptag.cpp @@ -124,8 +124,7 @@ TEST_P(SPTAGTest, sptag_serialize) { auto load_data = new uint8_t[bin_size]; reader(load_data, bin_size); - auto data = std::make_shared(); - data.reset(load_data); + std::shared_ptr data(load_data); load_data_list.Append(meta_list[i].first, data, bin_size); } diff --git a/core/unittest/db/test_wal.cpp b/core/unittest/db/test_wal.cpp index 9d3a35e658..8746c2cbf3 100644 --- a/core/unittest/db/test_wal.cpp +++ b/core/unittest/db/test_wal.cpp @@ -32,11 +32,13 @@ namespace { void MakeEmptyTestPath() { + pid_t ret; if (access(WAL_GTEST_PATH, 0) == 0) { - ::system("rm -rf " WAL_GTEST_PATH "*"); + ret = ::system("rm -rf " WAL_GTEST_PATH "*"); } else { - ::system("mkdir -m 777 -p " WAL_GTEST_PATH); + ret = ::system("mkdir -m 777 -p " WAL_GTEST_PATH); } + __glibcxx_assert(ret != -1); } } // namespace