|
@ -286,7 +286,7 @@ void iDeleteReq::Prepare(FieldDB *DB) { |
|
|
done = true; |
|
|
done = true; |
|
|
} else { |
|
|
} else { |
|
|
//如果正在创建或者删除,那么pend到对应的请求上
|
|
|
//如果正在创建或者删除,那么pend到对应的请求上
|
|
|
parent->PendReq(this); |
|
|
|
|
|
|
|
|
parent->PendReq(this->parent); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -334,9 +334,17 @@ BatchReq::BatchReq(WriteBatch *Batch,port::Mutex *mu): |
|
|
void Put(const Slice &key, const Slice &value) override { |
|
|
void Put(const Slice &key, const Slice &value) override { |
|
|
//为key和value构造存储的地方,防止由于string的析构造成可能得内存访问错误
|
|
|
//为key和value构造存储的地方,防止由于string的析构造成可能得内存访问错误
|
|
|
str_buf->push_back(key.ToString()); |
|
|
str_buf->push_back(key.ToString()); |
|
|
fa_buf->push_back({{"",value.ToString()}}); |
|
|
|
|
|
|
|
|
FieldArray *field = new FieldArray; |
|
|
|
|
|
field = ParseValue(value.ToString(), field); |
|
|
|
|
|
if (field == nullptr){ //batch中的value没有field
|
|
|
|
|
|
fa_buf->push_back({{"",value.ToString()}}); |
|
|
|
|
|
} else { |
|
|
|
|
|
fa_buf->push_back(*field); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
sub_requests->emplace_back(new FieldsReq(&str_buf->back(),&fa_buf->back(),mu)); |
|
|
sub_requests->emplace_back(new FieldsReq(&str_buf->back(),&fa_buf->back(),mu)); |
|
|
sub_requests->back()->parent = req; |
|
|
sub_requests->back()->parent = req; |
|
|
|
|
|
delete field; |
|
|
} |
|
|
} |
|
|
void Delete(const Slice &key) override { |
|
|
void Delete(const Slice &key) override { |
|
|
str_buf->push_back(key.ToString()); |
|
|
str_buf->push_back(key.ToString()); |
|
@ -370,10 +378,10 @@ BatchReq::~BatchReq() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void BatchReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
void BatchReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB,std::unordered_set<std::string *> &batchKeySet) |
|
|
|
|
|
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB,std::unordered_set<std::string> &batchKeySet) |
|
|
{ |
|
|
{ |
|
|
WriteBatch Sub_KVBatch,Sub_IndexBatch,Sub_MetaBatch; |
|
|
WriteBatch Sub_KVBatch,Sub_IndexBatch,Sub_MetaBatch; |
|
|
std::unordered_set<std::string *> Sub_batchKeySet; |
|
|
|
|
|
|
|
|
std::unordered_set<std::string> Sub_batchKeySet; |
|
|
//由于batch是有顺序的,根据我们现在的一个key只处理最开始的算法,这里需要反向迭代
|
|
|
//由于batch是有顺序的,根据我们现在的一个key只处理最开始的算法,这里需要反向迭代
|
|
|
for(auto subreq = sub_requests.rbegin(); subreq != sub_requests.rend(); subreq++ ) { |
|
|
for(auto subreq = sub_requests.rbegin(); subreq != sub_requests.rend(); subreq++ ) { |
|
|
(*subreq)->ConstructBatch(Sub_KVBatch, Sub_IndexBatch, Sub_MetaBatch, DB, Sub_batchKeySet); |
|
|
(*subreq)->ConstructBatch(Sub_KVBatch, Sub_IndexBatch, Sub_MetaBatch, DB, Sub_batchKeySet); |
|
@ -386,7 +394,7 @@ void BatchReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
KVBatch.Append(Sub_KVBatch); |
|
|
KVBatch.Append(Sub_KVBatch); |
|
|
IndexBatch.Append(Sub_IndexBatch); |
|
|
IndexBatch.Append(Sub_IndexBatch); |
|
|
MetaBatch.Append(Sub_MetaBatch); |
|
|
MetaBatch.Append(Sub_MetaBatch); |
|
|
batchKeySet.insert(batchKeySet.begin(),batchKeySet.end()); |
|
|
|
|
|
|
|
|
batchKeySet.insert(Sub_batchKeySet.begin(),Sub_batchKeySet.end()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|