|
#include "db/db_impl.h"
|
|
#include <deque>
|
|
#include <map>
|
|
#include <set>
|
|
#include <string>
|
|
#include "leveldb/db.h"
|
|
#include "leveldb/options.h"
|
|
#include "leveldb/slice.h"
|
|
#include "leveldb/status.h"
|
|
#include "port/port_stdcxx.h"
|
|
#include "fielddb/request.h"
|
|
|
|
namespace fielddb {
|
|
using namespace leveldb;
|
|
class FieldDB : leveldb::DB {
|
|
public:
|
|
FieldDB() = default;
|
|
FieldDB(const Options& options,const std::string& name);
|
|
/*lab1的要求*/
|
|
Status Put(const WriteOptions &options, const Slice &key, const Slice &value) override;
|
|
Status PutFields(const WriteOptions &, const Slice &key, const FieldArray &fields) override;
|
|
Status Delete(const WriteOptions &options, const Slice &key) override;
|
|
Status Write(const WriteOptions &options, WriteBatch *updates) override;
|
|
Status Get(const ReadOptions &options, const Slice &key, std::string *value) override;
|
|
Status GetFields(const ReadOptions &options, const Slice &key, FieldArray *fields) override;
|
|
std::vector<std::string> FindKeysByField(Field &field) override;
|
|
Iterator * NewIterator(const ReadOptions &options) override;
|
|
const Snapshot * GetSnapshot() override;
|
|
void ReleaseSnapshot(const Snapshot *snapshot) override;
|
|
bool GetProperty(const Slice &property, std::string *value) override;
|
|
void GetApproximateSizes(const Range *range, int n, uint64_t *sizes) override;
|
|
void CompactRange(const Slice *begin, const Slice *end) override;
|
|
/*与索引相关*/
|
|
bool CreateIndexOnField(const std::string& field_name);
|
|
bool DeleteIndex(std::string &field_name);
|
|
std::vector<std::string> QueryByIndex(Field &field);
|
|
|
|
static Status OpenFieldDB(const Options& options,const std::string& name,DB** dbptr);
|
|
|
|
private:
|
|
//根据metaDB的内容进行恢复
|
|
Status Recover();
|
|
|
|
private:
|
|
leveldb::DB *metaDB;
|
|
leveldb::DB *indexDB;
|
|
leveldb::DB *kvDB;
|
|
|
|
enum IndexStatus{
|
|
Creating,
|
|
Deleting,
|
|
Exist
|
|
};
|
|
std::map<std::string,int> index;
|
|
port::Mutex _mutex; // mutex for taskqueue
|
|
std::deque<Request *> taskqueue;
|
|
|
|
};
|
|
} // end of namespace
|