|
|
@ -83,11 +83,15 @@ Version::~Version() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//寻找文件的时候也要考虑生存期
|
|
|
|
int FindFile(const InternalKeyComparator& icmp, |
|
|
|
const std::vector<FileMetaData*>& files, const Slice& key) { |
|
|
|
uint32_t left = 0; |
|
|
|
uint32_t right = files.size(); |
|
|
|
|
|
|
|
ParsedInternalKey parsed; |
|
|
|
ParseInternalKey(key,&parsed); |
|
|
|
|
|
|
|
while (left < right) { |
|
|
|
uint32_t mid = (left + right) / 2; |
|
|
|
const FileMetaData* f = files[mid]; |
|
|
@ -101,6 +105,19 @@ int FindFile(const InternalKeyComparator& icmp, |
|
|
|
right = mid; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
while(right < files.size()) { |
|
|
|
printf("file ind %d num %d largest deadtime %d parsed deadtime %d\n", |
|
|
|
right,files[right]->number,files[right]->largest_deadtime,parsed.deadTime); |
|
|
|
if(files[right]->largest_deadtime >= parsed.deadTime) { |
|
|
|
break; |
|
|
|
} |
|
|
|
// if(icmp.InternalKeyComparator::Compare(files[right]->largest.Encode(), key) > 0) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
right ++; |
|
|
|
} |
|
|
|
|
|
|
|
return right; |
|
|
|
} |
|
|
|
|
|
|
@ -266,7 +283,7 @@ static void SaveValue(void* arg, const Slice& ikey, const Slice& v) { |
|
|
|
// std::cout<<"corrupt get"<<std::endl;
|
|
|
|
s->state = kCorrupt; |
|
|
|
} else { |
|
|
|
std::cout<<"tar&found"<<parsed_key.user_key.ToString()<<" "<<s->user_key.ToString()<<std::endl; |
|
|
|
std::cout<<"found & target "<<parsed_key.user_key.ToString()<<" "<<s->user_key.ToString()<<std::endl; |
|
|
|
if (s->ucmp->Compare(parsed_key.user_key, s->user_key) == 0) { |
|
|
|
s->state = (parsed_key.type == kTypeValue) ? kFound : kDeleted; |
|
|
|
if (s->state == kFound) { |
|
|
@ -284,14 +301,18 @@ static bool NewestFirst(FileMetaData* a, FileMetaData* b) { |
|
|
|
void Version::ForEachOverlapping(Slice user_key, Slice internal_key, void* arg, |
|
|
|
bool (*func)(void*, int, FileMetaData*)) { |
|
|
|
const Comparator* ucmp = vset_->icmp_.user_comparator(); |
|
|
|
|
|
|
|
ParsedInternalKey parsed; |
|
|
|
ParseInternalKey(internal_key,&parsed); |
|
|
|
printf("parsed lookup deadtime : %d\n",parsed.deadTime); |
|
|
|
// Search level-0 in order from newest to oldest.
|
|
|
|
std::vector<FileMetaData*> tmp; |
|
|
|
tmp.reserve(files_[0].size()); |
|
|
|
for (uint32_t i = 0; i < files_[0].size(); i++) { |
|
|
|
FileMetaData* f = files_[0][i]; |
|
|
|
//除了key的范围之外,还要考虑文件含有kv的最大deadtime
|
|
|
|
if (ucmp->Compare(user_key, f->smallest.user_key()) >= 0 && |
|
|
|
ucmp->Compare(user_key, f->largest.user_key()) <= 0) { |
|
|
|
ucmp->Compare(user_key, f->largest.user_key()) <= 0 && |
|
|
|
f->largest_deadtime > parsed.deadTime) { |
|
|
|
tmp.push_back(f); |
|
|
|
} |
|
|
|
} |
|
|
@ -306,6 +327,7 @@ void Version::ForEachOverlapping(Slice user_key, Slice internal_key, void* arg, |
|
|
|
|
|
|
|
// Search other levels.
|
|
|
|
for (int level = 1; level < config::kNumLevels; level++) { |
|
|
|
std::cout<<"----------search in level "<<level<<"--------------\n"; |
|
|
|
size_t num_files = files_[level].size(); |
|
|
|
if (num_files == 0) continue; |
|
|
|
|
|
|
@ -313,6 +335,7 @@ void Version::ForEachOverlapping(Slice user_key, Slice internal_key, void* arg, |
|
|
|
uint32_t index = FindFile(vset_->icmp_, files_[level], internal_key); |
|
|
|
if (index < num_files) { |
|
|
|
FileMetaData* f = files_[level][index]; |
|
|
|
std::cout<<"userkey fsmallest "<<user_key.ToString()<<" "<<f->smallest.user_key().ToString()<<std::endl; |
|
|
|
if (ucmp->Compare(user_key, f->smallest.user_key()) < 0) { |
|
|
|
// All of "f" is past any data for user_key
|
|
|
|
} else { |
|
|
@ -357,6 +380,8 @@ Status Version::Get(const ReadOptions& options, const LookupKey& k, |
|
|
|
state->s = state->vset->table_cache_->Get(*state->options, f->number, |
|
|
|
f->file_size, state->ikey, |
|
|
|
&state->saver, SaveValue); |
|
|
|
printf("file level %d num %d\n",level,f->number); |
|
|
|
std::cout<<"state->s ->saver.state: "<<state->s.ok()<<" "<<state->saver.state<<std::endl; |
|
|
|
if (!state->s.ok()) { |
|
|
|
state->found = true; |
|
|
|
return false; |
|
|
|