mirror of
https://github.com/google/leveldb.git
synced 2025-02-04 07:10:10 +08:00
MANIFEST file size will be huge after long time running, rotate MANIFEST when MANIFEST file write size exceed write buffer size to avoid this
This commit is contained in:
parent
5d94ad4d95
commit
6be8164b3a
@ -740,6 +740,7 @@ VersionSet::VersionSet(const std::string& dbname, const Options* options,
|
|||||||
icmp_(*cmp),
|
icmp_(*cmp),
|
||||||
next_file_number_(2),
|
next_file_number_(2),
|
||||||
manifest_file_number_(0), // Filled by Recover()
|
manifest_file_number_(0), // Filled by Recover()
|
||||||
|
manifest_file_size_hint_(0),
|
||||||
last_sequence_(0),
|
last_sequence_(0),
|
||||||
log_number_(0),
|
log_number_(0),
|
||||||
prev_log_number_(0),
|
prev_log_number_(0),
|
||||||
@ -797,6 +798,20 @@ Status VersionSet::LogAndApply(VersionEdit* edit, port::Mutex* mu) {
|
|||||||
}
|
}
|
||||||
Finalize(v);
|
Finalize(v);
|
||||||
|
|
||||||
|
if (descriptor_log_ != nullptr) {
|
||||||
|
if (manifest_file_size_hint_ >= options_->write_buffer_size) {
|
||||||
|
Log(options_->info_log, "MANIFEST size %ld exceed, switch to next file\n",
|
||||||
|
long(manifest_file_size_hint_));
|
||||||
|
delete descriptor_log_;
|
||||||
|
delete descriptor_file_;
|
||||||
|
descriptor_log_ = nullptr;
|
||||||
|
descriptor_file_ = nullptr;
|
||||||
|
manifest_file_number_ = manifest_file_number_ + 1;
|
||||||
|
next_file_number_ = next_file_number_ + 1;
|
||||||
|
manifest_file_size_hint_ = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize new descriptor log file if necessary by creating
|
// Initialize new descriptor log file if necessary by creating
|
||||||
// a temporary file that contains a snapshot of the current version.
|
// a temporary file that contains a snapshot of the current version.
|
||||||
std::string new_manifest_file;
|
std::string new_manifest_file;
|
||||||
@ -825,6 +840,7 @@ Status VersionSet::LogAndApply(VersionEdit* edit, port::Mutex* mu) {
|
|||||||
s = descriptor_log_->AddRecord(record);
|
s = descriptor_log_->AddRecord(record);
|
||||||
if (s.ok()) {
|
if (s.ok()) {
|
||||||
s = descriptor_file_->Sync();
|
s = descriptor_file_->Sync();
|
||||||
|
manifest_file_size_hint_ += record.size();
|
||||||
}
|
}
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
Log(options_->info_log, "MANIFEST write: %s\n", s.ToString().c_str());
|
Log(options_->info_log, "MANIFEST write: %s\n", s.ToString().c_str());
|
||||||
|
@ -300,6 +300,7 @@ class VersionSet {
|
|||||||
const InternalKeyComparator icmp_;
|
const InternalKeyComparator icmp_;
|
||||||
uint64_t next_file_number_;
|
uint64_t next_file_number_;
|
||||||
uint64_t manifest_file_number_;
|
uint64_t manifest_file_number_;
|
||||||
|
uint64_t manifest_file_size_hint_;
|
||||||
uint64_t last_sequence_;
|
uint64_t last_sequence_;
|
||||||
uint64_t log_number_;
|
uint64_t log_number_;
|
||||||
uint64_t prev_log_number_; // 0 or backing store for memtable being compacted
|
uint64_t prev_log_number_; // 0 or backing store for memtable being compacted
|
||||||
|
Loading…
Reference in New Issue
Block a user