|
|
@ -1,5 +1,6 @@ |
|
|
|
#include "fielddb/request.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <string>
|
|
|
|
#include "leveldb/slice.h"
|
|
|
|
#include "leveldb/status.h"
|
|
|
|
#include "leveldb/write_batch.h"
|
|
|
@ -54,7 +55,8 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
if (s.IsNotFound()){ |
|
|
|
oldFields = nullptr; |
|
|
|
} else if (s.ok()) { //得到数据库之前key的fields, 判断需不需要删除其中潜在的索引
|
|
|
|
oldFields = ParseValue(val_str); |
|
|
|
oldFields = new FieldArray; |
|
|
|
oldFields = ParseValue(val_str,oldFields); |
|
|
|
} else { |
|
|
|
assert(0); |
|
|
|
} |
|
|
@ -99,11 +101,11 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
|
|
|
|
//2.对于没有冲突但含有索引操作的put,构建metaKV,这里直接将KV对简单编码后写入metaDB
|
|
|
|
if(HasIndex || HasOldIndex) { |
|
|
|
Slice MetaKey,MetaValue; |
|
|
|
std::string MetaKey,MetaValue; |
|
|
|
std::string serialized = SerializeValue(*Fields); |
|
|
|
MetaKV MKV = MetaKV(Key,&serialized); |
|
|
|
MKV.TransPut(MetaKey, MetaValue); |
|
|
|
MetaBatch.Put(MetaKey, MetaValue); |
|
|
|
MetaBatch.Put(MetaKey, serialized); |
|
|
|
|
|
|
|
|
|
|
|
//3.1对于含有索引的oldfield删除索引
|
|
|
@ -135,6 +137,8 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
} |
|
|
|
//优化:对于3.1,3.2中都有的索引只写一次
|
|
|
|
} |
|
|
|
|
|
|
|
if(oldFields) delete oldFields; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -154,7 +158,9 @@ void DeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
//2.3 如果存在field的索引状态是Creating或者Deleting,那么在那个队列上面进行等待
|
|
|
|
std::string val_str; |
|
|
|
DB->kvDB_->Get(ReadOptions(), *Key, &val_str); |
|
|
|
FieldArray *Fields = ParseValue(val_str); |
|
|
|
FieldArray *Fields = new FieldArray; |
|
|
|
ParseValue(val_str,Fields); |
|
|
|
|
|
|
|
KVBatch.Delete(Slice(*Key)); |
|
|
|
bool HasIndex = false; |
|
|
|
{ |
|
|
@ -176,7 +182,7 @@ void DeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
} |
|
|
|
//2.对于没有冲突但含有索引操作的delete,构建metaKV,这里直接将KV对简单编码后写入metaDB
|
|
|
|
if(HasIndex) { |
|
|
|
Slice MetaKey; |
|
|
|
std::string MetaKey; |
|
|
|
MetaKV MKV = MetaKV(Key); |
|
|
|
MKV.TransDelete(MetaKey); //meta中写入一个delete不需要value
|
|
|
|
MetaBatch.Put(MetaKey, Slice()); |
|
|
@ -192,6 +198,7 @@ void DeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
delete Fields; |
|
|
|
} |
|
|
|
|
|
|
|
/*******iCreateReq*******/ |
|
|
|