|
|
@ -146,12 +146,14 @@ DBImpl::DBImpl(const Options& raw_options, const std::string& dbname) |
|
|
|
tmp_batch_(new WriteBatch), |
|
|
|
background_compaction_scheduled_(false), |
|
|
|
manual_compaction_(nullptr), |
|
|
|
// TODO(begin)
|
|
|
|
versions_(new VersionSet(dbname_, &options_, table_cache_, |
|
|
|
&internal_comparator_)), |
|
|
|
slot_page_(new SlotPage(dbname)) { |
|
|
|
|
|
|
|
vlog_set_ = new VlogSet(dbname, nullptr); |
|
|
|
vlog_set_->set_vlog_gc(new VlogGC(slot_page_, vlog_set_)); |
|
|
|
// TODO(end)
|
|
|
|
} |
|
|
|
|
|
|
|
DBImpl::~DBImpl() { |
|
|
@ -181,9 +183,10 @@ DBImpl::~DBImpl() { |
|
|
|
if (owns_cache_) { |
|
|
|
delete options_.block_cache; |
|
|
|
} |
|
|
|
|
|
|
|
// TODO(begin)
|
|
|
|
delete slot_page_; |
|
|
|
delete vlog_set_; |
|
|
|
// TODO(end)
|
|
|
|
} |
|
|
|
|
|
|
|
Status DBImpl::NewDB() { |
|
|
@ -1174,14 +1177,14 @@ Status DBImpl::Get(const ReadOptions& options, const Slice& key, |
|
|
|
if (imm != nullptr) imm->Unref(); |
|
|
|
current->Unref(); |
|
|
|
|
|
|
|
// TODO: search the slotpage and get value from vlog
|
|
|
|
// TODO(begin): search the slotpage and get value from vlog
|
|
|
|
size_t slot_num = *(size_t *)value->c_str(); |
|
|
|
struct slot_content sc; |
|
|
|
std::string vlog_value; |
|
|
|
slot_page_->get_slot(slot_num, &sc); |
|
|
|
vlog_set_->get_value(sc.vlog_num, sc.value_offset, &vlog_value); |
|
|
|
*value = vlog_value; |
|
|
|
|
|
|
|
// TODO(end)
|
|
|
|
return s; |
|
|
|
} |
|
|
|
|
|
|
@ -1216,7 +1219,7 @@ void DBImpl::ReleaseSnapshot(const Snapshot* snapshot) { |
|
|
|
|
|
|
|
// Convenience methods
|
|
|
|
Status DBImpl::Put(const WriteOptions& o, const Slice& key, const Slice& val) { |
|
|
|
// TODO: allocate slot_num in slotpage and put value in vlog
|
|
|
|
// TODO(begin): allocate slot_num in slotpage and put value in vlog
|
|
|
|
|
|
|
|
size_t slot_num = slot_page_->alloc_slot(); |
|
|
|
struct slot_content sc; |
|
|
@ -1228,9 +1231,11 @@ Status DBImpl::Put(const WriteOptions& o, const Slice& key, const Slice& val) { |
|
|
|
Slice slot_val(data, sizeof(data)); |
|
|
|
|
|
|
|
return DB::Put(o, key, slot_val); |
|
|
|
// TODO(end)
|
|
|
|
} |
|
|
|
|
|
|
|
Status DBImpl::Delete(const WriteOptions& options, const Slice& key) { |
|
|
|
// TODO(begin)
|
|
|
|
// size_t slot_num = *(size_t *)value->c_str();
|
|
|
|
// struct slot_content sc;
|
|
|
|
// std::string vlog_value;
|
|
|
@ -1248,7 +1253,7 @@ Status DBImpl::Delete(const WriteOptions& options, const Slice& key) { |
|
|
|
std::string vlog_value; |
|
|
|
slot_page_->get_slot(slot_num, &sc); |
|
|
|
vlog_set_->del_value(sc.vlog_num, sc.value_offset); |
|
|
|
|
|
|
|
// TODO(end)
|
|
|
|
return DB::Delete(options, key); |
|
|
|
} |
|
|
|
|
|
|
|