diff --git a/.codacy.yaml b/.codacy.yaml index f6ccef0791..230128ed74 100644 --- a/.codacy.yaml +++ b/.codacy.yaml @@ -1,12 +1,12 @@ exclude_paths: - - 'core/src/index/thirdparty/**' - - 'sdk/build-support/**' - - 'sdk/thirdparty/**' - 'core/build-support/**' + - 'core/src/index/thirdparty/**' - 'core/src/grpc/gen-milvus/**' - 'core/src/grpc/gen-status/**' - - 'sdk/grpc-gen/**' - 'core/thirdparty/**' + - 'sdk/build-support/**' + - 'sdk/grpc-gen/**' + - 'sdk/thirdparty/**' - 'ci/**' - 'docker/**' - 'docs/**' diff --git a/core/src/codecs/StructuredIndexFormat.cpp b/core/src/codecs/StructuredIndexFormat.cpp index 0087ac7bca..ce4748c80f 100644 --- a/core/src/codecs/StructuredIndexFormat.cpp +++ b/core/src/codecs/StructuredIndexFormat.cpp @@ -163,7 +163,7 @@ StructuredIndexFormat::Write(const milvus::storage::FSHandlerPtr& fs_ptr, const auto meta = iter.first.c_str(); size_t meta_length = iter.first.length(); fs_ptr->writer_ptr_->Write(&meta_length, sizeof(meta_length)); - fs_ptr->writer_ptr_->Write(const_cast(meta), meta_length); + fs_ptr->writer_ptr_->Write(meta, meta_length); auto binary = iter.second; int64_t binary_length = binary->size; diff --git a/core/src/codecs/VectorIndexFormat.cpp b/core/src/codecs/VectorIndexFormat.cpp index e5d7837310..04ab2f0303 100644 --- a/core/src/codecs/VectorIndexFormat.cpp +++ b/core/src/codecs/VectorIndexFormat.cpp @@ -194,7 +194,7 @@ VectorIndexFormat::WriteIndex(const storage::FSHandlerPtr& fs_ptr, const std::st auto meta = iter.first.c_str(); size_t meta_length = iter.first.length(); fs_ptr->writer_ptr_->Write(&meta_length, sizeof(meta_length)); - fs_ptr->writer_ptr_->Write(const_cast(meta), meta_length); + fs_ptr->writer_ptr_->Write(meta, meta_length); auto binary = iter.second; int64_t binary_length = binary->size; diff --git a/core/src/config/ConfigMgr.cpp b/core/src/config/ConfigMgr.cpp index b7481cc6e6..994737aac3 100644 --- a/core/src/config/ConfigMgr.cpp +++ b/core/src/config/ConfigMgr.cpp @@ -223,7 +223,7 @@ ConfigMgr::Set(const std::string& name, const std::string& value, bool update) { throw ConfigStatus(SetReturn::IMMUTABLE, "Config " + name + " is not modifiable"); } } catch (ConfigStatus& cs) { - throw cs; + throw; } catch (...) { throw "Config " + name + " not found."; } diff --git a/core/src/db/IDGenerator.cpp b/core/src/db/IDGenerator.cpp index 4bdb62cfcf..e026ee10d5 100644 --- a/core/src/db/IDGenerator.cpp +++ b/core/src/db/IDGenerator.cpp @@ -12,7 +12,6 @@ #include "db/IDGenerator.h" #include "utils/Log.h" -#include #include #include #include diff --git a/core/src/db/SnapshotUtils.cpp b/core/src/db/SnapshotUtils.cpp index b87654ec9c..995d105640 100644 --- a/core/src/db/SnapshotUtils.cpp +++ b/core/src/db/SnapshotUtils.cpp @@ -153,7 +153,7 @@ IsVectorField(const engine::snapshot::FieldPtr& field) { return false; } - engine::DataType ftype = static_cast(field->GetFtype()); + auto ftype = static_cast(field->GetFtype()); return IsVectorField(ftype); } diff --git a/core/src/db/insert/MemManagerFactory.cpp b/core/src/db/insert/MemManagerFactory.cpp index 5fb2084bc8..38df653d4c 100644 --- a/core/src/db/insert/MemManagerFactory.cpp +++ b/core/src/db/insert/MemManagerFactory.cpp @@ -11,16 +11,8 @@ #include "db/insert/MemManagerFactory.h" #include "MemManagerImpl.h" -#include "utils/Exception.h" -#include "utils/Log.h" -#include -#include -#include #include -#include -#include -#include namespace milvus { namespace engine { diff --git a/core/src/db/insert/MemManagerFactory.h b/core/src/db/insert/MemManagerFactory.h index bc1c6f74bb..d392881356 100644 --- a/core/src/db/insert/MemManagerFactory.h +++ b/core/src/db/insert/MemManagerFactory.h @@ -13,8 +13,6 @@ #include "MemManager.h" -#include - namespace milvus { namespace engine { diff --git a/core/src/db/meta/backend/SqliteEngine.h b/core/src/db/meta/backend/SqliteEngine.h index 9ce86ce043..d3fa023c70 100644 --- a/core/src/db/meta/backend/SqliteEngine.h +++ b/core/src/db/meta/backend/SqliteEngine.h @@ -24,8 +24,7 @@ namespace milvus::engine::meta { class SqliteEngine : public MetaEngine { public: explicit SqliteEngine(const DBMetaOptions& options); - - ~SqliteEngine(); + virtual ~SqliteEngine(); public: Status diff --git a/core/src/db/snapshot/Operations.h b/core/src/db/snapshot/Operations.h index 53ac51cde5..3aa7f4eaf8 100644 --- a/core/src/db/snapshot/Operations.h +++ b/core/src/db/snapshot/Operations.h @@ -122,7 +122,8 @@ class Operations : public std::enable_shared_from_this { virtual Status operator()(StorePtr store); - virtual Status + + Status Push(bool sync = true); virtual Status diff --git a/core/src/db/snapshot/ResourceOperations.cpp b/core/src/db/snapshot/ResourceOperations.cpp index a52e0cb53c..05b9d01843 100644 --- a/core/src/db/snapshot/ResourceOperations.cpp +++ b/core/src/db/snapshot/ResourceOperations.cpp @@ -114,8 +114,9 @@ PartitionCommitOperation::DoExecute(StorePtr store) { row_cnt = resource_->GetRowCount(); size = resource_->GetSize(); auto erase_sc = [&](SegmentCommitPtr& sc) { - if (!sc) + if (!sc) { return; + } auto prev_sc = GetStartedSS()->GetSegmentCommitBySegmentId(sc->GetSegmentId()); if (prev_sc) { resource_->GetMappings().erase(prev_sc->GetID()); diff --git a/core/src/db/snapshot/Resources.cpp b/core/src/db/snapshot/Resources.cpp index 1a8641df9e..3e28a9c088 100644 --- a/core/src/db/snapshot/Resources.cpp +++ b/core/src/db/snapshot/Resources.cpp @@ -100,7 +100,7 @@ Segment::ToString() const { ss << "id=" << GetID() << ", "; ss << "partition_id=" << GetPartitionId() << ", "; ss << "collection_id=" << GetCollectionId() << ", "; - ss << "num=" << (NUM_TYPE)GetNum() << ", "; + ss << "num=" << GetNum() << ", "; ss << "state=" << GetState() << ", "; return ss.str(); } diff --git a/core/src/db/snapshot/SnapshotHolder.cpp b/core/src/db/snapshot/SnapshotHolder.cpp index 1a677969fb..456c5f1b17 100644 --- a/core/src/db/snapshot/SnapshotHolder.cpp +++ b/core/src/db/snapshot/SnapshotHolder.cpp @@ -37,22 +37,17 @@ SnapshotHolder::~SnapshotHolder() { Status SnapshotHolder::Load(StorePtr store, ScopedSnapshotT& ss, ID_TYPE id, bool scoped) { - Status status; if (id > max_id_) { CollectionCommitPtr cc; - status = LoadNoLock(id, cc, store); - if (!status.ok()) - return status; - status = Add(store, id); - if (!status.ok()) - return status; + STATUS_CHECK(LoadNoLock(id, cc, store)); + STATUS_CHECK(Add(store, id)); } std::unique_lock lock(mutex_); if (id == 0 || id == max_id_) { auto raw = active_.at(max_id_); ss = ScopedSnapshotT(raw, scoped); - return status; + return Status::OK(); } if (id < min_id_) { std::stringstream emsg; @@ -71,7 +66,7 @@ SnapshotHolder::Load(StorePtr store, ScopedSnapshotT& ss, ID_TYPE id, bool scope return Status(SS_NOT_FOUND_ERROR, emsg.str()); } ss = ScopedSnapshotT(it->second, scoped); - return status; + return Status::OK(); } Status diff --git a/core/src/db/snapshot/Snapshots.cpp b/core/src/db/snapshot/Snapshots.cpp index 718af6a830..fd22a8aa7e 100644 --- a/core/src/db/snapshot/Snapshots.cpp +++ b/core/src/db/snapshot/Snapshots.cpp @@ -25,9 +25,7 @@ namespace snapshot { Status Snapshots::DropCollection(ID_TYPE collection_id, const LSN_TYPE& lsn) { ScopedSnapshotT ss; - auto status = GetSnapshot(ss, collection_id); - if (!status.ok()) - return status; + STATUS_CHECK(GetSnapshot(ss, collection_id)); return DoDropCollection(ss, lsn); } @@ -189,25 +187,21 @@ Snapshots::GetHolder(const ID_TYPE& collection_id, SnapshotHolderPtr& holder) co Status Snapshots::LoadHolder(StorePtr store, const ID_TYPE& collection_id, SnapshotHolderPtr& holder) { - Status status; { std::shared_lock lock(mutex_); - status = GetHolderNoLock(collection_id, holder); - if (status.ok() && holder) + auto status = GetHolderNoLock(collection_id, holder); + if (status.ok() && holder) { return status; + } } - status = LoadNoLock(store, collection_id, holder); - if (!status.ok()) - return status; + STATUS_CHECK(LoadNoLock(store, collection_id, holder)); std::unique_lock lock(mutex_); holders_[collection_id] = holder; ScopedSnapshotT ss; - status = holder->Load(store, ss); - if (!status.ok()) - return status; + STATUS_CHECK(holder->Load(store, ss)); name_id_map_[ss->GetName()] = collection_id; - return status; + return Status::OK(); } Status diff --git a/core/src/db/wal/WalFile.cpp b/core/src/db/wal/WalFile.cpp index 08e0e58b71..e4a487b682 100644 --- a/core/src/db/wal/WalFile.cpp +++ b/core/src/db/wal/WalFile.cpp @@ -18,9 +18,6 @@ namespace milvus { namespace engine { -WalFile::WalFile() { -} - WalFile::~WalFile() { CloseFile(); } diff --git a/core/src/db/wal/WalFile.h b/core/src/db/wal/WalFile.h index 0de4e07790..e7f867d117 100644 --- a/core/src/db/wal/WalFile.h +++ b/core/src/db/wal/WalFile.h @@ -24,8 +24,8 @@ namespace engine { class WalFile { public: - WalFile(); - ~WalFile(); + WalFile() = default; + virtual ~WalFile(); bool IsOpened() const { @@ -60,7 +60,7 @@ class WalFile { } inline int64_t - Write(void* data, int64_t length) { + Write(const void* data, int64_t length) { if (file_ == nullptr) { return 0; } diff --git a/core/src/db/wal/WalManager.h b/core/src/db/wal/WalManager.h index 4b08652e8f..58261aac39 100644 --- a/core/src/db/wal/WalManager.h +++ b/core/src/db/wal/WalManager.h @@ -11,6 +11,7 @@ #pragma once +#include "config/ServerConfig.h" #include "db/DB.h" #include "db/IDGenerator.h" #include "db/Types.h" diff --git a/core/src/db/wal/WalOperationCodec.cpp b/core/src/db/wal/WalOperationCodec.cpp index f3e530a422..c4c9ef1cce 100644 --- a/core/src/db/wal/WalOperationCodec.cpp +++ b/core/src/db/wal/WalOperationCodec.cpp @@ -58,7 +58,7 @@ WalOperationCodec::WriteInsertOperation(const WalFilePtr& file, const std::strin int32_t part_name_length = partition_name.size(); total_bytes += file->Write(&part_name_length); if (part_name_length > 0) { - total_bytes += file->Write((void*)partition_name.data(), part_name_length); + total_bytes += file->Write(partition_name.data(), part_name_length); } // write fixed data @@ -71,11 +71,11 @@ WalOperationCodec::WriteInsertOperation(const WalFilePtr& file, const std::strin int32_t field_name_length = pair.first.size(); total_bytes += file->Write(&field_name_length); - total_bytes += file->Write((void*)pair.first.data(), field_name_length); + total_bytes += file->Write(pair.first.data(), field_name_length); int64_t data_size = pair.second->data_.size(); total_bytes += file->Write(&data_size); - total_bytes += file->Write((void*)pair.second->data_.data(), data_size); + total_bytes += file->Write(pair.second->data_.data(), data_size); } // TODO: write variable data @@ -132,7 +132,7 @@ WalOperationCodec::WriteDeleteOperation(const WalFilePtr& file, const IDNumbers& int64_t id_count = entity_ids.size(); total_bytes += file->Write(&id_count); - total_bytes += file->Write((void*)entity_ids.data(), id_count * sizeof(idx_t)); + total_bytes += file->Write(entity_ids.data(), id_count * sizeof(idx_t)); // write operation id again // Note: makesure operation id is written at end, so that wal cleanup thread know which file can be deleted diff --git a/core/src/index/archive/KnowhereResource.cpp b/core/src/index/archive/KnowhereResource.cpp index 22a03ae6a6..853dac22ac 100644 --- a/core/src/index/archive/KnowhereResource.cpp +++ b/core/src/index/archive/KnowhereResource.cpp @@ -63,8 +63,9 @@ KnowhereResource::Initialize() { #ifdef MILVUS_GPU_VERSION bool enable_gpu = config.gpu.enable(); fiu_do_on("KnowhereResource.Initialize.disable_gpu", enable_gpu = false); - if (not enable_gpu) + if (!enable_gpu) { return Status::OK(); + } struct GpuResourceSetting { int64_t pinned_memory = 256 * M_BYTE; diff --git a/core/src/index/knowhere/knowhere/index/vector_index/ConfAdapterMgr.cpp b/core/src/index/knowhere/knowhere/index/vector_index/ConfAdapterMgr.cpp index 3182b002c6..add0d6a665 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/ConfAdapterMgr.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/ConfAdapterMgr.cpp @@ -19,8 +19,9 @@ namespace knowhere { ConfAdapterPtr AdapterMgr::GetAdapter(const IndexType type) { - if (!init_) + if (!init_) { RegisterAdapter(); + } try { return collection_.at(type)(); 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 b64db7cbf9..1782956520 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 @@ -28,21 +28,21 @@ MemoryIOWriter::operator()(const void* ptr, size_t size, size_t nitems) { total = total_need * magic_num; rp = size * nitems; data_ = new uint8_t[total]; - memcpy((void*)(data_), ptr, rp); + memcpy(data_, ptr, rp); return nitems; } if (total_need > total) { total = total_need * magic_num; auto new_data = new uint8_t[total]; - memcpy((void*)new_data, (void*)data_, rp); + memcpy(new_data, data_, rp); delete[] data_; data_ = new_data; - memcpy((void*)(data_ + rp), ptr, size * nitems); + memcpy((data_ + rp), ptr, size * nitems); rp = total_need; } else { - memcpy((void*)(data_ + rp), ptr, size * nitems); + memcpy((data_ + rp), ptr, size * nitems); rp = total_need; } @@ -51,12 +51,14 @@ MemoryIOWriter::operator()(const void* ptr, size_t size, size_t nitems) { size_t MemoryIOReader::operator()(void* ptr, size_t size, size_t nitems) { - if (rp >= total) + if (rp >= total) { return 0; + } size_t nremain = (total - rp) / size; - if (nremain < nitems) + if (nremain < nitems) { nitems = nremain; - memcpy(ptr, (void*)(data_ + rp), size * nitems); + } + memcpy(ptr, (data_ + rp), size * nitems); rp += size * nitems; return nitems; } diff --git a/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSG.cpp b/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSG.cpp index b5be90ae96..226f3ac9b8 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSG.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSG.cpp @@ -52,7 +52,7 @@ NsgIndex::Build_with_ids(size_t nb, float* data, const int64_t* ids, const Build // ori_data_ = new float[ntotal * dimension]; ids_ = new int64_t[ntotal]; // memcpy((void*)ori_data_, (void*)data, sizeof(float) * ntotal * dimension); - memcpy((void*)ids_, (void*)ids, sizeof(int64_t) * ntotal); + memcpy(ids_, ids, sizeof(int64_t) * ntotal); search_length = parameters.search_length; out_degree = parameters.out_degree; @@ -153,8 +153,9 @@ NsgIndex::GetNeighbors(const float* query, float* data, std::vector& r } while (count < buffer_size) { node_t id = rand_r(&seed) % ntotal; - if (has_calculated_dist[id]) + if (has_calculated_dist[id]) { continue; // duplicate id + } // init_ids.push_back(id); init_ids[count] = id; ++count; @@ -193,26 +194,29 @@ NsgIndex::GetNeighbors(const float* query, float* data, std::vector& r node_t start_pos = resset[cursor].id; auto& wait_for_search_node_vec = graph[start_pos]; - for (size_t i = 0; i < wait_for_search_node_vec.size(); ++i) { - node_t id = wait_for_search_node_vec[i]; - if (has_calculated_dist[id]) + for (node_t id : wait_for_search_node_vec) { + if (has_calculated_dist[id]) { continue; + } has_calculated_dist[id] = true; float dist = distance_->Compare(query, data + dimension * id, dimension); Neighbor nn(id, dist, false); fullset.push_back(nn); - if (dist >= resset[buffer_size - 1].distance) + if (dist >= resset[buffer_size - 1].distance) { continue; + } size_t pos = InsertIntoPool(resset.data(), buffer_size, nn); // replace with a closer node - if (pos < nearest_updated_pos) + if (pos < nearest_updated_pos) { nearest_updated_pos = pos; + } // assert(buffer_size + 1 >= resset.size()); - if (buffer_size + 1 < resset.size()) + if (buffer_size + 1 < resset.size()) { ++buffer_size; + } } } if (cursor >= nearest_updated_pos) { @@ -255,8 +259,9 @@ NsgIndex::GetNeighbors(const float* query, float* data, std::vector& r } while (count < buffer_size) { node_t id = rand_r(&seed) % ntotal; - if (has_calculated_dist[id]) + if (has_calculated_dist[id]) { continue; // duplicate id + } // init_ids.push_back(id); init_ids[count] = id; ++count; @@ -291,26 +296,29 @@ NsgIndex::GetNeighbors(const float* query, float* data, std::vector& r node_t start_pos = resset[cursor].id; auto& wait_for_search_node_vec = graph[start_pos]; - for (size_t i = 0; i < wait_for_search_node_vec.size(); ++i) { - node_t id = wait_for_search_node_vec[i]; - if (has_calculated_dist[id]) + for (node_t id : wait_for_search_node_vec) { + if (has_calculated_dist[id]) { continue; + } has_calculated_dist[id] = true; float dist = distance_->Compare(data + dimension * id, query, dimension); Neighbor nn(id, dist, false); fullset.push_back(nn); - if (dist >= resset[buffer_size - 1].distance) + if (dist >= resset[buffer_size - 1].distance) { continue; + } size_t pos = InsertIntoPool(resset.data(), buffer_size, nn); // replace with a closer node - if (pos < nearest_updated_pos) + if (pos < nearest_updated_pos) { nearest_updated_pos = pos; + } // assert(buffer_size + 1 >= resset.size()); - if (buffer_size + 1 < resset.size()) + if (buffer_size + 1 < resset.size()) { ++buffer_size; // trick + } } } if (cursor >= nearest_updated_pos) { @@ -349,8 +357,9 @@ NsgIndex::GetNeighbors(const float* query, float* data, std::vector& r } while (count < buffer_size) { node_t id = rand_r(&seed) % ntotal; - if (has_calculated_dist[id]) + if (has_calculated_dist[id]) { continue; // duplicate id + } init_ids[count] = id; ++count; has_calculated_dist[id] = true; @@ -383,24 +392,26 @@ NsgIndex::GetNeighbors(const float* query, float* data, std::vector& r node_t start_pos = resset[cursor].id; auto& wait_for_search_node_vec = graph[start_pos]; - for (size_t i = 0; i < wait_for_search_node_vec.size(); ++i) { - node_t id = wait_for_search_node_vec[i]; - if (has_calculated_dist[id]) + for (node_t id : wait_for_search_node_vec) { + if (has_calculated_dist[id]) { continue; + } has_calculated_dist[id] = true; float dist = distance_->Compare(query, data + dimension * id, dimension); - if (dist >= resset[buffer_size - 1].distance) + if (dist >= resset[buffer_size - 1].distance) { continue; + } //// difference from other GetNeighbors Neighbor nn(id, dist, false); /////////////////////////////////////// size_t pos = InsertIntoPool(resset.data(), buffer_size, nn); // replace with a closer node - if (pos < nearest_updated_pos) + if (pos < nearest_updated_pos) { nearest_updated_pos = pos; + } //>> Debug code ///// @@ -408,8 +419,9 @@ NsgIndex::GetNeighbors(const float* query, float* data, std::vector& r // nearest_updated_pos << std::endl; ///// // trick: avoid search query search_length < init_ids.size() ... - if (buffer_size + 1 < resset.size()) + if (buffer_size + 1 < resset.size()) { ++buffer_size; + } } } if (cursor >= nearest_updated_pos) { @@ -423,7 +435,7 @@ NsgIndex::GetNeighbors(const float* query, float* data, std::vector& r void NsgIndex::Link(float* data) { - float* cut_graph_dist = new float[ntotal * out_degree]; + auto cut_graph_dist = new float[ntotal * out_degree]; nsg.resize(ntotal); #pragma omp parallel @@ -475,8 +487,9 @@ NsgIndex::SyncPrune(float* data, size_t n, std::vector& pool, boost::d // avoid lose nearest neighbor in knng for (size_t i = 0; i < knng[n].size(); ++i) { auto id = knng[n][i]; - if (has_calculated[id]) + if (has_calculated[id]) { continue; + } float dist = distance_->Compare(data + dimension * n, data + dimension * id, dimension); pool.emplace_back(Neighbor(id, dist, true)); } @@ -513,8 +526,9 @@ NsgIndex::InterInsert(float* data, unsigned n, std::vector& mutex_ve auto& neighbor_id_pool = nsg[current]; float* neighbor_dist_pool = cut_graph_dist + current * out_degree; for (size_t i = 0; i < out_degree; ++i) { - if (neighbor_dist_pool[i] == -1) + if (neighbor_dist_pool[i] == -1) { break; + } size_t current_neighbor = neighbor_id_pool[i]; // center's neighbor id auto& nsn_id_pool = nsg[current_neighbor]; // nsn => neighbor's neighbor @@ -525,8 +539,9 @@ NsgIndex::InterInsert(float* data, unsigned n, std::vector& mutex_ve { LockGuard lk(mutex_vec[current_neighbor]); for (size_t j = 0; j < out_degree; ++j) { - if (nsn_dist_pool[j] == -1) + if (nsn_dist_pool[j] == -1) { break; + } // At least one edge can be connected back if (n == nsn_id_pool[j]) { @@ -538,8 +553,9 @@ NsgIndex::InterInsert(float* data, unsigned n, std::vector& mutex_ve wait_for_link_pool.push_back(nsn); } } - if (duplicate) + if (duplicate) { continue; + } // original: (neighbor) <------- (current) // after: (neighbor) -------> (current) @@ -570,8 +586,9 @@ NsgIndex::InterInsert(float* data, unsigned n, std::vector& mutex_ve if (nsn_dist_pool[j] == -1) { nsn_id_pool.push_back(current_as_neighbor.id); nsn_dist_pool[j] = current_as_neighbor.distance; - if (j + 1 < out_degree) + if (j + 1 < out_degree) { nsn_dist_pool[j + 1] = -1; + } break; } } @@ -594,16 +611,16 @@ NsgIndex::SelectEdge(float* data, unsigned& cursor, std::vector& sort_ while (result.size() < out_degree && cursor < search_deepth && (++cursor) < pool.size()) { auto& p = pool[cursor]; bool should_link = true; - for (size_t t = 0; t < result.size(); ++t) { - float dist = distance_->Compare(data + dimension * result[t].id, data + dimension * p.id, dimension); - + for (auto& t : result) { + float dist = distance_->Compare(data + dimension * t.id, data + dimension * p.id, dimension); if (dist < p.distance) { should_link = false; break; } } - if (should_link) + if (should_link) { result.push_back(p); + } } } @@ -636,16 +653,17 @@ NsgIndex::DFS(size_t root, boost::dynamic_bitset<>& has_linked, int64_t& linked_ while (!s.empty()) { size_t next = ntotal + 1; - for (unsigned i = 0; i < nsg[start].size(); i++) { - if (has_linked[nsg[start][i]] == false) { // if not link - next = nsg[start][i]; + for (auto i : nsg[start]) { + if (has_linked[i] == false) { // if not link + next = i; break; } } if (next == (ntotal + 1)) { s.pop(); - if (s.empty()) + if (s.empty()) { break; + } start = s.top(); continue; } @@ -667,8 +685,9 @@ NsgIndex::FindUnconnectedNode(float* data, boost::dynamic_bitset<>& has_linked, } } - if (id == ntotal) + if (id == ntotal) { return; // No Unlinked Node + } // search unlinked-node's neighbor std::vector tmp, pool; @@ -676,9 +695,9 @@ NsgIndex::FindUnconnectedNode(float* data, boost::dynamic_bitset<>& has_linked, std::sort(pool.begin(), pool.end()); size_t found = 0; - for (size_t i = 0; i < pool.size(); i++) { // find nearest neighbor and add unlinked-node as its neighbor - if (has_linked[pool[i].id]) { - root = pool[i].id; + for (auto node : pool) { // find nearest neighbor and add unlinked-node as its neighbor + if (has_linked[node.id]) { + root = node.id; found = 1; break; } @@ -850,12 +869,13 @@ NsgIndex::Search(const float* query, float* data, const unsigned& nq, const unsi bool is_ip = (metric_type == Metric_Type::Metric_Type_IP); for (unsigned int i = 0; i < nq; ++i) { unsigned int pos = 0; - for (unsigned int j = 0; j < resset[i].size(); ++j) { - if (pos >= k) + for (auto node : resset[i]) { + if (pos >= k) { break; // already top k - if (!bitset || !bitset->test((faiss::ConcurrentBitset::id_type_t)resset[i][j].id)) { - ids[i * k + pos] = ids_[resset[i][j].id]; - dist[i * k + pos] = is_ip ? -resset[i][j].distance : resset[i][j].distance; + } + if (!bitset || !bitset->test(node.id)) { + ids[i * k + pos] = ids_[node.id]; + dist[i * k + pos] = is_ip ? -node.distance : node.distance; ++pos; } } @@ -880,11 +900,11 @@ NsgIndex::GetSize() { ret += ntotal * dimension * sizeof(float); ret += ntotal * sizeof(int64_t); ret += sizeof(*distance_); - for (size_t i = 0; i < nsg.size(); ++i) { - ret += nsg[i].size() * sizeof(node_t); + for (auto& v : nsg) { + ret += v.size() * sizeof(node_t); } - for (size_t i = 0; i < knng.size(); ++i) { - ret += knng[i].size() * sizeof(node_t); + for (auto& v : knng) { + ret += v.size() * sizeof(node_t); } return ret; } diff --git a/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSG.h b/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSG.h index c7524c08ba..af7f608dc7 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSG.h +++ b/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSG.h @@ -44,7 +44,7 @@ using Graph = std::vector>; class NsgIndex { public: enum Metric_Type { - Metric_Type_L2, + Metric_Type_L2 = 0, Metric_Type_IP, }; diff --git a/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSGHelper.cpp b/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSGHelper.cpp index 334cc5d02c..54d90d602c 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSGHelper.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSGHelper.cpp @@ -29,7 +29,7 @@ InsertIntoPool(Neighbor* addr, unsigned K, Neighbor nn) { int left = 0, right = K - 1; if (addr[left].distance > nn.distance) { //>> Fix: memmove overflow, dump when vector deconstruct - memmove((char*)&addr[left + 1], &addr[left], (K - 1) * sizeof(Neighbor)); + memmove(&addr[left + 1], &addr[left], (K - 1) * sizeof(Neighbor)); addr[left] = nn; return left; } @@ -39,29 +39,33 @@ InsertIntoPool(Neighbor* addr, unsigned K, Neighbor nn) { } while (left < right - 1) { int mid = (left + right) / 2; - if (addr[mid].distance > nn.distance) + if (addr[mid].distance > nn.distance) { right = mid; - else + } else { left = mid; + } } // check equal ID while (left > 0) { - if (addr[left].distance < nn.distance) // pos is right + if (addr[left].distance < nn.distance) { // pos is right break; - if (addr[left].id == nn.id) + } + if (addr[left].id == nn.id) { return K + 1; + } left--; } - if (addr[left].id == nn.id || addr[right].id == nn.id) + if (addr[left].id == nn.id || addr[right].id == nn.id) { return K + 1; + } //>> Fix: memmove overflow, dump when vector deconstruct - memmove((char*)&addr[right + 1], &addr[right], (K - 1 - right) * sizeof(Neighbor)); + memmove(&addr[right + 1], &addr[right], (K - 1 - right) * sizeof(Neighbor)); addr[right] = nn; return right; } -}; // namespace impl +} // namespace impl } // namespace knowhere } // namespace milvus diff --git a/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSGIO.cpp b/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSGIO.cpp index ff9e021134..16f16e4be6 100644 --- a/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSGIO.cpp +++ b/core/src/index/knowhere/knowhere/index/vector_index/impl/nsg/NSGIO.cpp @@ -27,7 +27,7 @@ write_index(NsgIndex* index, MemoryIOWriter& writer) { writer(index->ids_, sizeof(int64_t) * index->ntotal, 1); for (unsigned i = 0; i < index->ntotal; ++i) { - auto neighbor_num = (node_t)index->nsg[i].size(); + auto neighbor_num = static_cast(index->nsg[i].size()); writer(&neighbor_num, sizeof(node_t), 1); writer(index->nsg[i].data(), neighbor_num * sizeof(node_t), 1); } @@ -41,7 +41,7 @@ read_index(MemoryIOReader& reader) { reader(&metric, sizeof(int32_t), 1); reader(&ntotal, sizeof(size_t), 1); reader(&dimension, sizeof(size_t), 1); - auto index = new NsgIndex(dimension, ntotal, (impl::NsgIndex::Metric_Type)metric); + auto index = new NsgIndex(dimension, ntotal, static_cast(metric)); reader(&index->navigation_point, sizeof(index->navigation_point), 1); // index->ori_data_ = new float[index->ntotal * index->dimension]; diff --git a/core/src/index/unittest/CMakeLists.txt b/core/src/index/unittest/CMakeLists.txt index 34570891db..ece34cadc9 100644 --- a/core/src/index/unittest/CMakeLists.txt +++ b/core/src/index/unittest/CMakeLists.txt @@ -158,7 +158,7 @@ install(TARGETS test_binaryivf DESTINATION unittest) ################################################################################ # -add_definitions(-std=c++11 -O3 -lboost -march=native -Wall -DINFO) +add_definitions(-std=c++11 -O3 -march=native -Werror -DINFO) find_package(OpenMP REQUIRED) if (OpenMP_FOUND) diff --git a/core/src/segment/Segment.cpp b/core/src/segment/Segment.cpp index 3eaa9d3e6c..2017e0152f 100644 --- a/core/src/segment/Segment.cpp +++ b/core/src/segment/Segment.cpp @@ -149,7 +149,7 @@ Segment::DeleteEntity(std::vector& offsets) { return Status::OK(); } // sort offset in descendant - std::sort(offsets.begin(), offsets.end(), std::greater()); + std::sort(offsets.begin(), offsets.end(), std::greater<>()); // delete entity data from max offset to min offset for (auto& pair : fixed_fields_) { diff --git a/core/src/storage/IOWriter.h b/core/src/storage/IOWriter.h index d6f09c8d4f..8b508f3d92 100644 --- a/core/src/storage/IOWriter.h +++ b/core/src/storage/IOWriter.h @@ -26,7 +26,7 @@ class IOWriter { InOpen(const std::string& name) = 0; virtual void - Write(void* ptr, int64_t size) = 0; + Write(const void* ptr, int64_t size) = 0; virtual void Seekp(int64_t pos) = 0; diff --git a/core/src/storage/disk/DiskIOWriter.cpp b/core/src/storage/disk/DiskIOWriter.cpp index 3e7970b6c3..73b23742c8 100644 --- a/core/src/storage/disk/DiskIOWriter.cpp +++ b/core/src/storage/disk/DiskIOWriter.cpp @@ -30,8 +30,8 @@ DiskIOWriter::InOpen(const std::string& name) { } void -DiskIOWriter::Write(void* ptr, int64_t size) { - fs_.write(reinterpret_cast(ptr), size); +DiskIOWriter::Write(const void* ptr, int64_t size) { + fs_.write(reinterpret_cast(ptr), size); len_ += size; } diff --git a/core/src/storage/disk/DiskIOWriter.h b/core/src/storage/disk/DiskIOWriter.h index a82d802223..4f7c3983c2 100644 --- a/core/src/storage/disk/DiskIOWriter.h +++ b/core/src/storage/disk/DiskIOWriter.h @@ -40,7 +40,7 @@ class DiskIOWriter : public IOWriter { InOpen(const std::string& name) override; void - Write(void* ptr, int64_t size) override; + Write(const void* ptr, int64_t size) override; void Seekp(int64_t pos) override; diff --git a/core/src/storage/s3/S3IOWriter.cpp b/core/src/storage/s3/S3IOWriter.cpp index 68acb374a3..3c66f522c3 100644 --- a/core/src/storage/s3/S3IOWriter.cpp +++ b/core/src/storage/s3/S3IOWriter.cpp @@ -24,8 +24,8 @@ S3IOWriter::open(const std::string& name) { } void -S3IOWriter::write(void* ptr, int64_t size) { - buffer_ += std::string(reinterpret_cast(ptr), size); +S3IOWriter::write(const void* ptr, int64_t size) { + buffer_ += std::string(reinterpret_cast(ptr), size); len_ += size; } diff --git a/core/src/storage/s3/S3IOWriter.h b/core/src/storage/s3/S3IOWriter.h index 4461f981ce..c9f7c154e7 100644 --- a/core/src/storage/s3/S3IOWriter.h +++ b/core/src/storage/s3/S3IOWriter.h @@ -36,7 +36,7 @@ class S3IOWriter : public IOWriter { Open(const std::string& name) override; void - Write(void* ptr, int64_t size) override; + Write(const void* ptr, int64_t size) override; int64_t Length() override; diff --git a/core/unittest/db/utils.cpp b/core/unittest/db/utils.cpp index 37f5daa364..810a003a14 100644 --- a/core/unittest/db/utils.cpp +++ b/core/unittest/db/utils.cpp @@ -182,9 +182,9 @@ DBTest::SetUp() { res_mgr->Add(milvus::scheduler::ResourceFactory::Create("cpu", "CPU", 0)); auto default_conn = milvus::scheduler::Connection("IO", 500.0); - auto PCIE = milvus::scheduler::Connection("IO", 11000.0); res_mgr->Connect("disk", "cpu", default_conn); #ifdef MILVUS_GPU_VERSION + auto PCIE = milvus::scheduler::Connection("IO", 11000.0); res_mgr->Add(milvus::scheduler::ResourceFactory::Create("0", "GPU", 0)); res_mgr->Connect("cpu", "0", PCIE); #endif @@ -264,9 +264,9 @@ SchedulerTest::SetUp() { res_mgr->Add(milvus::scheduler::ResourceFactory::Create("cpu", "CPU", 0)); auto default_conn = milvus::scheduler::Connection("IO", 500.0); - auto PCIE = milvus::scheduler::Connection("IO", 11000.0); res_mgr->Connect("disk", "cpu", default_conn); #ifdef MILVUS_GPU_VERSION + auto PCIE = milvus::scheduler::Connection("IO", 11000.0); res_mgr->Add(milvus::scheduler::ResourceFactory::Create("0", "GPU", 0)); res_mgr->Connect("cpu", "0", PCIE); #endif diff --git a/core/unittest/storage/test_s3_client.cpp b/core/unittest/storage/test_s3_client.cpp index dac0110aaf..1d1ec98bb4 100644 --- a/core/unittest/storage/test_s3_client.cpp +++ b/core/unittest/storage/test_s3_client.cpp @@ -32,7 +32,7 @@ TEST_F(StorageTest, S3_CLIENT_TEST) { const std::string filename_dummy = "/tmp/test_file_dummy"; const std::string filename_out = "/tmp/test_file_out"; const std::string objname = "/tmp/test_obj"; - const std::string objname_dummy = "/tmp/test_obj_dummy"; + // const std::string objname_dummy = "/tmp/test_obj_dummy"; const std::string content = "abcdefghijklmnopqrstuvwxyz"; auto& storage_inst = milvus::storage::S3ClientWrapper::GetInstance();