|
|
@ -25,7 +25,7 @@ void Request::PendReq(Request *req) { |
|
|
|
//为虚函数提供最基本的实现
|
|
|
|
void Request::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB, |
|
|
|
std::unordered_set<std::string> &batchKeySet) |
|
|
|
SliceHashSet &batchKeySet) |
|
|
|
{ |
|
|
|
assert(0); |
|
|
|
} |
|
|
@ -48,12 +48,12 @@ bool Request::isPending() { |
|
|
|
/*******FieldsReq*******/ |
|
|
|
void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB, |
|
|
|
std::unordered_set<std::string> &batchKeySet) |
|
|
|
SliceHashSet &batchKeySet) |
|
|
|
{ |
|
|
|
if (batchKeySet.find(Key.ToString()) != batchKeySet.end()){ |
|
|
|
if (batchKeySet.find(Key) != batchKeySet.end()){ |
|
|
|
return;//并发的被合并的put/delete请求只处理一次
|
|
|
|
} else { |
|
|
|
batchKeySet.insert(Key.ToString()); |
|
|
|
batchKeySet.insert(Key); |
|
|
|
} |
|
|
|
std::string val_str; |
|
|
|
Status s = Status::NotFound("test"); |
|
|
@ -164,12 +164,12 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
/*******DeleteReq*******/ |
|
|
|
void DeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB, |
|
|
|
std::unordered_set<std::string> &batchKeySet) |
|
|
|
SliceHashSet &batchKeySet) |
|
|
|
{ |
|
|
|
if (batchKeySet.find(Key.ToString()) != batchKeySet.end()){ |
|
|
|
if (batchKeySet.find(Key) != batchKeySet.end()){ |
|
|
|
return;//并发的被合并的put/delete请求只处理一次
|
|
|
|
} else { |
|
|
|
batchKeySet.insert(Key.ToString()); |
|
|
|
batchKeySet.insert(Key); |
|
|
|
} |
|
|
|
//1. 读取当前的最新的键值对,判断是否存在含有键值对的field
|
|
|
|
//2.1 如果无,则正常构造delete
|
|
|
@ -263,7 +263,7 @@ void iCreateReq::PendReq(Request *req) { |
|
|
|
|
|
|
|
void iCreateReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB, |
|
|
|
std::unordered_set<std::string> &batchKeySet) |
|
|
|
SliceHashSet &batchKeySet) |
|
|
|
{ |
|
|
|
//遍历数据库,构建二级索引到indexbatch,(更新metaDB中的元数据为Index类型的(Field,Creating))
|
|
|
|
//一个indexwritebatch写入,那么索引创建删除应该和metadb没有交互
|
|
|
@ -322,7 +322,7 @@ void iDeleteReq::PendReq(Request* req) { |
|
|
|
} |
|
|
|
|
|
|
|
void iDeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB,std::unordered_set<std::string> &batchKeySet) |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB,SliceHashSet &batchKeySet) |
|
|
|
{ |
|
|
|
std::vector<std::pair<std::string, std::string>> keysAndVal = |
|
|
|
DB->FindKeysAndValByFieldName(Field); |
|
|
@ -404,10 +404,10 @@ BatchReq::~BatchReq() { |
|
|
|
} |
|
|
|
|
|
|
|
void BatchReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB,std::unordered_set<std::string> &batchKeySet) |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB,SliceHashSet &batchKeySet) |
|
|
|
{ |
|
|
|
WriteBatch Sub_KVBatch,Sub_IndexBatch,Sub_MetaBatch; |
|
|
|
std::unordered_set<std::string> Sub_batchKeySet; |
|
|
|
SliceHashSet Sub_batchKeySet; |
|
|
|
//由于batch是有顺序的,根据我们现在的一个key只处理最开始的算法,这里需要反向迭代
|
|
|
|
uint64_t start_ = DB->env_->NowMicros(); |
|
|
|
for(auto subreq = sub_requests.rbegin(); subreq != sub_requests.rend(); subreq++ ) { |
|
|
|