Compare commits

...

3 Commits

Author SHA1 Message Date
  ArcueidType 0980c4f110 update baseline benchmark 8 months ago
  ArcueidType a9a8a8d73d baseline benchmark 8 months ago
  Arcueid 0b3316e485 append basic io test for baseline 8 months ago
9 changed files with 113 additions and 10 deletions
Split View
  1. +0
    -1
      .idea/misc.xml
  2. +5
    -0
      CMakeLists.txt
  3. +10
    -5
      benchmarks/db_bench.cc
  4. +14
    -3
      db/db_impl.cc
  5. +2
    -0
      db/fields.cc
  6. +3
    -0
      db/fields.h
  7. +2
    -0
      db/filename.cc
  8. +2
    -1
      db/filename.h
  9. +75
    -0
      test/test_basicio.cc

+ 0
- 1
.idea/misc.xml View File

@ -4,7 +4,6 @@
<option name="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue" value="false" type="bool" />
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexedValue" value="true" type="bool" />
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexRemoved" />
<option name="/Default/Environment/Hierarchy/GeneratedFilesCacheKey/Timestamp/@EntryValue" value="5" type="long" />
</component>
<component name="CMakePythonSetting">

+ 5
- 0
CMakeLists.txt View File

@ -524,3 +524,8 @@ add_executable(test_fields
"${PROJECT_SOURCE_DIR}/test/test_fields.cc"
)
target_link_libraries(test_fields PRIVATE leveldb gtest)
add_executable(test_basicio
"${PROJECT_SOURCE_DIR}/test/test_basicio.cc"
)
target_link_libraries(test_basicio PRIVATE leveldb gtest)

+ 10
- 5
benchmarks/db_bench.cc View File

@ -74,7 +74,7 @@ static int FLAGS_reads = -1;
static int FLAGS_threads = 1;
// Size of each value
static int FLAGS_value_size = 100;
static int FLAGS_value_size = 1000;
// Arrange to generate values that shrink to this fraction of
// their original size after compression
@ -852,8 +852,13 @@ 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();
auto value = gen.Generate(value_size_);
FieldArray field_array = {
{"1", value.ToString()},
};
auto encoded_value = Fields(field_array).Serialize();
batch.Put(key.slice(), Slice(encoded_value));
bytes += encoded_value.size() + key.slice().size();
thread->stats.FinishedSingleOp();
}
s = db_->Write(write_options_, &batch);
@ -870,7 +875,7 @@ class Benchmark {
int i = 0;
int64_t bytes = 0;
for (iter->SeekToFirst(); i < reads_ && iter->Valid(); iter->Next()) {
bytes += iter->key().size() + iter->value().size();
bytes += iter->key().size() + iter->fields().size();
thread->stats.FinishedSingleOp();
++i;
}
@ -883,7 +888,7 @@ class Benchmark {
int i = 0;
int64_t bytes = 0;
for (iter->SeekToLast(); i < reads_ && iter->Valid(); iter->Prev()) {
bytes += iter->key().size() + iter->value().size();
bytes += iter->key().size() + iter->fields().size();
thread->stats.FinishedSingleOp();
++i;
}

+ 14
- 3
db/db_impl.cc View File

@ -257,6 +257,9 @@ void DBImpl::RemoveObsoleteFiles() {
case kTableFile:
keep = (live.find(number) != live.end());
break;
case kVTableFile:
keep = (live.find(number) != live.end());
break;
case kTempFile:
// Any temp files that are currently being written to must
// be recorded in pending_outputs_, which is inserted into "live"
@ -1153,8 +1156,12 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key,
s = current->Get(options, lkey, value, &stats);
have_stat_update = true;
}
auto fields = Fields(Slice(*value));
*value = fields["1"];
if (s.ok()) {
auto fields = Fields(Slice(*value));
*value = fields["1"];
} else {
*value = "";
}
mutex_.Lock();
}
@ -1203,7 +1210,11 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key,
s = current->Get(options, lkey, value, &stats);
have_stat_update = true;
}
*fields = Fields(Slice(*value));
if (s.ok()) {
*fields = Fields(Slice(*value));
} else {
*fields = Fields();
}
mutex_.Lock();
}

+ 2
- 0
db/fields.cc View File

@ -7,6 +7,7 @@ namespace leveldb {
assert(!field_array.empty());
for (const auto& field : field_array) {
this->_fields[field.first] = field.second;
this->size_ += field.first.size() + field.second.size();
}
}
@ -25,6 +26,7 @@ namespace leveldb {
Slice value = Slice(field.data() + name_size, field.size() - name_size);
this->_fields[name.ToString()] = value.ToString();
this->size_ += name.ToString().size() + value.ToString().size();
fields = Slice(fields.data() + field_size, fields.size() - field_size);
}

+ 3
- 0
db/fields.h View File

@ -33,8 +33,11 @@ namespace leveldb {
// Fields编码为存入LevelDB的Value
std::string Serialize() const;
uint64_t size() const { return size_; }
private:
std::map<std::string, std::string> _fields;
uint64_t size_ = 0;
};
} // namespace leveldb
#endif //STORAGE_LEVELDB_FIELDS_H_

+ 2
- 0
db/filename.cc View File

@ -112,6 +112,8 @@ bool ParseFileName(const std::string& filename, uint64_t* number,
*type = kTableFile;
} else if (suffix == Slice(".dbtmp")) {
*type = kTempFile;
} else if (suffix == Slice(".vtb")) {
*type = kVTableFile;
} else {
return false;
}

+ 2
- 1
db/filename.h View File

@ -25,7 +25,8 @@ enum FileType {
kDescriptorFile,
kCurrentFile,
kTempFile,
kInfoLogFile // Either the current one, or an old one
kInfoLogFile, // Either the current one, or an old one
kVTableFile
};
// Return the name of the log file with the specified number

+ 75
- 0
test/test_basicio.cc View File

@ -0,0 +1,75 @@
#include "gtest/gtest.h"
#include "leveldb/env.h"
#include "leveldb/db.h"
using namespace leveldb;
constexpr int value_size = 2048;
constexpr int data_size = 128 << 20;
std::map<std::string, std::string> data;
Status OpenDB(std::string dbName, DB **db) {
Options options;
options.create_if_missing = true;
return DB::Open(options, dbName, db);
}
void InsertData(DB *db) {
WriteOptions writeOptions;
int key_num = data_size / value_size;
srand(0);
for (int i = 0; i < key_num; i++) {
int key_ = rand() % key_num+1;
std::string key = std::to_string(key_);
std::string value(value_size, 'a');
db->Put(writeOptions, key, value);
data[key] = value;
}
}
TEST(TestBasicIO, PointGet) {
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
data.clear();
InsertData(db);
ReadOptions readOptions;
for (auto iter = data.begin(); iter != data.end(); ++iter) {
std::string value;
db->Get(readOptions, iter->first, &value);
ASSERT_TRUE(value == iter->second);
}
delete db;
}
TEST(TestBasicIO, RangeQuery) {
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
data.clear();
InsertData(db);
ReadOptions readOptions;
auto iter = db->NewIterator(readOptions);
iter->SeekToFirst();
while (iter->Valid()) {
ASSERT_TRUE(data[iter->key().ToString()] == iter->fields()["1"]);
iter->Next();
}
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

Loading…
Cancel
Save