#include "fielddb/field_db.h"
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
#include "leveldb/db.h"
|
|
#include "leveldb/env.h"
|
|
#include "leveldb/options.h"
|
|
#include "leveldb/status.h"
|
|
#include "util/serialize_value.h"
|
|
|
|
namespace fielddb {
|
|
using namespace leveldb;
|
|
//TODO:打开fieldDB
|
|
Status FieldDB::OpenFieldDB(const Options& options,
|
|
const std::string& name, FieldDB** dbptr) {
|
|
// options.env->CreateDir("./abc")
|
|
if(*dbptr == nullptr){
|
|
return Status::NotSupported(name, "new a fieldDb first\n");
|
|
}
|
|
|
|
Status status;
|
|
DB *indexdb, *kvdb, *metadb;
|
|
status = Open(options, name+"_indexDB", &indexdb);
|
|
if(!status.ok()) return status;
|
|
|
|
status = Open(options, name+"_kvDB", &kvdb);
|
|
if(!status.ok()) return status;
|
|
status = Open(options, name+"_metaDB", &metadb);
|
|
if(!status.ok()) return status;
|
|
|
|
(*dbptr)->indexDB_ = indexdb;
|
|
(*dbptr)->kvDB_ = kvdb;
|
|
(*dbptr)->metaDB_ = metadb;
|
|
(*dbptr)->dbname_ = name;
|
|
|
|
status = (*dbptr)->Recover();
|
|
return status;
|
|
}
|
|
|
|
// todo
|
|
Status FieldDB::Recover() {
|
|
//
|
|
return Status::OK();
|
|
}
|
|
|
|
Status FieldDB::Put(const WriteOptions &options, const Slice &key, const Slice &value) {
|
|
return kvDB_->Put(options, key, value);
|
|
}
|
|
|
|
// TODO:需要对是否进行index更新做处理
|
|
Status FieldDB::PutFields(const WriteOptions &Options,
|
|
const Slice &key, const FieldArray &fields) {
|
|
//
|
|
return kvDB_->PutFields(Options, key, fields);
|
|
}
|
|
|
|
// todo: 删除有索引的key时indexdb也要同步
|
|
Status FieldDB::Delete(const WriteOptions &options, const Slice &key) {
|
|
//
|
|
return kvDB_->Delete(options, key);
|
|
}
|
|
// TODO:根据updates里面的东西,要对是否需要更新index进行分别处理
|
|
Status FieldDB::Write(const WriteOptions &options, WriteBatch *updates) {
|
|
return Status::OK();
|
|
}
|
|
|
|
Status FieldDB::Get(const ReadOptions &options, const Slice &key, std::string *value) {
|
|
return kvDB_->Get(options, key, value);
|
|
}
|
|
|
|
Status FieldDB::GetFields(const ReadOptions &options, const Slice &key, FieldArray *fields) {
|
|
return kvDB_->GetFields(options, key, fields);
|
|
|
|
}
|
|
|
|
std::vector<std::string> FieldDB::FindKeysByField(Field &field) {
|
|
return kvDB_->FindKeysByField(field);
|
|
}
|
|
|
|
Iterator * FieldDB::NewIterator(const ReadOptions &options) {
|
|
return kvDB_->NewIterator(options);
|
|
}
|
|
|
|
// TODO:使用统一seq进行snapshot管理
|
|
const Snapshot * FieldDB::GetSnapshot() {
|
|
return kvDB_->GetSnapshot();
|
|
}
|
|
// TODO:同上
|
|
void FieldDB::ReleaseSnapshot(const Snapshot *snapshot) {
|
|
kvDB_->ReleaseSnapshot(snapshot);
|
|
}
|
|
|
|
bool FieldDB::GetProperty(const Slice &property, std::string *value) {
|
|
return kvDB_->GetProperty(property, value) | indexDB_->GetProperty(property, value);
|
|
}
|
|
|
|
void FieldDB::GetApproximateSizes(const Range *range, int n, uint64_t *sizes) {
|
|
uint64_t temp = 0;
|
|
kvDB_->GetApproximateSizes(range, n, sizes);
|
|
indexDB_->GetApproximateSizes(range, n, &temp);
|
|
*sizes += temp;
|
|
}
|
|
|
|
void FieldDB::CompactRange(const Slice *begin, const Slice *end) {
|
|
kvDB_->CompactRange(begin, end);
|
|
}
|
|
|
|
} // end of namespace
|