leveldb
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
leveldb::Compaction Class Reference

#include <version_set.h>

Collaboration diagram for leveldb::Compaction:
Collaboration graph
[legend]

Public Member Functions

 ~Compaction ()
 
int level () const
 
VersionEditedit ()
 
int num_input_files (int which) const
 
FileMetaDatainput (int which, int i) const
 
uint64_t MaxOutputFileSize () const
 
bool IsTrivialMove () const
 
void AddInputDeletions (VersionEdit *edit)
 
bool IsBaseLevelForKey (const Slice &user_key)
 
bool ShouldStopBefore (const Slice &internal_key)
 
void ReleaseInputs ()
 

Private Member Functions

 Compaction (const Options *options, int level)
 

Private Attributes

int level_
 
uint64_t max_output_file_size_
 
Versioninput_version_
 
VersionEdit edit_
 
std::vector< FileMetaData * > inputs_ [2]
 
std::vector< FileMetaData * > grandparents_
 
size_t grandparent_index_
 
bool seen_key_
 
int64_t overlapped_bytes_
 
size_t level_ptrs_ [config::kNumLevels]
 

Friends

class Version
 
class VersionSet
 

Detailed Description

Definition at line 324 of file version_set.h.

Constructor & Destructor Documentation

§ ~Compaction()

leveldb::Compaction::~Compaction ( )

Definition at line 1460 of file version_set.cc.

1460  {
1461  if (input_version_ != NULL) {
1462  input_version_->Unref();
1463  }
1464 }
Version * input_version_
Definition: version_set.h:373
Here is the call graph for this function:

§ Compaction()

leveldb::Compaction::Compaction ( const Options options,
int  level 
)
private

Definition at line 1448 of file version_set.cc.

1449  : level_(level),
1451  input_version_(NULL),
1452  grandparent_index_(0),
1453  seen_key_(false),
1454  overlapped_bytes_(0) {
1455  for (int i = 0; i < config::kNumLevels; i++) {
1456  level_ptrs_[i] = 0;
1457  }
1458 }
size_t level_ptrs_[config::kNumLevels]
Definition: version_set.h:393
int level() const
Definition: version_set.h:330
static const int kNumLevels
Definition: dbformat.h:22
uint64_t max_output_file_size_
Definition: version_set.h:372
Version * input_version_
Definition: version_set.h:373
int64_t overlapped_bytes_
Definition: version_set.h:384
static uint64_t MaxFileSizeForLevel(const Options *options, int level)
Definition: version_set.cc:53

Member Function Documentation

§ AddInputDeletions()

void leveldb::Compaction::AddInputDeletions ( VersionEdit edit)

Definition at line 1476 of file version_set.cc.

1476  {
1477  for (int which = 0; which < 2; which++) {
1478  for (size_t i = 0; i < inputs_[which].size(); i++) {
1479  edit->DeleteFile(level_ + which, inputs_[which][i]->number);
1480  }
1481  }
1482 }
void DeleteFile(int level, uint64_t file)
Definition: version_edit.h:75
std::vector< FileMetaData * > inputs_[2]
Definition: version_set.h:377
VersionEdit * edit()
Definition: version_set.h:334
Here is the call graph for this function:
Here is the caller graph for this function:

§ edit()

VersionEdit* leveldb::Compaction::edit ( )
inline

Definition at line 334 of file version_set.h.

334 { return &edit_; }
VersionEdit edit_
Definition: version_set.h:374
Here is the caller graph for this function:

§ input()

FileMetaData* leveldb::Compaction::input ( int  which,
int  i 
) const
inline

Definition at line 340 of file version_set.h.

340 { return inputs_[which][i]; }
std::vector< FileMetaData * > inputs_[2]
Definition: version_set.h:377
Here is the caller graph for this function:

§ IsBaseLevelForKey()

bool leveldb::Compaction::IsBaseLevelForKey ( const Slice user_key)

Definition at line 1484 of file version_set.cc.

1484  {
1485  // Maybe use binary search to find right entry instead of linear search?
1486  const Comparator* user_cmp = input_version_->vset_->icmp_.user_comparator();
1487  for (int lvl = level_ + 2; lvl < config::kNumLevels; lvl++) {
1488  const std::vector<FileMetaData*>& files = input_version_->files_[lvl];
1489  for (; level_ptrs_[lvl] < files.size(); ) {
1490  FileMetaData* f = files[level_ptrs_[lvl]];
1491  if (user_cmp->Compare(user_key, f->largest.user_key()) <= 0) {
1492  // We've advanced far enough
1493  if (user_cmp->Compare(user_key, f->smallest.user_key()) >= 0) {
1494  // Key falls in this file's range, so definitely not base level
1495  return false;
1496  }
1497  break;
1498  }
1499  level_ptrs_[lvl]++;
1500  }
1501  }
1502  return true;
1503 }
size_t level_ptrs_[config::kNumLevels]
Definition: version_set.h:393
std::vector< FileMetaData * > files_[config::kNumLevels]
Definition: version_set.h:138
static const int kNumLevels
Definition: dbformat.h:22
const Comparator * user_comparator() const
Definition: dbformat.h:125
VersionSet * vset_
Definition: version_set.h:132
const InternalKeyComparator icmp_
Definition: version_set.h:301
Version * input_version_
Definition: version_set.h:373
Here is the call graph for this function:
Here is the caller graph for this function:

