|
|
@ -321,6 +321,107 @@ void Version::ForEachOverlapping(Slice user_key, Slice internal_key, void* arg, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Status Version::Get(const ReadOptions& options, const LookupKey& k,
|
|
|
|
// std::string* value, GetStats* stats) {
|
|
|
|
// stats->seek_file = nullptr;
|
|
|
|
// stats->seek_file_level = -1;
|
|
|
|
|
|
|
|
// struct State {
|
|
|
|
// Saver saver;
|
|
|
|
// GetStats* stats;
|
|
|
|
// const ReadOptions* options;
|
|
|
|
// Slice ikey;
|
|
|
|
// FileMetaData* last_file_read;
|
|
|
|
// int last_file_read_level;
|
|
|
|
|
|
|
|
// VersionSet* vset;
|
|
|
|
// Status s;
|
|
|
|
// bool found;
|
|
|
|
|
|
|
|
// static bool Match(void* arg, int level, FileMetaData* f) {
|
|
|
|
// State* state = reinterpret_cast<State*>(arg);
|
|
|
|
|
|
|
|
// if (state->stats->seek_file == nullptr &&
|
|
|
|
// state->last_file_read != nullptr) { //如果 seek_file 为空且 last_file_read 不为空
|
|
|
|
// // We have had more than one seek for this read. Charge the 1st file.
|
|
|
|
// // 记录第一次的查找文件信息
|
|
|
|
// state->stats->seek_file = state->last_file_read; //则记录 seek_file 以标记第一次读取的文件和层级。
|
|
|
|
// state->stats->seek_file_level = state->last_file_read_level;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// state->last_file_read = f; //更新 last_file_read 和 last_file_read_level
|
|
|
|
// state->last_file_read_level = level;
|
|
|
|
// //调用 table_cache_->Get:从缓存中获取指定文件,并在查找键时使用 SaveValue 回调,
|
|
|
|
// state->s = state->vset->table_cache_->Get(*state->options, f->number,
|
|
|
|
// f->file_size, state->ikey,
|
|
|
|
// &state->saver, SaveValue);
|
|
|
|
|
|
|
|
|
|
|
|
// // 使用TableCache::Get并传递自定义的SaveValue函数以进行TTL检查,燕改
|
|
|
|
// auto ttl_save_value = [](void* arg, const Slice& key, const Slice& value) {
|
|
|
|
// Saver* saver = reinterpret_cast<Saver*>(arg);
|
|
|
|
// if (value.size() < 19) {
|
|
|
|
// saver->state = kNotFound;
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // 解析时间戳并检查过期情况
|
|
|
|
// uint64_t expire_time = DecodeFixed64(value.data() + value.size() - 19);
|
|
|
|
// if (expire_time > Env::Default()->NowMicros()) {
|
|
|
|
// SaveValue(arg, key, value); // 未过期,保存数据
|
|
|
|
// } else {
|
|
|
|
// saver->state = kNotFound; // 数据已过期
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// // 调用Get并传递自定义的ttl_save_value,燕改
|
|
|
|
// state->s = state->vset->table_cache_->Get(*state->options, f->number,
|
|
|
|
// f->file_size, state->ikey,
|
|
|
|
// &state->saver, ttl_save_value);
|
|
|
|
|
|
|
|
// if (!state->s.ok()) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// switch (state->saver.state) {
|
|
|
|
// case kNotFound:
|
|
|
|
// state->found = false; // 设置为未找到,燕改
|
|
|
|
// return true; // Keep searching in other files
|
|
|
|
// case kFound:
|
|
|
|
// state->found = true;
|
|
|
|
// return false;
|
|
|
|
// case kDeleted:
|
|
|
|
// return false;
|
|
|
|
// case kCorrupt:
|
|
|
|
// state->s =
|
|
|
|
// Status::Corruption("corrupted key for ", state->saver.user_key);
|
|
|
|
// state->found = true;
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // Not reached. Added to avoid false compilation warnings of
|
|
|
|
// // "control reaches end of non-void function".
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// State state;
|
|
|
|
// state.found = false;
|
|
|
|
// state.stats = stats;
|
|
|
|
// state.last_file_read = nullptr;
|
|
|
|
// state.last_file_read_level = -1;
|
|
|
|
|
|
|
|
// state.options = &options;
|
|
|
|
// state.ikey = k.internal_key();
|
|
|
|
// state.vset = vset_;
|
|
|
|
|
|
|
|
// state.saver.state = kNotFound;
|
|
|
|
// state.saver.ucmp = vset_->icmp_.user_comparator();
|
|
|
|
// state.saver.user_key = k.user_key();
|
|
|
|
// state.saver.value = value;
|
|
|
|
|
|
|
|
// ForEachOverlapping(state.saver.user_key, state.ikey, &state, &State::Match);
|
|
|
|
|
|
|
|
// return state.found ? state.s : Status::NotFound(Slice());
|
|
|
|
// }
|
|
|
|
Status Version::Get(const ReadOptions& options, const LookupKey& k, |
|
|
|
std::string* value, GetStats* stats) { |
|
|
|
stats->seek_file = nullptr; |
|
|
|