From 51129477cec2b741301ce76c36f061242d4e1544 Mon Sep 17 00:00:00 2001 From: augurier <14434658+augurier@user.noreply.gitee.com> Date: Sun, 29 Dec 2024 09:05:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=80=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E7=B4=A2=E5=BC=95=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmarks/db_bench_FieldDB.cc | 39 ++++++++++++++++++++++++++++++++++++--- util/serialize_value.cc | 1 + 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/benchmarks/db_bench_FieldDB.cc b/benchmarks/db_bench_FieldDB.cc index 3abf7c5..dfb8f61 100644 --- a/benchmarks/db_bench_FieldDB.cc +++ b/benchmarks/db_bench_FieldDB.cc @@ -63,6 +63,10 @@ static const char* FLAGS_benchmarks = "readreverse," "fill100K," "crc32c," + "CreateIndex," + "FindKeysByField," + "QueryByIndex," + "DeleteIndex," "snappycomp," "snappyuncomp," "zstdcomp," @@ -635,6 +639,14 @@ class Benchmark { method = &Benchmark::Compact; } else if (name == Slice("crc32c")) { method = &Benchmark::Crc32c; + } else if (name == Slice("CreateIndex")) { + method = &Benchmark::CreateIndex; + } else if (name == Slice("FindKeysByField")) { + method = &Benchmark::FindKeysByField; + } else if (name == Slice("QueryByIndex")) { + method = &Benchmark::QueryByIndex; + } else if (name == Slice("DeleteIndex")) { + method = &Benchmark::DeleteIndex; } else if (name == Slice("snappycomp")) { method = &Benchmark::SnappyCompress; } else if (name == Slice("snappyuncomp")) { @@ -664,7 +676,7 @@ class Benchmark { } else { delete db_; db_ = nullptr; - //DestroyDB(FLAGS_db, Options()); + DestroyDB(FLAGS_db, Options()); Open(); } } @@ -821,7 +833,7 @@ class Benchmark { options.compression = FLAGS_compression ? kSnappyCompression : kNoCompression; // Status s = DB::Open(options, FLAGS_db, &db_); - fielddb::DestroyDB(FLAGS_db, options); + //fielddb::DestroyDB(FLAGS_db, options); db_ = new FieldDB(); Status s = FieldDB::OpenFieldDB(options, FLAGS_db, &db_); if (!s.ok()) { @@ -870,7 +882,7 @@ class Benchmark { {"age", age}, {"tag", tag} }; - Slice value = SerializeValue(fields); + std::string value = SerializeValue(fields); batch.Put(key.slice(), value); bytes += value.size() + key.slice().size(); thread->stats.FinishedSingleOp(); @@ -1078,6 +1090,27 @@ class Benchmark { g_env->RemoveFile(fname); } } + + void CreateIndex(ThreadState* thread) { + db_->CreateIndexOnField("age", write_options_); + } + + void FindKeysByField(ThreadState* thread) { + Field f = {"age", "20"}; + std::vector res; + res = db_->FindKeysByField(f); + } + + void QueryByIndex(ThreadState* thread) { + Field f = {"age", "20"}; + Status s; + db_->QueryByIndex(f, &s); + } + + void DeleteIndex(ThreadState* thread) { + db_->DeleteIndex("age", write_options_); + } + }; } // namespace leveldb diff --git a/util/serialize_value.cc b/util/serialize_value.cc index 73fb092..a66aef7 100644 --- a/util/serialize_value.cc +++ b/util/serialize_value.cc @@ -36,6 +36,7 @@ FieldArray *ParseValue(const std::string& value_str,FieldArray *fields){ res->emplace_back(nameStr, valStr); } else { std::cout << "name and val not match! From ParseValue" << std::endl; + assert(0); } nameSlice.clear(); valSlice.clear(); From b3de788556382c690af8c8db37294e9ea28c2b25 Mon Sep 17 00:00:00 2001 From: augurier <14434658+augurier@user.noreply.gitee.com> Date: Sun, 29 Dec 2024 09:47:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9F=A5=E5=87=BA=E4=BA=86=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E6=B5=8B=E8=AF=95destroy=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmarks/db_bench_FieldDB.cc | 5 ++--- benchmarks/db_bench_testDB.cc | 4 ++-- testdb/testdb.cc | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/benchmarks/db_bench_FieldDB.cc b/benchmarks/db_bench_FieldDB.cc index dfb8f61..a07795a 100644 --- a/benchmarks/db_bench_FieldDB.cc +++ b/benchmarks/db_bench_FieldDB.cc @@ -547,7 +547,7 @@ class Benchmark { } } if (!FLAGS_use_existing_db) { - DestroyDB(FLAGS_db, Options()); + fielddb::DestroyDB(FLAGS_db, Options()); } } @@ -676,7 +676,7 @@ class Benchmark { } else { delete db_; db_ = nullptr; - DestroyDB(FLAGS_db, Options()); + fielddb::DestroyDB(FLAGS_db, Options()); Open(); } } @@ -833,7 +833,6 @@ class Benchmark { options.compression = FLAGS_compression ? kSnappyCompression : kNoCompression; // Status s = DB::Open(options, FLAGS_db, &db_); - //fielddb::DestroyDB(FLAGS_db, options); db_ = new FieldDB(); Status s = FieldDB::OpenFieldDB(options, FLAGS_db, &db_); if (!s.ok()) { diff --git a/benchmarks/db_bench_testDB.cc b/benchmarks/db_bench_testDB.cc index 6191132..5a4acb9 100644 --- a/benchmarks/db_bench_testDB.cc +++ b/benchmarks/db_bench_testDB.cc @@ -544,7 +544,7 @@ class Benchmark { } } if (!FLAGS_use_existing_db) { - DestroyDB(FLAGS_db, Options()); + testdb::DestroyDB(FLAGS_db, Options()); } } @@ -665,7 +665,7 @@ class Benchmark { } else { delete db_; db_ = nullptr; - DestroyDB(FLAGS_db, Options()); + testdb::DestroyDB(FLAGS_db, Options()); Open(); } } diff --git a/testdb/testdb.cc b/testdb/testdb.cc index 6baa209..d932f97 100644 --- a/testdb/testdb.cc +++ b/testdb/testdb.cc @@ -2,6 +2,7 @@ #include "db/db_impl.h" #include #include "leveldb/status.h" +#include "testdb.h" using namespace testdb; Status testDB::OpentestDB(Options& options, @@ -93,7 +94,7 @@ void testDB::CompactRange(const Slice *begin, const Slice *end) { kvDB_->CompactRange(begin, end); } -Status DestroyDB(const std::string& name, const Options& options) { +Status testdb::DestroyDB(const std::string& name, const Options& options) { Status s; s = leveldb::DestroyDB(name+"_kvDB", options); assert(s.ok()); @@ -108,4 +109,4 @@ testDB::~testDB() { delete kvDB_; // delete indexDB_; // delete metaDB_; -} \ No newline at end of file +} From 75426ffb064de60dc9ecf06ca882334abae8738e Mon Sep 17 00:00:00 2001 From: augurier <14434658+augurier@user.noreply.gitee.com> Date: Sun, 29 Dec 2024 11:33:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=9B=E5=88=A0=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E5=AF=B9=E8=AF=BB=E5=86=99=E6=80=A7=E8=83=BD=E5=BD=B1=E5=93=8D?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmarks/db_bench_FieldDB.cc | 219 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) diff --git a/benchmarks/db_bench_FieldDB.cc b/benchmarks/db_bench_FieldDB.cc index a07795a..4238ef6 100644 --- a/benchmarks/db_bench_FieldDB.cc +++ b/benchmarks/db_bench_FieldDB.cc @@ -63,10 +63,22 @@ static const char* FLAGS_benchmarks = "readreverse," "fill100K," "crc32c," + "readwhilewriting," "CreateIndex," "FindKeysByField," "QueryByIndex," "DeleteIndex," + "compact," + "WriteSeqWhileCreating," + "WriteSeqWhileDeleting," + "compact," + "WriteRandomWhileCreating," + "WriteRandomWhileDeleting," + "compact," + "ReadSeqWhileCreating," + "ReadSeqWhileDeleting," + "ReadRandomWhileCreating," + "ReadRandomWhileDeleting," "snappycomp," "snappyuncomp," "zstdcomp," @@ -647,6 +659,30 @@ class Benchmark { method = &Benchmark::QueryByIndex; } else if (name == Slice("DeleteIndex")) { method = &Benchmark::DeleteIndex; + } else if (name == Slice("WriteSeqWhileCreating")) { + num_threads++; + method = &Benchmark::WriteSeqWhileCreating; + } else if (name == Slice("WriteSeqWhileDeleting")) { + num_threads++; + method = &Benchmark::WriteSeqWhileDeleting; + } else if (name == Slice("WriteRandomWhileCreating")) { + num_threads++; + method = &Benchmark::WriteRandomWhileCreating; + } else if (name == Slice("WriteRandomWhileDeleting")) { + num_threads++; + method = &Benchmark::WriteRandomWhileDeleting; + } else if (name == Slice("ReadSeqWhileCreating")) { + num_threads++; + method = &Benchmark::ReadSeqWhileCreating; + } else if (name == Slice("ReadSeqWhileDeleting")) { + num_threads++; + method = &Benchmark::ReadSeqWhileDeleting; + } else if (name == Slice("ReadRandomWhileCreating")) { + num_threads++; + method = &Benchmark::ReadRandomWhileCreating; + } else if (name == Slice("ReadRandomWhileDeleting")) { + num_threads++; + method = &Benchmark::ReadRandomWhileDeleting; } else if (name == Slice("snappycomp")) { method = &Benchmark::SnappyCompress; } else if (name == Slice("snappyuncomp")) { @@ -1110,6 +1146,189 @@ class Benchmark { db_->DeleteIndex("age", write_options_); } + void WriteSeqWhileCreating(ThreadState* thread) { + if (thread->tid > 0) { + WriteSeq(thread); + } else { + // Special thread that keeps creating index until other threads are done. + if (db_->GetIndexStatus("age") != IndexStatus::NotExist) { + std::fprintf(stderr, "index status error in WriteWhileCreating\n"); + std::exit(1); + } + + while (true) { + if (db_->GetIndexStatus("age") == IndexStatus::Exist) { + break; + } + + db_->CreateIndexOnField("age", write_options_); + } + + // Do not count any of the preceding work/delay in stats. + thread->stats.Start(); + } + } + + void WriteSeqWhileDeleting(ThreadState* thread) { + if (thread->tid > 0) { + WriteSeq(thread); + } else { + // Special thread that keeps creating index until other threads are done. + if (db_->GetIndexStatus("age") != IndexStatus::Exist) { + std::fprintf(stderr, "index status error in WriteWhileDeleting\n"); + std::exit(1); + } + + while (true) { + if (db_->GetIndexStatus("age") == IndexStatus::NotExist) { + break; + } + + db_->DeleteIndex("age", write_options_); + } + + // Do not count any of the preceding work/delay in stats. + thread->stats.Start(); + } + } + + void WriteRandomWhileCreating(ThreadState* thread) { + if (thread->tid > 0) { + WriteRandom(thread); + } else { + // Special thread that keeps creating index until other threads are done. + if (db_->GetIndexStatus("age") != IndexStatus::NotExist) { + std::fprintf(stderr, "index status error in WriteWhileCreating\n"); + std::exit(1); + } + + while (true) { + if (db_->GetIndexStatus("age") == IndexStatus::Exist) { + break; + } + + db_->CreateIndexOnField("age", write_options_); + } + + // Do not count any of the preceding work/delay in stats. + thread->stats.Start(); + } + } + + void WriteRandomWhileDeleting(ThreadState* thread) { + if (thread->tid > 0) { + WriteRandom(thread); + } else { + // Special thread that keeps creating index until other threads are done. + if (db_->GetIndexStatus("age") != IndexStatus::Exist) { + std::fprintf(stderr, "index status error in WriteWhileDeleting\n"); + std::exit(1); + } + + while (true) { + if (db_->GetIndexStatus("age") == IndexStatus::NotExist) { + break; + } + + db_->DeleteIndex("age", write_options_); + } + + // Do not count any of the preceding work/delay in stats. + thread->stats.Start(); + } + } + + void ReadSeqWhileCreating(ThreadState* thread) { + if (thread->tid > 0) { + ReadSequential(thread); + } else { + // Special thread that keeps creating index until other threads are done. + if (db_->GetIndexStatus("age") != IndexStatus::NotExist) { + std::fprintf(stderr, "index status error in WriteWhileCreating\n"); + std::exit(1); + } + + while (true) { + if (db_->GetIndexStatus("age") == IndexStatus::Exist) { + break; + } + + db_->CreateIndexOnField("age", write_options_); + } + + // Do not count any of the preceding work/delay in stats. + thread->stats.Start(); + } + } + + void ReadSeqWhileDeleting(ThreadState* thread) { + if (thread->tid > 0) { + ReadSequential(thread); + } else { + // Special thread that keeps creating index until other threads are done. + if (db_->GetIndexStatus("age") != IndexStatus::Exist) { + std::fprintf(stderr, "index status error in WriteWhileDeleting\n"); + std::exit(1); + } + + while (true) { + if (db_->GetIndexStatus("age") == IndexStatus::NotExist) { + break; + } + + db_->DeleteIndex("age", write_options_); + } + + // Do not count any of the preceding work/delay in stats. + thread->stats.Start(); + } + } + + void ReadRandomWhileCreating(ThreadState* thread) { + if (thread->tid > 0) { + ReadRandom(thread); + } else { + // Special thread that keeps creating index until other threads are done. + if (db_->GetIndexStatus("age") != IndexStatus::NotExist) { + std::fprintf(stderr, "index status error in WriteWhileCreating\n"); + std::exit(1); + } + + while (true) { + if (db_->GetIndexStatus("age") == IndexStatus::Exist) { + break; + } + + db_->CreateIndexOnField("age", write_options_); + } + + // Do not count any of the preceding work/delay in stats. + thread->stats.Start(); + } + } + + void ReadRandomWhileDeleting(ThreadState* thread) { + if (thread->tid > 0) { + ReadRandom(thread); + } else { + // Special thread that keeps creating index until other threads are done. + if (db_->GetIndexStatus("age") != IndexStatus::Exist) { + std::fprintf(stderr, "index status error in WriteWhileDeleting\n"); + std::exit(1); + } + + while (true) { + if (db_->GetIndexStatus("age") == IndexStatus::NotExist) { + break; + } + + db_->DeleteIndex("age", write_options_); + } + + // Do not count any of the preceding work/delay in stats. + thread->stats.Start(); + } + } }; } // namespace leveldb