§ IsTrivialMove()

bool leveldb::Compaction::IsTrivialMove ( ) const

Definition at line 1466 of file version_set.cc.

1466  {
1467  const VersionSet* vset = input_version_->vset_;
1468  // Avoid a move if there is lots of overlapping grandparent data.
1469  // Otherwise, the move could create a parent file that will require
1470  // a very expensive merge later on.
1471  return (num_input_files(0) == 1 && num_input_files(1) == 0 &&
1473  MaxGrandParentOverlapBytes(vset->options_));
1474 }
friend class VersionSet
Definition: version_set.h:367
VersionSet * vset_
Definition: version_set.h:132
static int64_t MaxGrandParentOverlapBytes(const Options *options)
Definition: version_set.cc:29
Version * input_version_
Definition: version_set.h:373
static int64_t TotalFileSize(const std::vector< FileMetaData *> &files)
Definition: version_set.cc:58
std::vector< FileMetaData * > grandparents_
Definition: version_set.h:381
int num_input_files(int which) const
Definition: version_set.h:337
Here is the call graph for this function:
Here is the caller graph for this function:

§ level()

int leveldb::Compaction::level ( ) const
inline

Definition at line 330 of file version_set.h.

330 { return level_; }
Here is the caller graph for this function:

§ MaxOutputFileSize()

uint64_t leveldb::Compaction::MaxOutputFileSize ( ) const
inline

Definition at line 343 of file version_set.h.

343 { return max_output_file_size_; }
uint64_t max_output_file_size_
Definition: version_set.h:372
Here is the caller graph for this function:

§ num_input_files()

int leveldb::Compaction::num_input_files ( int  which) const
inline

Definition at line 337 of file version_set.h.

337 { return inputs_[which].size(); }
std::vector< FileMetaData * > inputs_[2]
Definition: version_set.h:377
Here is the caller graph for this function:

§ ReleaseInputs()

void leveldb::Compaction::ReleaseInputs ( )

Definition at line 1528 of file version_set.cc.

1528  {
1529  if (input_version_ != NULL) {
1530  input_version_->Unref();
1531  input_version_ = NULL;
1532  }
1533 }
Version * input_version_
Definition: version_set.h:373
Here is the call graph for this function:
Here is the caller graph for this function:

§ ShouldStopBefore()

bool leveldb::Compaction::ShouldStopBefore ( const Slice internal_key)

Definition at line 1505 of file version_set.cc.

1505  {
1506  const VersionSet* vset = input_version_->vset_;
1507  // Scan to find earliest grandparent file that contains key.
1508  const InternalKeyComparator* icmp = &vset->icmp_;
1509  while (grandparent_index_ < grandparents_.size() &&
1510  icmp->Compare(internal_key,
1511  grandparents_[grandparent_index_]->largest.Encode()) > 0) {
1512  if (seen_key_) {
1514  }
1516  }
1517  seen_key_ = true;
1518 
1519  if (overlapped_bytes_ > MaxGrandParentOverlapBytes(vset->options_)) {
1520  // Too much overlap for current output; start new output
1521  overlapped_bytes_ = 0;
1522  return true;
1523  } else {
1524  return false;
1525  }
1526 }
friend class VersionSet
Definition: version_set.h:367
VersionSet * vset_
Definition: version_set.h:132
const InternalKeyComparator icmp_
Definition: version_set.h:301
static int64_t MaxGrandParentOverlapBytes(const Options *options)
Definition: version_set.cc:29
Version * input_version_
Definition: version_set.h:373
int64_t overlapped_bytes_
Definition: version_set.h:384
std::vector< FileMetaData * > grandparents_
Definition: version_set.h:381
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

§ Version

friend class Version
friend

Definition at line 366 of file version_set.h.

§ VersionSet

friend class VersionSet
friend

Definition at line 367 of file version_set.h.

Member Data Documentation

§ edit_

VersionEdit leveldb::Compaction::edit_
private

Definition at line 374 of file version_set.h.

§ grandparent_index_

size_t leveldb::Compaction::grandparent_index_
private

Definition at line 382 of file version_set.h.

§ grandparents_

std::vector<FileMetaData*> leveldb::Compaction::grandparents_
private

Definition at line 381 of file version_set.h.

§ input_version_

Version* leveldb::Compaction::input_version_
private

Definition at line 373 of file version_set.h.

§ inputs_

std::vector<FileMetaData*> leveldb::Compaction::inputs_[2]
private

Definition at line 377 of file version_set.h.

§ level_

int leveldb::Compaction::level_
private

Definition at line 371 of file version_set.h.

§ level_ptrs_

size_t leveldb::Compaction::level_ptrs_[config::kNumLevels]
private

Definition at line 393 of file version_set.h.

§ max_output_file_size_

uint64_t leveldb::Compaction::max_output_file_size_
private

Definition at line 372 of file version_set.h.

§ overlapped_bytes_

int64_t leveldb::Compaction::overlapped_bytes_
private

Definition at line 384 of file version_set.h.

§ seen_key_

bool leveldb::Compaction::seen_key_
private

Definition at line 383 of file version_set.h.


The documentation for this class was generated from the following files: