|
|
@ -17,6 +17,8 @@ |
|
|
|
namespace fielddb { |
|
|
|
using namespace leveldb; |
|
|
|
|
|
|
|
const char EMPTY[1] = {0}; |
|
|
|
|
|
|
|
//为虚函数提供最基本的实现
|
|
|
|
void Request::PendReq(Request *req) { |
|
|
|
assert(0); |
|
|
@ -77,7 +79,7 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
DB->index_mu.AssertHeld(); |
|
|
|
//1.将存在冲突的put pend到对应的请求
|
|
|
|
for(auto [field_name,field_value] : *Fields) { |
|
|
|
if(field_name == "") break; |
|
|
|
if(field_name == EMPTY) break; |
|
|
|
if(DB->index_.count(field_name)) { |
|
|
|
auto [index_status,parent_req] = DB->index_[field_name]; |
|
|
|
if(index_status == IndexStatus::Creating || index_status == IndexStatus::Deleting) { |
|
|
@ -92,7 +94,7 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
//冲突也可能存在于,需要删除旧数据的索引,但该索引正在创删中
|
|
|
|
if (oldFields != nullptr){ |
|
|
|
for(auto [field_name,field_value] : *oldFields) { |
|
|
|
if(field_name == "") break; |
|
|
|
if(field_name == EMPTY) break; |
|
|
|
if(DB->index_.count(field_name)) { |
|
|
|
auto [index_status,parent_req] = DB->index_[field_name]; |
|
|
|
if(index_status == IndexStatus::Creating || index_status == IndexStatus::Deleting) { |
|
|
@ -119,7 +121,7 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
//3.1对于含有索引的oldfield删除索引
|
|
|
|
if (HasOldIndex) { |
|
|
|
for(auto [field_name,field_value] : *oldFields) { |
|
|
|
if(field_name == "") continue; |
|
|
|
if(field_name == EMPTY) continue; |
|
|
|
if(DB->index_.count(field_name)) { |
|
|
|
std::string indexKey; |
|
|
|
AppendIndexKey(&indexKey, ParsedInternalIndexKey( |
|
|
@ -132,7 +134,7 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
//3.2对于含有索引的field建立索引
|
|
|
|
if (HasIndex) { |
|
|
|
for(auto [field_name,field_value] : *Fields) { |
|
|
|
if(field_name == "") continue; |
|
|
|
if(field_name == EMPTY) continue; |
|
|
|
if(DB->index_.count(field_name)) { |
|
|
|
std::string indexKey; |
|
|
|
AppendIndexKey(&indexKey, ParsedInternalIndexKey( |
|
|
@ -177,7 +179,7 @@ void DeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
DB->index_mu.AssertHeld(); |
|
|
|
//1.将存在冲突的delete pend到对应的请求
|
|
|
|
for(auto [field_name,field_value] : *Fields) { |
|
|
|
if(field_name == "") break; |
|
|
|
if(field_name == EMPTY) break; |
|
|
|
if(DB->index_.count(field_name)) { |
|
|
|
auto [index_status,parent_req] = DB->index_[field_name]; |
|
|
|
if(index_status == IndexStatus::Creating || index_status == IndexStatus::Deleting) { |
|
|
@ -198,7 +200,7 @@ void DeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
MetaBatch.Put(MetaKey, Slice()); |
|
|
|
//3.对于含有索引的field删除索引
|
|
|
|
for(auto [field_name,field_value] : *Fields) { |
|
|
|
if(field_name == "") continue; |
|
|
|
if(field_name == EMPTY) continue; |
|
|
|
if(DB->index_.count(field_name)) { |
|
|
|
std::string indexKey; |
|
|
|
AppendIndexKey(&indexKey, ParsedInternalIndexKey( |
|
|
@ -338,17 +340,17 @@ BatchReq::BatchReq(WriteBatch *Batch,port::Mutex *mu): |
|
|
|
void Put(const Slice &key, const Slice &value) override { |
|
|
|
//为key和value构造存储的地方,防止由于string的析构造成可能得内存访问错误
|
|
|
|
str_buf->push_back(key.ToString()); |
|
|
|
FieldArray *field = new FieldArray; |
|
|
|
field = ParseValue(value.ToString(), field); |
|
|
|
if (field->empty()){ //batch中的value没有field
|
|
|
|
fa_buf->push_back({{"",value.ToString()}}); |
|
|
|
} else { |
|
|
|
fa_buf->push_back(*field); |
|
|
|
} |
|
|
|
fa_buf->push_back({{EMPTY,value.ToString()}}); |
|
|
|
// FieldArray *field = new FieldArray;
|
|
|
|
// field = ParseValue(value.ToString(), field);
|
|
|
|
// if (field->empty()){ //batch中的value没有field
|
|
|
|
// } else {
|
|
|
|
// fa_buf->push_back(*field);
|
|
|
|
// }
|
|
|
|
|
|
|
|
sub_requests->emplace_back(new FieldsReq(&str_buf->back(),&fa_buf->back(),mu)); |
|
|
|
sub_requests->back()->parent = req; |
|
|
|
delete field; |
|
|
|
// delete field;
|
|
|
|
} |
|
|
|
void Delete(const Slice &key) override { |
|
|
|
str_buf->push_back(key.ToString()); |
|
|
|