Compare commits

...

5 Commits

4 changed files with 16 additions and 19 deletions
Unified View
  1. +3
    -3
      benchmarks/db_bench.cc
  2. +8
    -1
      db/builder.cc
  3. +1
    -12
      db/db_impl.cc
  4. +4
    -3
      test/test.cpp

+ 3
- 3
benchmarks/db_bench.cc View File

@ -74,7 +74,7 @@ static int FLAGS_reads = -1;
static int FLAGS_threads = 1; static int FLAGS_threads = 1;
// Size of each value // Size of each value
static int FLAGS_value_size = 100;
static int FLAGS_value_size = 5000;
// Arrange to generate values that shrink to this fraction of // Arrange to generate values that shrink to this fraction of
// their original size after compression // their original size after compression
@ -1127,8 +1127,8 @@ int main(int argc, char** argv) {
// Choose a location for the test database if none given with --db=<path> // Choose a location for the test database if none given with --db=<path>
if (FLAGS_db == nullptr) { if (FLAGS_db == nullptr) {
leveldb::g_env->GetTestDirectory(&default_db_path);
default_db_path += "/dbbench";
//leveldb::g_env->GetTestDirectory(&default_db_path);
default_db_path = "dbbench";
FLAGS_db = default_db_path.c_str(); FLAGS_db = default_db_path.c_str();
} }

+ 8
- 1
db/builder.cc View File

@ -40,9 +40,16 @@ Status BuildTable(const std::string& dbname, Env* env, const Options& options,
TableBuilder* builder = new TableBuilder(options, file); TableBuilder* builder = new TableBuilder(options, file);
meta->smallest.DecodeFrom(iter->key()); meta->smallest.DecodeFrom(iter->key());
Slice key; Slice key;
Slice value;
for (; iter->Valid(); iter->Next()) { for (; iter->Valid(); iter->Next()) {
key = iter->key(); key = iter->key();
builder->Add(key, iter->value());
value=iter->value();
if(meta->valuelog_id==0&&value.size()>0&&value.data()[0]==(char)(0x01)){
Slice tmp_value=value;
tmp_value.remove_prefix(1);
assert(GetVarint64(&tmp_value,&meta->valuelog_id));
}
builder->Add(key, value);
} }
if (!key.empty()) { if (!key.empty()) {
meta->largest.DecodeFrom(key); meta->largest.DecodeFrom(key);

+ 1
- 12
db/db_impl.cc View File

@ -1234,7 +1234,7 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key,
mem->Unref(); mem->Unref();
if (imm != nullptr) imm->Unref(); if (imm != nullptr) imm->Unref();
current->Unref(); current->Unref();
if(!s.ok())return s;
if(value->c_str()[0]==0x00){ if(value->c_str()[0]==0x00){
*value=value->substr(1); *value=value->substr(1);
return s; return s;
@ -1575,17 +1575,6 @@ void DBImpl::GetApproximateSizes(const Range* range, int n, uint64_t* sizes) {
v->Unref(); v->Unref();
} }
std::vector<std::pair<uint64_t,std::pair<uint64_t,uint64_t>>> DBImpl::WriteValueLog(std::vector<Slice> values){ std::vector<std::pair<uint64_t,std::pair<uint64_t,uint64_t>>> DBImpl::WriteValueLog(std::vector<Slice> values){
//lock
// std::vector<std::pair<uint64_t,std::pair<uint64_t,uint64_t>>> res;
// for(int i=0;i<values.size();i++){
// int len=values[i].size();
// valuelogfile_->Append(values[i]);
// res.push_back({valuelogfile_number_,{valuelogfile_offset,len}});
// valuelogfile_offset+=len;
// }
// //unlock
// valuelogfile_->Flush();
// return res;
std::string file_name_=ValueLogFileName(dbname_,valuelogfile_number_); std::string file_name_=ValueLogFileName(dbname_,valuelogfile_number_);
std::ofstream valueFile(file_name_, std::ios::app | std::ios::binary); std::ofstream valueFile(file_name_, std::ios::app | std::ios::binary);
if (!valueFile.is_open()) { if (!valueFile.is_open()) {

+ 4
- 3
test/test.cpp View File

@ -167,16 +167,17 @@ TEST(Test, LARGE_DATA_COMPACT_TEST) {
abort(); abort();
} }
std::vector<std::string> values; std::vector<std::string> values;
for(int i=0;i<500000;i++){
for(int i=0;i<5000;i++){
std::string key=std::to_string(i); std::string key=std::to_string(i);
std::string value; std::string value;
for(int j=0;j<1000;j++){
int len=rand()%496+5;
for(int j=0;j<len;j++){
value+=std::to_string(i); value+=std::to_string(i);
} }
values.push_back(value); values.push_back(value);
db->Put(writeOptions,key,value); db->Put(writeOptions,key,value);
} }
for(int i=0;i<500000;i++){
for(int i=0;i<5000;i++){
std::string key=std::to_string(i); std::string key=std::to_string(i);
std::string value; std::string value;
Status s=db->Get(readOptions,key,&value); Status s=db->Get(readOptions,key,&value);

Loading…
Cancel
Save