Commit 464a3415 authored by peng.xu's avatar peng.xu
Browse files

Merge branch 'branch-0.5.0' into 'branch-0.5.0'

format code by clang-format

See merge request megasearch/milvus!637

Former-commit-id: 5ef398b80b258437c7edd3543bb1c0721e8a4078
parents c181e405 58b82398
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -104,13 +104,13 @@ if [[ ${RUN_CPPLINT} == "ON" ]]; then
    fi
    echo "cpplint check passed!"

#    # clang-format check
#    make check-clang-format
#    if [ $? -ne 0 ]; then
#        echo "ERROR! clang-format check failed"
#        exit 1
#    fi
#    echo "clang-format check passed!"
    # clang-format check
    make check-clang-format
    if [ $? -ne 0 ]; then
        echo "ERROR! clang-format check failed"
        exit 1
    fi
    echo "clang-format check passed!"
#
#    # clang-tidy check
#    make check-clang-tidy
+34 −22
Original line number Diff line number Diff line
@@ -15,16 +15,15 @@
// specific language governing permissions and limitations
// under the License.


#pragma once

#include "LRU.h"
#include "utils/Log.h"

#include <string>
#include <mutex>
#include <atomic>
#include <mutex>
#include <set>
#include <string>

namespace zilliz {
namespace milvus {
@@ -37,33 +36,46 @@ class Cache {
    Cache(int64_t capacity_gb, uint64_t cache_max_count);
    ~Cache() = default;

    int64_t usage() const {
    int64_t
    usage() const {
        return usage_;
    }

    int64_t capacity() const {
    int64_t
    capacity() const {
        return capacity_;
    }  // unit: BYTE
    void set_capacity(int64_t capacity); //unit: BYTE
    void
    set_capacity(int64_t capacity);  // unit: BYTE

    double freemem_percent() const {
    double
    freemem_percent() const {
        return freemem_percent_;
    }

    void set_freemem_percent(double percent) {
    void
    set_freemem_percent(double percent) {
        freemem_percent_ = percent;
    }

    size_t size() const;
    bool exists(const std::string &key);
    ItemObj get(const std::string &key);
    void insert(const std::string &key, const ItemObj &item);
    void erase(const std::string &key);
    void print();
    void clear();
    size_t
    size() const;
    bool
    exists(const std::string& key);
    ItemObj
    get(const std::string& key);
    void
    insert(const std::string& key, const ItemObj& item);
    void
    erase(const std::string& key);
    void
    print();
    void
    clear();

 private:
    void free_memory();
    void
    free_memory();

 private:
    int64_t usage_;
+26 −17
Original line number Diff line number Diff line
@@ -15,15 +15,14 @@
// specific language governing permissions and limitations
// under the License.


#pragma once

#include "Cache.h"
#include "utils/Log.h"
#include "metrics/Metrics.h"
#include "utils/Log.h"

#include <string>
#include <memory>
#include <string>

namespace zilliz {
namespace milvus {
@@ -32,23 +31,33 @@ namespace cache {
template <typename ItemObj>
class CacheMgr {
 public:
    virtual uint64_t ItemCount() const;
    virtual uint64_t
    ItemCount() const;

    virtual bool ItemExists(const std::string &key);
    virtual bool
    ItemExists(const std::string& key);

    virtual ItemObj GetItem(const std::string &key);
    virtual ItemObj
    GetItem(const std::string& key);

    virtual void InsertItem(const std::string &key, const ItemObj &data);
    virtual void
    InsertItem(const std::string& key, const ItemObj& data);

    virtual void EraseItem(const std::string &key);
    virtual void
    EraseItem(const std::string& key);

    virtual void PrintInfo();
    virtual void
    PrintInfo();

    virtual void ClearCache();
    virtual void
    ClearCache();

    int64_t CacheUsage() const;
    int64_t CacheCapacity() const;
    void SetCapacity(int64_t capacity);
    int64_t
    CacheUsage() const;
    int64_t
    CacheCapacity() const;
    void
    SetCapacity(int64_t capacity);

 protected:
    CacheMgr();
+8 −9
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.


#include "cache/CpuCacheMgr.h"
#include "server/Config.h"
#include "utils/Log.h"
@@ -50,8 +49,8 @@ CpuCacheMgr::CpuCacheMgr() {
    if (cpu_cache_threshold > 0.0 && cpu_cache_threshold <= 1.0) {
        cache_->set_freemem_percent(cpu_cache_threshold);
    } else {
        SERVER_LOG_ERROR << "Invalid cpu_cache_threshold: " << cpu_cache_threshold
                         << ", by default set to " << cache_->freemem_percent();
        SERVER_LOG_ERROR << "Invalid cpu_cache_threshold: " << cpu_cache_threshold << ", by default set to "
                         << cache_->freemem_percent();
    }
}

+9 −7
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@
#include "CacheMgr.h"
#include "DataObj.h"

#include <string>
#include <memory>
#include <string>

namespace zilliz {
namespace milvus {
@@ -33,9 +33,11 @@ class CpuCacheMgr : public CacheMgr<DataObjPtr> {

 public:
    // TODO: use smart pointer instead
    static CpuCacheMgr *GetInstance();
    static CpuCacheMgr*
    GetInstance();

    engine::VecIndexPtr GetIndex(const std::string &key);
    engine::VecIndexPtr
    GetIndex(const std::string& key);
};

}  // namespace cache
Loading