10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

58 lignes
1.4 KiB

#include "fielddb/meta.h"
#include "util/coding.h"
#include <string>
#include "leveldb/options.h"
#include "leveldb/slice.h"
#include "leveldb/write_batch.h"
namespace fielddb {
using namespace leveldb;
// Slice MetaKV::metaKey() {
// std::string buf;
// PutLengthPrefixedSlice(&buf, Key);
// PutFixed64(&buf, meta_seq);
// PutFixed32(&buf, tag);
// return Slice(buf);
// }
// Slice MetaKV::metaValue() {
// return Slice(SerializeValue(Fields));
// }
//对于含有index field的put的meta编码为 (KV|Key,Value)
void MetaKV::Trans(Slice &MetaKey,Slice &MetaValue) {
MetaKey.clear();
MetaValue.clear();
std::string buf;
PutFixed32(&buf, KV_Creating);
PutLengthPrefixedSlice(&buf, Slice(*name));
MetaKey = Slice(buf);
MetaValue = Slice(*value);
}
class CleanerHandler : public WriteBatch::Handler {
public:
WriteBatch *NeedClean;
void Put(const Slice& key, const Slice& value) override {
//将所有之前put的meta数据进行delete
NeedClean->Delete(key);
}
void Delete(const Slice& key) override {
//所有的传入的MetaBatch都是Put的
assert(0);
}
};
void MetaCleaner::Collect(WriteBatch &MetaBatch) {
CleanerHandler Handler;
Handler.NeedClean = &NeedClean;
MetaBatch.Iterate(&Handler);
}
void MetaCleaner::CleanMetaBatch(DB *metaDB) {
if(NeedClean.ApproximateSize() == 0) return;
metaDB->Write(WriteOptions(), &NeedClean);
}
}