diff options
author | neal-zhu <13126959424@163.com> | 2019-06-11 20:20:58 +0800 |
---|---|---|
committer | neal-zhu <13126959424@163.com> | 2019-06-11 20:20:58 +0800 |
commit | 8fa7a937ee8f38d8869357b0f27f120c5c58f4c9 (patch) | |
tree | 777cfc2ca10485509d54d4b8e50f0daf27c03330 /db | |
parent | 6a90bb91ee72642241fdbeefa673f88370c7b245 (diff) | |
download | leveldb-8fa7a937ee8f38d8869357b0f27f120c5c58f4c9.tar.gz |
fix bug
Diffstat (limited to 'db')
-rw-r--r-- | db/version_set.cc | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/db/version_set.cc b/db/version_set.cc index 625598d..1c2781e 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -328,7 +328,9 @@ Status Version::Get(const ReadOptions& options, const LookupKey& k, Slice ikey = k.internal_key(); Slice user_key = k.user_key(); const Comparator* ucmp = vset_->icmp_.user_comparator(); - Status s; + + stats->seek_file = nullptr; + stats->seek_file_level = -1; struct State { GetStats* stats; @@ -337,6 +339,8 @@ Status Version::Get(const ReadOptions& options, const LookupKey& k, Slice user_key; const Comparator* ucmp; std::string* value; + FileMetaData *last_file_read; + int last_file_level; VersionSet *vset; Status s; @@ -344,11 +348,13 @@ Status Version::Get(const ReadOptions& options, const LookupKey& k, static bool Match(void* arg, int level, FileMetaData* f) { State* state = reinterpret_cast<State*>(arg); - if (state->stats->seek_file == nullptr) { + if (state->last_file_read != nullptr && state->stats->seek_file == nullptr) { // We have had more than one seek for this read. Charge the 1st file. - state->stats->seek_file = f; - state->stats->seek_file_level = level; + state->stats->seek_file = state->last_file_read; + state->stats->seek_file_level = state->last_file_level; } + state->last_file_read = f; + state->last_file_level = level; Saver saver; saver.state = kNotFound; @@ -378,18 +384,18 @@ Status Version::Get(const ReadOptions& options, const LookupKey& k, } }; - stats->seek_file = nullptr; - stats->seek_file_level = -1; - State state; state.s = Status::NotFound(Slice()); state.stats = stats; + state.last_file_read = nullptr; + state.last_file_level = -1; + state.ikey = ikey; state.user_key = user_key; state.ucmp = ucmp; state.value = value; state.vset = vset_; - + ForEachOverlapping(user_key, ikey, &state, &State::Match); return state.s; |