#include "fielddb/field_db.h"
|
|
#include <cstdint>
|
|
#include <vector>
|
|
#include "leveldb/db.h"
|
|
#include "leveldb/env.h"
|
|
#include "leveldb/options.h"
|
|
#include "leveldb/status.h"
|
|
#include "util/serialize_value.h"
|
|
|
|
namespace leveldb {
|
|
//TODO:打开fieldDB
|
|
static Status OpenFieldDB(const Options& options,const std::string& name,DB** dbptr) {
|
|
// options.env->CreateDir("./abc")
|
|
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 &, const Slice &key, const FieldArray &fields) {
|
|
return Status::OK();
|
|
}
|
|
|
|
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) {
|
|
std::string value;
|
|
Status status;
|
|
status = kvDB->Get(options, key, &value);
|
|
if(status.ok() == false) return status;
|
|
fields = ParseValue(value);
|
|
return status;
|
|
}
|
|
|
|
std::vector<std::string> FieldDB::FindKeysByField(Field &field) {
|
|
std::vector<std::string> result;
|
|
auto iter = kvDB->NewIterator(ReadOptions());
|
|
for(iter->SeekToFirst();iter->Valid();iter->Next()) {
|
|
InternalFieldArray fields(iter->value());
|
|
if(fields.HasField(field)) {
|
|
result.push_back(iter->key().ToString());
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
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
|