|
|
@ -19,7 +19,8 @@ void Request::PendReq(Request *req) { |
|
|
|
|
|
|
|
//为虚函数提供最基本的实现
|
|
|
|
void Request::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) |
|
|
|
{ |
|
|
|
assert(0); |
|
|
|
} |
|
|
@ -41,12 +42,13 @@ bool Request::isPending() { |
|
|
|
|
|
|
|
/*******FieldsReq*******/ |
|
|
|
void FieldsReq::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) |
|
|
|
{ |
|
|
|
if (batchKeySet.find(Key) != batchKeySet.end()){ |
|
|
|
if (batchKeySet.find(*Key) != batchKeySet.end()){ |
|
|
|
return;//并发的被合并的put/delete请求只处理一次
|
|
|
|
} else { |
|
|
|
batchKeySet.insert(Key); |
|
|
|
batchKeySet.insert(*Key); |
|
|
|
} |
|
|
|
std::string val_str; |
|
|
|
Status s = DB->kvDB_->Get(ReadOptions(), *Key, &val_str); |
|
|
@ -59,8 +61,6 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
assert(0); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
KVBatch.Put(Slice(*Key), Slice(SerializeValue(*Fields))); |
|
|
|
bool HasIndex = false; |
|
|
|
bool HasOldIndex = false; |
|
|
|
{ |
|
|
@ -96,7 +96,8 @@ void FieldsReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
KVBatch.Put(Slice(*Key), Slice(SerializeValue(*Fields))); |
|
|
|
//2.对于没有冲突但含有索引操作的put,构建metaKV,这里直接将KV对简单编码后写入metaDB
|
|
|
|
if(HasIndex || HasOldIndex) { |
|
|
|
Slice MetaKey,MetaValue; |
|
|
@ -140,12 +141,13 @@ 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) |
|
|
|
WriteBatch &MetaBatch,fielddb::FieldDB *DB, |
|
|
|
std::unordered_set<std::string> &batchKeySet) |
|
|
|
{ |
|
|
|
if (batchKeySet.find(Key) != batchKeySet.end()){ |
|
|
|
if (batchKeySet.find(*Key) != batchKeySet.end()){ |
|
|
|
return;//并发的被合并的put/delete请求只处理一次
|
|
|
|
} else { |
|
|
|
batchKeySet.insert(Key); |
|
|
|
batchKeySet.insert(*Key); |
|
|
|
} |
|
|
|
//1. 读取当前的最新的键值对,判断是否存在含有键值对的field
|
|
|
|
//2.1 如果无,则正常构造delete
|
|
|
@ -153,9 +155,9 @@ void DeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
//在kvDB和metaDB中写入对应的delete
|
|
|
|
//2.3 如果存在field的索引状态是Creating或者Deleting,那么在那个队列上面进行等待
|
|
|
|
std::string val_str; |
|
|
|
DB->kvDB_->Get(ReadOptions(), *Key, &val_str); |
|
|
|
Status s = DB->kvDB_->Get(ReadOptions(), *Key, &val_str); |
|
|
|
if (s.IsNotFound()) return; |
|
|
|
FieldArray *Fields = ParseValue(val_str); |
|
|
|
KVBatch.Delete(Slice(*Key)); |
|
|
|
bool HasIndex = false; |
|
|
|
{ |
|
|
|
// MutexLock L(&DB->index_mu); //互斥访问索引状态表
|
|
|
@ -174,6 +176,7 @@ void DeleteReq::ConstructBatch(WriteBatch &KVBatch,WriteBatch &IndexBatch, |
|
|
|
//assert(0);
|
|
|
|
} |
|
|
|
} |
|
|
|
KVBatch.Delete(Slice(*Key)); |
|
|
|
//2.对于没有冲突但含有索引操作的delete,构建metaKV,这里直接将KV对简单编码后写入metaDB
|
|
|
|
if(HasIndex) { |
|
|
|
Slice MetaKey; |
|
|
@ -223,7 +226,8 @@ void iCreateReq::PendReq(Request *req) { |
|
|
|
} |
|
|
|
|
|
|
|
void iCreateReq::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) |
|
|
|
{ |
|
|
|
//遍历数据库,构建二级索引到indexbatch,(更新metaDB中的元数据为Index类型的(Field,Creating))
|
|
|
|
//一个indexwritebatch写入,那么索引创建删除应该和metadb没有交互
|
|
|
@ -282,7 +286,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,std::unordered_set<std::string> &batchKeySet) |
|
|
|
{ |
|
|
|
std::vector<std::pair<std::string, std::string>> keysAndVal = |
|
|
|
DB->FindKeysAndValByFieldName(*Field); |
|
|
|