RocksIdMapper.h 2.1 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/
#pragma once

#include "utils/Error.h"
#include "VecIdMapper.h"

#include "rocksdb/db.h"

#include <string>
#include <vector>
#include <unordered_map>
Y
yu yunfeng 已提交
16
#include <mutex>
G
groot 已提交
17 18 19 20 21 22

namespace zilliz {
namespace vecwise {
namespace server {

class RocksIdMapper : public IVecIdMapper{
Y
yu yunfeng 已提交
23
 public:
G
groot 已提交
24 25 26
    RocksIdMapper();
    ~RocksIdMapper();

Y
yu yunfeng 已提交
27 28 29
    ServerError AddGroup(const std::string& group) override;
    bool IsGroupExist(const std::string& group) const override;

G
groot 已提交
30 31 32 33 34 35 36 37 38
    ServerError Put(const std::string& nid, const std::string& sid, const std::string& group = "") override;
    ServerError Put(const std::vector<std::string>& nid, const std::vector<std::string>& sid, const std::string& group = "") override;

    ServerError Get(const std::string& nid, std::string& sid, const std::string& group = "") const override;
    ServerError Get(const std::vector<std::string>& nid, std::vector<std::string>& sid, const std::string& group = "") const override;

    ServerError Delete(const std::string& nid, const std::string& group = "") override;
    ServerError DeleteGroup(const std::string& group) override;

Y
yu yunfeng 已提交
39
 private:
G
groot 已提交
40 41 42
    void OpenDb();
    void CloseDb();

Y
yu yunfeng 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55
    ServerError AddGroupInternal(const std::string& group);

    bool IsGroupExistInternal(const std::string& group) const;

    ServerError PutInternal(const std::string& nid, const std::string& sid, const std::string& group);

    ServerError GetInternal(const std::string& nid, std::string& sid, const std::string& group) const;

    ServerError DeleteInternal(const std::string& nid, const std::string& group);

    ServerError DeleteGroupInternal(const std::string& group);

 private:
G
groot 已提交
56
    rocksdb::DB* db_;
Y
yu yunfeng 已提交
57 58
    mutable std::unordered_map<std::string, rocksdb::ColumnFamilyHandle*> column_handles_;
    mutable std::mutex db_mutex_;
G
groot 已提交
59 60
};

Y
yu yunfeng 已提交
61

G
groot 已提交
62 63 64
}
}
}