|
@ -518,6 +518,7 @@ Status DBImpl::WriteLevel0Table(MemTable* mem, VersionEdit* edit, |
|
|
const uint64_t start_micros = env_->NowMicros(); |
|
|
const uint64_t start_micros = env_->NowMicros(); |
|
|
FileMetaData meta; |
|
|
FileMetaData meta; |
|
|
meta.number = versions_->NewFileNumber(); |
|
|
meta.number = versions_->NewFileNumber(); |
|
|
|
|
|
meta.valuelog_id = versions_->NewFileNumber(); |
|
|
pending_outputs_.insert(meta.number); |
|
|
pending_outputs_.insert(meta.number); |
|
|
Iterator* iter = mem->NewIterator(); |
|
|
Iterator* iter = mem->NewIterator(); |
|
|
Log(options_.info_log, "Level-0 table #%llu: started", |
|
|
Log(options_.info_log, "Level-0 table #%llu: started", |
|
@ -1092,14 +1093,6 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { |
|
|
if (status.ok()) { |
|
|
if (status.ok()) { |
|
|
status = input->status(); |
|
|
status = input->status(); |
|
|
} |
|
|
} |
|
|
//not completely correct, should be written in new function, related to removeabsol...
|
|
|
|
|
|
// if(status.ok()){
|
|
|
|
|
|
// for(auto id:old_valuelog_ids){
|
|
|
|
|
|
// auto valuelog_filename=ValueLogFileName(dbname_,id);
|
|
|
|
|
|
// Status s=env_->RemoveFile(valuelog_filename);
|
|
|
|
|
|
// assert(s.ok());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
delete input; |
|
|
delete input; |
|
|
input = nullptr; |
|
|
input = nullptr; |
|
|
|
|
|
|
|
@ -1314,7 +1307,6 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* updates) { |
|
|
Writer* last_writer = &w; |
|
|
Writer* last_writer = &w; |
|
|
if (status.ok() && updates != nullptr) { // nullptr batch is for compactions
|
|
|
if (status.ok() && updates != nullptr) { // nullptr batch is for compactions
|
|
|
WriteBatch* write_batch = BuildBatchGroup(&last_writer); |
|
|
WriteBatch* write_batch = BuildBatchGroup(&last_writer); |
|
|
WriteBatchInternal::ConverToValueLog(write_batch,this); |
|
|
|
|
|
WriteBatchInternal::SetSequence(write_batch, last_sequence + 1); |
|
|
WriteBatchInternal::SetSequence(write_batch, last_sequence + 1); |
|
|
last_sequence += WriteBatchInternal::Count(write_batch); |
|
|
last_sequence += WriteBatchInternal::Count(write_batch); |
|
|
|
|
|
|
|
@ -1480,7 +1472,6 @@ Status DBImpl::MakeRoomForWrite(bool force) { |
|
|
RecordBackgroundError(s); |
|
|
RecordBackgroundError(s); |
|
|
} |
|
|
} |
|
|
delete logfile_; |
|
|
delete logfile_; |
|
|
addNewValueLog(); |
|
|
|
|
|
logfile_ = lfile; |
|
|
logfile_ = lfile; |
|
|
logfile_number_ = new_log_number; |
|
|
logfile_number_ = new_log_number; |
|
|
log_ = new log::Writer(lfile); |
|
|
log_ = new log::Writer(lfile); |
|
@ -1574,55 +1565,12 @@ 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){ |
|
|
|
|
|
//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()) { |
|
|
|
|
|
assert(0); |
|
|
|
|
|
} |
|
|
|
|
|
uint64_t offset=valueFile.tellp(); |
|
|
|
|
|
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(); |
|
|
|
|
|
valueFile.write(values[i].data(),len); |
|
|
|
|
|
res.push_back({valuelogfile_number_,{offset,len}}); |
|
|
|
|
|
offset+=len; |
|
|
|
|
|
} |
|
|
|
|
|
//unlock
|
|
|
|
|
|
valueFile.close(); |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
void DBImpl::writeValueLogForCompaction(WritableFile* target_file,std::vector<Slice> values){ |
|
|
void DBImpl::writeValueLogForCompaction(WritableFile* target_file,std::vector<Slice> values){ |
|
|
for(int i=0;i<values.size();i++){ |
|
|
for(int i=0;i<values.size();i++){ |
|
|
target_file->Append(values[i]); |
|
|
target_file->Append(values[i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void DBImpl::addNewValueLog(){ |
|
|
|
|
|
//lock
|
|
|
|
|
|
// if(valuelogfile_){
|
|
|
|
|
|
// valuelogfile_->Sync();
|
|
|
|
|
|
// valuelogfile_->Close();
|
|
|
|
|
|
// delete valuelogfile_;
|
|
|
|
|
|
// }
|
|
|
|
|
|
valuelogfile_number_=versions_->NewFileNumber(); |
|
|
|
|
|
// valuelogfile_offset=0;
|
|
|
|
|
|
// std::string file_name_=ValueLogFileName(dbname_,valuelogfile_number_);
|
|
|
|
|
|
// env_->NewWritableFile(file_name_,&valuelogfile_);
|
|
|
|
|
|
//unlock
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Status DBImpl::ReadValueLog(uint64_t file_id, uint64_t offset,uint64_t len,Slice* value){ |
|
|
Status DBImpl::ReadValueLog(uint64_t file_id, uint64_t offset,uint64_t len,Slice* value){ |
|
|
//lock_shared
|
|
|
//lock_shared
|
|
|
std::string file_name_=ValueLogFileName(dbname_,file_id); |
|
|
std::string file_name_=ValueLogFileName(dbname_,file_id); |
|
@ -1644,7 +1592,11 @@ Status DBImpl::ReadValueLog(uint64_t file_id, uint64_t offset,uint64_t len,Slice |
|
|
// can call if they wish
|
|
|
// can call if they wish
|
|
|
Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { |
|
|
Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { |
|
|
WriteBatch batch; |
|
|
WriteBatch batch; |
|
|
batch.Put(key, value); |
|
|
|
|
|
|
|
|
std::string buf; |
|
|
|
|
|
buf+=(char)(0x00); |
|
|
|
|
|
buf+=std::string(value.data(),value.size()); |
|
|
|
|
|
Slice new_value=Slice(buf); |
|
|
|
|
|
batch.Put(key, new_value); |
|
|
return Write(opt, &batch); |
|
|
return Write(opt, &batch); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1678,7 +1630,6 @@ Status DB::Open(const Options& options, const std::string& dbname, DB** dbptr) { |
|
|
impl->log_ = new log::Writer(lfile); |
|
|
impl->log_ = new log::Writer(lfile); |
|
|
impl->mem_ = new MemTable(impl->internal_comparator_); |
|
|
impl->mem_ = new MemTable(impl->internal_comparator_); |
|
|
impl->mem_->Ref(); |
|
|
impl->mem_->Ref(); |
|
|
impl->addNewValueLog(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (s.ok() && save_manifest) { |
|
|
if (s.ok() && save_manifest) { |
|
|