|
|
@ -107,7 +107,7 @@ Status FieldDB::Recover() { |
|
|
|
//在所有的请求完成后,会自动把metaDB的内容清空。
|
|
|
|
Iter = metaDB_->NewIterator(ReadOptions()); |
|
|
|
Iter->SeekToFirst(); |
|
|
|
std::cout << "Iter Valid : " << Iter->Valid() << std::endl; |
|
|
|
//std::cout << "Iter Valid : " << Iter->Valid() << std::endl;
|
|
|
|
delete Iter; |
|
|
|
//3. 等待所有请求完成
|
|
|
|
return Status::OK(); |
|
|
@ -125,7 +125,7 @@ Request *FieldDB::GetHandleInterval() { |
|
|
|
return tail; |
|
|
|
} |
|
|
|
|
|
|
|
Status FieldDB::HandleRequest(Request &req) { |
|
|
|
Status FieldDB::HandleRequest(Request &req, const WriteOptions &op) { |
|
|
|
uint64_t start_ = env_->NowMicros(); |
|
|
|
MutexLock L(&mutex_); |
|
|
|
taskqueue_.push_back(&req); |
|
|
@ -156,7 +156,6 @@ Status FieldDB::HandleRequest(Request &req) { |
|
|
|
//此处可以放锁是因为写入的有序性可以通过队列来保证
|
|
|
|
mutex_.Unlock(); |
|
|
|
uint64_t start_write = env_->NowMicros(); |
|
|
|
WriteOptions op; |
|
|
|
if(MetaBatch.ApproximateSize() > 12) { |
|
|
|
uint64_t start_meta = env_->NowMicros(); |
|
|
|
status = metaDB_->Write(op, &MetaBatch); |
|
|
@ -215,7 +214,7 @@ Status FieldDB::HandleRequest(Request &req) { |
|
|
|
|
|
|
|
elapsed += env_->NowMicros() - start_; |
|
|
|
count ++; |
|
|
|
dumpStatistics(); |
|
|
|
//dumpStatistics();
|
|
|
|
|
|
|
|
if(!taskqueue_.empty()) { |
|
|
|
taskqueue_.front()->cond_.Signal(); |
|
|
@ -240,7 +239,7 @@ Status FieldDB::PutFields(const WriteOptions &Options, |
|
|
|
|
|
|
|
FieldsReq req(&key_,&fields_,&mutex_); |
|
|
|
|
|
|
|
Status status = HandleRequest(req); |
|
|
|
Status status = HandleRequest(req, Options); |
|
|
|
return status; |
|
|
|
} |
|
|
|
|
|
|
@ -249,7 +248,7 @@ Status FieldDB::Delete(const WriteOptions &options, const Slice &key) { |
|
|
|
|
|
|
|
std::string key_ = key.ToString(); |
|
|
|
DeleteReq req(&key_,&mutex_); |
|
|
|
Status status = HandleRequest(req); |
|
|
|
Status status = HandleRequest(req, options); |
|
|
|
return status; |
|
|
|
} |
|
|
|
|
|
|
@ -266,7 +265,7 @@ Status FieldDB::Write(const WriteOptions &options, WriteBatch *updates) { |
|
|
|
uint64_t start_ = env_->NowMicros(); |
|
|
|
BatchReq req(updates,&mutex_); |
|
|
|
construct_BatchReq_init_elapsed += env_->NowMicros() - start_; |
|
|
|
Status status = HandleRequest(req); |
|
|
|
Status status = HandleRequest(req, options); |
|
|
|
return status; |
|
|
|
} |
|
|
|
//由于常规put将空串作为name,这里也需要适当修改
|
|
|
@ -305,10 +304,10 @@ std::vector> FieldDB::FindKeysAndValByFieldN |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
Status FieldDB::CreateIndexOnField(const std::string& field_name) { |
|
|
|
Status FieldDB::CreateIndexOnField(const std::string& field_name, const WriteOptions &op) { |
|
|
|
std::string Field = field_name; |
|
|
|
iCreateReq req(&Field,&mutex_); |
|
|
|
HandleRequest(req); |
|
|
|
HandleRequest(req, op); |
|
|
|
//如果已经存在索引,那么直接返回
|
|
|
|
if(req.Existed) { |
|
|
|
return req.s; |
|
|
@ -316,15 +315,15 @@ Status FieldDB::CreateIndexOnField(const std::string& field_name) { |
|
|
|
WriteBatch KVBatch,IndexBatch,MetaBatch; |
|
|
|
std::unordered_set<std::string> useless; |
|
|
|
req.ConstructBatch(KVBatch, IndexBatch, MetaBatch, this, useless); |
|
|
|
indexDB_->Write(WriteOptionspan>(), &IndexBatch); |
|
|
|
indexDB_->Write(op, &IndexBatch); |
|
|
|
req.Finalize(this); |
|
|
|
return req.s; |
|
|
|
} |
|
|
|
|
|
|
|
Status FieldDB::DeleteIndex(const std::string &field_name) { |
|
|
|
Status FieldDB::DeleteIndex(const std::string &field_name, const WriteOptions &op) { |
|
|
|
std::string Field = field_name; |
|
|
|
iDeleteReq req(&Field,&mutex_); |
|
|
|
HandleRequest(req); |
|
|
|
HandleRequest(req, op); |
|
|
|
//如果已经被删除或者不存在,那么可以直接返回
|
|
|
|
if(req.Deleted) { |
|
|
|
return req.s; |
|
|
@ -332,7 +331,7 @@ Status FieldDB::DeleteIndex(const std::string &field_name) { |
|
|
|
WriteBatch KVBatch,IndexBatch,MetaBatch; |
|
|
|
std::unordered_set<std::string> useless; |
|
|
|
req.ConstructBatch(KVBatch, IndexBatch, MetaBatch, this, useless); |
|
|
|
indexDB_->Write(WriteOptionspan>(), &IndexBatch); |
|
|
|
indexDB_->Write(op, &IndexBatch); |
|
|
|
req.Finalize(this); |
|
|
|
return req.s; |
|
|
|
} |
|
|
|