Browse Source

update unorderediter

pull/3/head
dgy 8 months ago
parent
commit
9a270859a7
3 changed files with 30 additions and 13 deletions
  1. +2
    -1
      db/db_impl.cc
  2. +2
    -2
      db/dbformat.h
  3. +26
    -10
      db/unordered_iter.cc

+ 2
- 1
db/db_impl.cc View File

@ -1766,7 +1766,7 @@ Status DBImpl::ReadValueLog(uint64_t file_id, uint64_t offset,
std::string file_name_ = ValueLogFileName(dbname_, file_id);
mutex_.Lock();
if(file_id==valuelogfile_number_){
if(file_id==valuelogfile_number_||config::mem_value_log_number==0){
mutex_.Unlock();
std::ifstream inFile(file_name_, std::ios::in | std::ios::binary);
@ -1776,6 +1776,7 @@ Status DBImpl::ReadValueLog(uint64_t file_id, uint64_t offset,
char buf[value_len];
inFile.read(buf,value_len);
inFile.close();
*value=std::string(buf,value_len);
return Status::OK();
}

+ 2
- 2
db/dbformat.h View File

@ -47,9 +47,9 @@ static const int kReadBytesPeriod = 1048576;
// maximum size of value_log file
static const int value_log_size=1<<26;
//1<<33/1<<26=1<<7
static const int mem_value_log_number=1<<8;//8GB
static const int mem_value_log_number=0;//8GB
static const int max_unorder_iter_memory_usage=32<<20; //32MB
static const int max_unorder_iter_memory_usage=64<<20; //32MB
} // namespace config

+ 26
- 10
db/unordered_iter.cc View File

@ -52,6 +52,8 @@ class UnorderedIter : public Iterator {
current_file->close();
delete current_file;
}
if(buf_for_now_key)delete buf_for_now_key;
if(buf_for_now_value)delete buf_for_now_value;
delete iter_;
}
bool Valid() const override { return mode!=2; }
@ -91,18 +93,25 @@ class UnorderedIter : public Iterator {
current_file->seekg(offset);
current_file->read((char*)(&value_len),sizeof(uint64_t));
char buf[value_len];
current_file->read(buf,value_len);
buf_for_now_value=std::string(buf,value_len);
if(value_len>buf_for_now_value_size){
buf_for_now_value_size=value_len;
if(buf_for_now_value)delete buf_for_now_value;
buf_for_now_value=new char[value_len];
}
current_file->read(buf_for_now_value,value_len);
current_file->read((char*)(&key_len),sizeof(uint64_t));
char key_buf[key_len];
current_file->read(key_buf,key_len);
buf_for_now_key=std::string(key_buf,key_len);
if(key_len>buf_for_now_key_size){
buf_for_now_key_size=key_len;
if(buf_for_now_key)delete buf_for_now_key;
buf_for_now_key=new char[key_len];
}
current_file->read(buf_for_now_key,key_len);
now_key=Slice(buf_for_now_key);
now_value=Slice(buf_for_now_value);
now_value=Slice(buf_for_now_value,value_len);
now_key=Slice(buf_for_now_key,key_len);
}
@ -110,8 +119,10 @@ class UnorderedIter : public Iterator {
Iterator* const iter_;
Slice now_value;
Slice now_key;
std::string buf_for_now_key;
std::string buf_for_now_value;
int buf_for_now_key_size=0;
char* buf_for_now_key=nullptr;
int buf_for_now_value_size=0;
char* buf_for_now_value=nullptr;
bool iter_valid=false;
std::map<uint64_t,std::vector<uint64_t>> valuelog_map;
int memory_usage=0;
@ -156,6 +167,11 @@ void UnorderedIter::Next() {
valuelog_map_iter=valuelog_map.begin();
if(valuelog_map_iter!=valuelog_map.end()){
for(auto it=valuelog_map.begin();it!=valuelog_map.end();it++){
std::sort(it->second.begin(),it->second.end());
}
std::string file_name_ = ValueLogFileName(db_name_, valuelog_map_iter->first);
assert(!current_file);
current_file=new std::ifstream(file_name_, std::ios::in | std::ios::binary);

Loading…
Cancel
Save