Browse Source

fix bug for compaction

version_2
小人鱼 9 months ago
parent
commit
6659764bcd
3 changed files with 12 additions and 15 deletions
  1. +8
    -1
      db/builder.cc
  2. +0
    -11
      db/db_impl.cc
  3. +4
    -3
      test/test.cpp

+ 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);
meta->smallest.DecodeFrom(iter->key());
Slice key;
Slice value;
for (; iter->Valid(); iter->Next()) {
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()) {
meta->largest.DecodeFrom(key);

+ 0
- 11
db/db_impl.cc View File

@ -1575,17 +1575,6 @@ void DBImpl::GetApproximateSizes(const Range* range, int n, uint64_t* sizes) {
v->Unref();
}
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::ofstream valueFile(file_name_, std::ios::app | std::ios::binary);
if (!valueFile.is_open()) {

+ 4
- 3
test/test.cpp View File

@ -167,16 +167,17 @@ TEST(Test, LARGE_DATA_COMPACT_TEST) {
abort();
}
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 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);
}
values.push_back(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 value;
Status s=db->Get(readOptions,key,&value);

Loading…
Cancel
Save