From 0c1d366879fb4d50b4b5b2c3417f29a578821a02 Mon Sep 17 00:00:00 2001 From: cyq <1056374449@qq.com> Date: Sat, 28 Dec 2024 17:36:09 +0800 Subject: [PATCH] fix bug --- benchmarks/db_bench.cc | 2 ++ fielddb/field_db.h | 4 ++-- fielddb/request.cpp | 30 ++++++++++++++++-------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/benchmarks/db_bench.cc b/benchmarks/db_bench.cc index 72d962c..4ff7f05 100644 --- a/benchmarks/db_bench.cc +++ b/benchmarks/db_bench.cc @@ -1127,6 +1127,8 @@ int main(int argc, char** argv) { } } + FLAGS_num /= FLAGS_threads; + leveldb::g_env = leveldb::Env::Default(); // Choose a location for the test database if none given with --db= diff --git a/fielddb/field_db.h b/fielddb/field_db.h index 27e8a86..c19e7da 100644 --- a/fielddb/field_db.h +++ b/fielddb/field_db.h @@ -109,7 +109,7 @@ private: uint64_t write_clean_elapsed = 0; uint64_t write_bytes = 0; - uint64_t write_bytes_lim = 20 * 1024 * 1024; + uint64_t write_bytes_lim = 50 * 1024 * 1024; uint64_t temp_elapsed = 0; @@ -135,7 +135,7 @@ private: std::cout << "temp_elased : " << temp_elapsed * 1.0 / count<< std::endl; // std::cout << MetaBatch.ApproximateSize() << " " << IndexBatch.ApproximateSize() << " " << KVBatch.ApproximateSize() << std::endl; std::cout << "=====================================================\n"; - write_bytes_lim = write_bytes + 20 * 1024 * 1024; + write_bytes_lim = write_bytes + 50 * 1024 * 1024; std::fflush(stdout); } } diff --git a/fielddb/request.cpp b/fielddb/request.cpp index b07ab2d..cefb159 100644 --- a/fielddb/request.cpp +++ b/fielddb/request.cpp @@ -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());