|
@ -52,11 +52,12 @@ struct DBImpl::Writer { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
struct DBImpl::CompactionState { |
|
|
struct DBImpl::CompactionState { |
|
|
// Files produced by compaction
|
|
|
|
|
|
|
|
|
// Files produced by compaction 这里的改动和filemetadata对应
|
|
|
struct Output { |
|
|
struct Output { |
|
|
uint64_t number; |
|
|
uint64_t number; |
|
|
uint64_t file_size; |
|
|
uint64_t file_size; |
|
|
InternalKey smallest, largest; |
|
|
InternalKey smallest, largest; |
|
|
|
|
|
uint64_t smallest_deadtime,largest_deadtime; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Output* current_output() { return &outputs[outputs.size() - 1]; } |
|
|
Output* current_output() { return &outputs[outputs.size() - 1]; } |
|
@ -536,7 +537,7 @@ Status DBImpl::WriteLevel0Table(MemTable* mem, VersionEdit* edit, |
|
|
level = base->PickLevelForMemTableOutput(min_user_key, max_user_key); |
|
|
level = base->PickLevelForMemTableOutput(min_user_key, max_user_key); |
|
|
} |
|
|
} |
|
|
edit->AddFile(level, meta.number, meta.file_size, meta.smallest, |
|
|
edit->AddFile(level, meta.number, meta.file_size, meta.smallest, |
|
|
meta.largest); |
|
|
|
|
|
|
|
|
meta.largest,meta.smallest_deadtime,meta.largest_deadtime); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
CompactionStats stats; |
|
|
CompactionStats stats; |
|
@ -740,7 +741,7 @@ void DBImpl::BackgroundCompaction() { |
|
|
FileMetaData* f = c->input(0, 0); |
|
|
FileMetaData* f = c->input(0, 0); |
|
|
c->edit()->RemoveFile(c->level(), f->number); |
|
|
c->edit()->RemoveFile(c->level(), f->number); |
|
|
c->edit()->AddFile(c->level() + 1, f->number, f->file_size, f->smallest, |
|
|
c->edit()->AddFile(c->level() + 1, f->number, f->file_size, f->smallest, |
|
|
f->largest); |
|
|
|
|
|
|
|
|
f->largest,f->smallest_deadtime,f->largest_deadtime); |
|
|
status = versions_->LogAndApply(c->edit(), &mutex_); |
|
|
status = versions_->LogAndApply(c->edit(), &mutex_); |
|
|
if (!status.ok()) { |
|
|
if (!status.ok()) { |
|
|
RecordBackgroundError(status); |
|
|
RecordBackgroundError(status); |
|
@ -814,6 +815,8 @@ Status DBImpl::OpenCompactionOutputFile(CompactionState* compact) { |
|
|
out.number = file_number; |
|
|
out.number = file_number; |
|
|
out.smallest.Clear(); |
|
|
out.smallest.Clear(); |
|
|
out.largest.Clear(); |
|
|
out.largest.Clear(); |
|
|
|
|
|
out.smallest_deadtime = UINT64_MAX; |
|
|
|
|
|
out.largest_deadtime = 0; |
|
|
compact->outputs.push_back(out); |
|
|
compact->outputs.push_back(out); |
|
|
mutex_.Unlock(); |
|
|
mutex_.Unlock(); |
|
|
} |
|
|
} |
|
@ -889,7 +892,7 @@ Status DBImpl::InstallCompactionResults(CompactionState* compact) { |
|
|
for (size_t i = 0; i < compact->outputs.size(); i++) { |
|
|
for (size_t i = 0; i < compact->outputs.size(); i++) { |
|
|
const CompactionState::Output& out = compact->outputs[i]; |
|
|
const CompactionState::Output& out = compact->outputs[i]; |
|
|
compact->compaction->edit()->AddFile(level + 1, out.number, out.file_size, |
|
|
compact->compaction->edit()->AddFile(level + 1, out.number, out.file_size, |
|
|
out.smallest, out.largest); |
|
|
|
|
|
|
|
|
out.smallest, out.largest,out.smallest_deadtime,out.largest_deadtime); |
|
|
} |
|
|
} |
|
|
return versions_->LogAndApply(compact->compaction->edit(), &mutex_); |
|
|
return versions_->LogAndApply(compact->compaction->edit(), &mutex_); |
|
|
} |
|
|
} |
|
@ -1003,6 +1006,17 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { |
|
|
compact->current_output()->smallest.DecodeFrom(key); |
|
|
compact->current_output()->smallest.DecodeFrom(key); |
|
|
} |
|
|
} |
|
|
compact->current_output()->largest.DecodeFrom(key); |
|
|
compact->current_output()->largest.DecodeFrom(key); |
|
|
|
|
|
|
|
|
|
|
|
ParsedInternalKey parsed; |
|
|
|
|
|
ParseInternalKey(key,&parsed); |
|
|
|
|
|
uint64_t &smallest_deadtime = compact->current_output()->smallest_deadtime; |
|
|
|
|
|
uint64_t &largest_deadtime = compact->current_output()->largest_deadtime; |
|
|
|
|
|
if(parsed.deadTime == 0) { |
|
|
|
|
|
smallest_deadtime = UINT64_MAX; |
|
|
|
|
|
} |
|
|
|
|
|
smallest_deadtime = std::min(smallest_deadtime,parsed.deadTime); |
|
|
|
|
|
largest_deadtime = std::max(largest_deadtime,parsed.deadTime); |
|
|
|
|
|
|
|
|
compact->builder->Add(key, input->value()); |
|
|
compact->builder->Add(key, input->value()); |
|
|
|
|
|
|
|
|
// Close output file if it is big enough
|
|
|
// Close output file if it is big enough
|
|
@ -1206,10 +1220,10 @@ Status DBImpl::Put(const WriteOptions& o, const Slice& key, |
|
|
return DB::Put(o, key, val, ttl); |
|
|
return DB::Put(o, key, val, ttl); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Status DBImpl::Put(const WriteOptions& options, const Slice& key, |
|
|
|
|
|
const Slice& value, uint64_t ttl) { |
|
|
|
|
|
return DB::Put(options,key,value,ttl); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Status DBImpl::Put(const WriteOptions& options, const Slice& key,
|
|
|
|
|
|
// const Slice& value, uint64_t ttl) {
|
|
|
|
|
|
// return DB::Put(options,key,value,ttl);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
Status DBImpl::Delete(const WriteOptions& options, const Slice& key) { |
|
|
Status DBImpl::Delete(const WriteOptions& options, const Slice& key) { |
|
|
return DB::Delete(options, key); |
|
|
return DB::Delete(options, key); |
|
@ -1505,13 +1519,13 @@ Status DB::Put(const WriteOptions& opt, const Slice& key, |
|
|
return Write(opt, &batch); |
|
|
return Write(opt, &batch); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//为了通过编译,忽略ttl
|
|
|
|
|
|
Status DB::Put(const WriteOptions& options, const Slice& key, |
|
|
|
|
|
const
Slice&
value,
uint64_t
ttl)
{ |
|
|
|
|
|
WriteBatch batch; |
|
|
|
|
|
batch.Put(key, value); |
|
|
|
|
|
return Write(options, &batch); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// //为了通过编译,忽略ttl
|
|
|
|
|
|
// Status DB::Put(const WriteOptions& options, const Slice& key,
|
|
|
|
|
|
// const Slice& value, uint64_t ttl) {
|
|
|
|
|
|
// WriteBatch batch;
|
|
|
|
|
|
// batch.Put(key, value);
|
|
|
|
|
|
// return Write(options, &batch);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
Status DB::Delete(const WriteOptions& opt, const Slice& key) { |
|
|
Status DB::Delete(const WriteOptions& opt, const Slice& key) { |
|
|
WriteBatch batch; |
|
|
WriteBatch batch; |
|
|