Browse Source

cache Saver in State object

xry
neal-zhu 5 years ago
parent
commit
107a75b62c
1 changed files with 20 additions and 21 deletions
  1. +20
    -21
      db/version_set.cc

+ 20
- 21
db/version_set.cc View File

@ -324,13 +324,11 @@ void Version::ForEachOverlapping(Slice user_key, Slice internal_key, void* arg,
Status Version::Get(const ReadOptions& options, const LookupKey& k, Status Version::Get(const ReadOptions& options, const LookupKey& k,
std::string* value, GetStats* stats) { std::string* value, GetStats* stats) {
Slice ikey = k.internal_key();
Slice user_key = k.user_key();
const Comparator* ucmp = vset_->icmp_.user_comparator();
stats->seek_file = nullptr; stats->seek_file = nullptr;
stats->seek_file_level = -1; stats->seek_file_level = -1;
struct State { struct State {
Saver saver;
GetStats* stats; GetStats* stats;
const ReadOptions* options; const ReadOptions* options;
Slice ikey; Slice ikey;
@ -342,6 +340,7 @@ Status Version::Get(const ReadOptions& options, const LookupKey& k,
VersionSet* vset; VersionSet* vset;
Status s; Status s;
bool found;
static bool Match(void* arg, int level, FileMetaData* f) { static bool Match(void* arg, int level, FileMetaData* f) {
State* state = reinterpret_cast<State*>(arg); State* state = reinterpret_cast<State*>(arg);
@ -356,50 +355,50 @@ Status Version::Get(const ReadOptions& options, const LookupKey& k,
state->last_file_read = f; state->last_file_read = f;
state->last_file_read_level = level; state->last_file_read_level = level;
Saver saver;
saver.state = kNotFound;
saver.ucmp = state->ucmp;
saver.user_key = state->user_key;
saver.value = state->value;
Status s = state->vset->table_cache_->Get(*state->options, f->number,
state->s = state->vset->table_cache_->Get(*state->options, f->number,
f->file_size, state->ikey, f->file_size, state->ikey,
&saver, SaveValue);
if (!s.ok()) {
state->s = s;
&state->saver, SaveValue);
if (!state->s.ok()) {
state->found = true;
return false; return false;
} }
switch (saver.state) {
switch (state->saver.state) {
case kNotFound: case kNotFound:
return true; // Keep saerching in other files return true; // Keep saerching in other files
case kFound: case kFound:
state->s = s;
state->found = true;
return false; return false;
case kDeleted: case kDeleted:
return false; return false;
case kCorrupt: case kCorrupt:
state->s = Status::Corruption("corrupted key for ", state->user_key); state->s = Status::Corruption("corrupted key for ", state->user_key);
state->found = true;
return false; return false;
} }
} }
}; };
State state; State state;
state.s = Status::NotFound(Slice());
state.found = false;
state.stats = stats; state.stats = stats;
state.last_file_read = nullptr; state.last_file_read = nullptr;
state.last_file_read_level = -1; state.last_file_read_level = -1;
state.options = &options; state.options = &options;
state.ikey = ikey;
state.user_key = user_key;
state.ucmp = ucmp;
state.ikey = k.internal_key();
state.user_key = k.user_key();
state.ucmp = vset_->icmp_.user_comparator();
state.value = value; state.value = value;
state.vset = vset_; state.vset = vset_;
ForEachOverlapping(user_key, ikey, &state, &State::Match);
state.saver.state = kNotFound;
state.saver.ucmp = state.ucmp;
state.saver.user_key = state.user_key;
state.saver.value = state.value;
ForEachOverlapping(state.user_key, state.ikey, &state, &State::Match);
return state.s;
return state.foundspan> ? state.s : Status::NotFound(Slice());
} }
bool Version::UpdateStats(const GetStats& stats) { bool Version::UpdateStats(const GetStats& stats) {

Loading…
Cancel
Save