Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some question about VersionSet::PickCompactionForGuards #26

Open
baiqiubai opened this issue Jun 26, 2022 · 0 comments
Open

Some question about VersionSet::PickCompactionForGuards #26

baiqiubai opened this issue Jun 26, 2022 · 0 comments

Comments

@baiqiubai
Copy link

baiqiubai commented Jun 26, 2022

Why not add all files at the level level directly to guards_compaction_and_all_files instead of taking the intersection of Complete_guards and Guards? I'm a little confused about this code, so I'd appreciate explaining it 。
`

              int guard_index_iter = 0;
	  for (size_t i = 0; i < complete_guards.size(); i++) {
		  GuardMetaData* cg = complete_guards[i];
		  int guard_index = -1;
		  Slice guard_key = cg->guard_key.user_key(), next_guard_key;
		  if (i + 1 < complete_guards.size()) {
			  next_guard_key = complete_guards[i+1]->guard_key.user_key();
		  }

		  for (; guard_index_iter < guards.size(); guard_index_iter++) {
			  int compare = icmp_.user_comparator()->Compare(guards[guard_index_iter]->guard_key.user_key(), guard_key);
			  if (compare == 0) {
				  guard_index = guard_index_iter;
				  guard_index_iter++;
				  break;
			  } else if (compare > 0) {
				  break;
			  } else {
				  // Ideally it should never reach here since there are no duplicates in complete_guards and complete_guards is a superset of guards
			  }
		  }

		  if (guard_index == -1) { // If guard is not found for this complete guard
			  continue;
		  }
		  GuardMetaData* g = guards[guard_index];
		  bool guard_added = false;
		  for (unsigned j = 0; j < g->files.size(); j++) {
			  FileMetaData* file = g->file_metas[j];
			  Slice file_smallest = file->smallest.user_key();
			  Slice file_largest = file->largest.user_key();
			  if ((i < complete_guards.size()-1 							// If it is not the last guard, checking for smallest and largest to fit in the range
							  && (icmp_.user_comparator()->Compare(file_smallest, guard_key) < 0
									  || icmp_.user_comparator()->Compare(file_largest, next_guard_key) >= 0))
					  || (i == complete_guards.size()-1 						// If it is the last guard, checking for the smallest to fit in the guard
							  && icmp_.user_comparator()->Compare(file_smallest, guard_key) < 0)) {
				  guards_to_add_to_compaction.push_back(g);
				  guards_compaction_add_all_files.push_back(true);	
				  guard_added = true;
				  break; // No need to check other files
			  }
		  }
		  if (!guard_added && which == 0 && (force_compact || v->guard_compaction_scores_[current_level][guard_index] >= 1.0)) {
			  guards_to_add_to_compaction.push_back(g);
			  guards_compaction_add_all_files.push_back(false);
			  continue;
		  }
	  }

`

@baiqiubai baiqiubai changed the title Some question VersionSet::PickCompactionForGuards Some question about VersionSet::PickCompactionForGuards Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant