|
@ -1,10 +1,21 @@ |
|
|
#include "db/db_impl.h" |
|
|
#include "db/db_impl.h" |
|
|
|
|
|
#include <deque> |
|
|
|
|
|
#include <map> |
|
|
|
|
|
#include <set> |
|
|
|
|
|
#include <string> |
|
|
#include "leveldb/db.h" |
|
|
#include "leveldb/db.h" |
|
|
#include "leveldb/options.h" |
|
|
#include "leveldb/options.h" |
|
|
|
|
|
#include "leveldb/slice.h" |
|
|
#include "leveldb/status.h" |
|
|
#include "leveldb/status.h" |
|
|
namespace leveldb{ |
|
|
|
|
|
class FieldDB:leveldb::DB { |
|
|
|
|
|
|
|
|
#include "port/port_stdcxx.h" |
|
|
|
|
|
#include "fielddb/request.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace fielddb { |
|
|
|
|
|
using namespace leveldb; |
|
|
|
|
|
class FieldDB : leveldb::DB { |
|
|
public: |
|
|
public: |
|
|
|
|
|
FieldDB() = default; |
|
|
|
|
|
FieldDB(const Options& options,const std::string& name); |
|
|
/*lab1的要求*/ |
|
|
/*lab1的要求*/ |
|
|
Status Put(const WriteOptions &options, const Slice &key, const Slice &value) override; |
|
|
Status Put(const WriteOptions &options, const Slice &key, const Slice &value) override; |
|
|
Status PutFields(const WriteOptions &, const Slice &key, const FieldArray &fields) override; |
|
|
Status PutFields(const WriteOptions &, const Slice &key, const FieldArray &fields) override; |
|
@ -24,10 +35,25 @@ public: |
|
|
bool DeleteIndex(std::string &field_name); |
|
|
bool DeleteIndex(std::string &field_name); |
|
|
std::vector<std::string> QueryByIndex(Field &field); |
|
|
std::vector<std::string> QueryByIndex(Field &field); |
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
static Status OpenFieldDB(const Options& options,const std::string& name,DB** dbptr); |
|
|
static Status OpenFieldDB(const Options& options,const std::string& name,DB** dbptr); |
|
|
|
|
|
|
|
|
leveldb::DBImpl *indexDB; |
|
|
|
|
|
leveldb::DBImpl *kvDB; |
|
|
|
|
|
|
|
|
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 |
|
|
} // end of namespace |