|
|
@ -664,7 +664,7 @@ class Benchmark { |
|
|
|
} else { |
|
|
|
delete db_; |
|
|
|
db_ = nullptr; |
|
|
|
DestroyDB(FLAGS_db, Options()); |
|
|
|
//DestroyDB(FLAGS_db, Options());
|
|
|
|
Open(); |
|
|
|
} |
|
|
|
} |
|
|
@ -821,6 +821,7 @@ 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()) { |
|
|
@ -858,8 +859,20 @@ class Benchmark { |
|
|
|
for (int j = 0; j < entries_per_batch_; j++) { |
|
|
|
const int k = seq ? i + j : thread->rand.Uniform(FLAGS_num); |
|
|
|
key.Set(k); |
|
|
|
batch.Put(key.slice(), gen.Generate(value_size_)); |
|
|
|
bytes += value_size_ + key.slice().size(); |
|
|
|
|
|
|
|
std::string name = "customer#" + std::to_string(k); |
|
|
|
//这个字段用来查找
|
|
|
|
std::string age = std::to_string(thread->rand.Uniform(FLAGS_num) % 100); |
|
|
|
//这个字段填充长度
|
|
|
|
std::string tag = gen.Generate(value_size_).ToString(); |
|
|
|
FieldArray fields = { |
|
|
|
{"name", name}, |
|
|
|
{"age", age}, |
|
|
|
{"tag", tag} |
|
|
|
}; |
|
|
|
Slice value = SerializeValue(fields); |
|
|
|
batch.Put(key.slice(), value); |
|
|
|
bytes += value.size() + key.slice().size(); |
|
|
|
thread->stats.FinishedSingleOp(); |
|
|
|
} |
|
|
|
s = db_->Write(write_options_, &batch); |
|
|
@ -899,13 +912,13 @@ class Benchmark { |
|
|
|
|
|
|
|
void ReadRandom(ThreadState* thread) { |
|
|
|
ReadOptions options; |
|
|
|
std::string value; |
|
|
|
int found = 0; |
|
|
|
KeyBuffer key; |
|
|
|
for (int i = 0; i < reads_; i++) { |
|
|
|
const int k = thread->rand.Uniform(FLAGS_num); |
|
|
|
key.Set(k); |
|
|
|
if (db_->Get(options, key.slice(), &value).ok()) { |
|
|
|
FieldArray fields_ret; |
|
|
|
if (db_->GetFields(options, key.slice(), &fields_ret).ok()) { |
|
|
|
found++; |
|
|
|
} |
|
|
|
thread->stats.FinishedSingleOp(); |
|
|
@ -917,26 +930,26 @@ class Benchmark { |
|
|
|
|
|
|
|
void ReadMissing(ThreadState* thread) { |
|
|
|
ReadOptions options; |
|
|
|
std::string value; |
|
|
|
FieldArray fields_ret; |
|
|
|
KeyBuffer key; |
|
|
|
for (int i = 0; i < reads_; i++) { |
|
|
|
const int k = thread->rand.Uniform(FLAGS_num); |
|
|
|
key.Set(k); |
|
|
|
Slice s = Slice(key.slice().data(), key.slice().size() - 1); |
|
|
|
db_->Get(options, s, &value); |
|
|
|
db_->GetFields(options, s, &fields_ret); |
|
|
|
thread->stats.FinishedSingleOp(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ReadHot(ThreadState* thread) { |
|
|
|
ReadOptions options; |
|
|
|
std::string value; |
|
|
|
FieldArray fields_ret; |
|
|
|
const int range = (FLAGS_num + 99) / 100; |
|
|
|
KeyBuffer key; |
|
|
|
for (int i = 0; i < reads_; i++) { |
|
|
|
const int k = thread->rand.Uniform(range); |
|
|
|
key.Set(k); |
|
|
|
db_->Get(options, key.slice(), &value); |
|
|
|
db_->GetFields(options, key.slice(), &fields_ret); |
|
|
|
thread->stats.FinishedSingleOp(); |
|
|
|
} |
|
|
|
} |
|
|
|