#include "port/port_stdcxx.h"
|
|
#include "db/db_impl.h"
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <deque>
|
|
#include <map>
|
|
#include <set>
|
|
#include <string>
|
|
#include "leveldb/db.h"
|
|
#include "leveldb/env.h"
|
|
#include "leveldb/options.h"
|
|
#include "leveldb/slice.h"
|
|
#include "leveldb/status.h"
|
|
#include <shared_mutex>
|
|
# ifndef test_DB_H
|
|
# define test_DB_H
|
|
namespace testdb {
|
|
using namespace leveldb;
|
|
|
|
enum IndexStatus{
|
|
Creating,
|
|
Deleting,
|
|
Exist,
|
|
NotExist
|
|
};
|
|
|
|
class testDB {
|
|
private:
|
|
leveldb::DB *kvDB_;
|
|
// leveldb::DB *metaDB_;
|
|
// leveldb::DB *indexDB_;
|
|
|
|
std::string dbname_;
|
|
const Options *options_;
|
|
Env *env_;
|
|
public:
|
|
friend class Request;
|
|
friend class testsReq;
|
|
friend class iCreateReq;
|
|
friend class iDeleteReq;
|
|
friend class DeleteReq;
|
|
friend class BatchReq;
|
|
|
|
//用的时候必须testDB *db = new testDB()再open,不能像之前一样DB *db
|
|
// testDB() : indexDB_(nullptr), kvDB_(nullptr), metaDB_(nullptr) {};
|
|
testDB() : kvDB_(nullptr) { }
|
|
~testDB();
|
|
/*lab1的要求,作为db派生类要实现的虚函数*/
|
|
Status Put(const WriteOptions &options, const Slice &key, const Slice &value) ;
|
|
Status PutFields(const WriteOptions &, const Slice &key, const FieldArray &tests) ;
|
|
Status Delete(const WriteOptions &options, const Slice &key) ;
|
|
Status Write(const WriteOptions &options, WriteBatch *updates) ;
|
|
Status Get(const ReadOptions &options, const Slice &key, std::string *value) ;
|
|
Status GetFields(const ReadOptions &options, const Slice &key, FieldArray *tests) ;
|
|
std::vector<std::string> FindKeysByField(Field &test) ;
|
|
Iterator * NewIterator(const ReadOptions &options) ;
|
|
const Snapshot * GetSnapshot() ;
|
|
void ReleaseSnapshot(const Snapshot *snapshot) ;
|
|
bool GetProperty(const Slice &property, std::string *value) ;
|
|
void GetApproximateSizes(const Range *range, int n, uint64_t *sizes) ;
|
|
void CompactRange(const Slice *begin, const Slice *end) ;
|
|
|
|
static Status OpentestDB(Options& options,const std::string& name,testDB** dbptr);
|
|
|
|
|
|
|
|
};
|
|
|
|
Status DestroyDB(const std::string& name,
|
|
const Options& options);
|
|
} // end of namespace
|
|
# endif
|