From: Sage Weil Date: Tue, 29 Sep 2015 02:16:02 +0000 (-0400) Subject: pass optoins, log_nubmer to writer. usually. X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=beed65a211de874576421619e9b3b7fa98e1ae2b;p=rocksdb.git pass optoins, log_nubmer to writer. usually. --- diff --git a/db/db_impl.cc b/db/db_impl.cc index 808a2620..b5241582 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -391,7 +391,7 @@ Status DBImpl::NewDB() { } file->SetPreallocationBlockSize(db_options_.manifest_preallocation_size); { - log::Writer log(std::move(file)); + log::Writer log(&db_options_, std::move(file), 0); std::string record; new_db.EncodeTo(&record); s = log.AddRecord(record); @@ -3493,8 +3493,9 @@ Status DBImpl::SetNewMemtableAndNewLogFile(ColumnFamilyData* cfd, // (compression, etc) but err on the side of caution. lfile->SetPreallocationBlockSize( 1.1 * mutable_cf_options.write_buffer_size); - new_log = new log::Writer(std::move(lfile)); - log_dir_synced_ = false; + new_log = new log::Writer(&db_options_, std::move(lfile), + new_log_number); + log_dir_synced_ = false; } } @@ -4002,7 +4003,8 @@ Status DB::Open(const DBOptions& db_options, const std::string& dbname, if (s.ok()) { lfile->SetPreallocationBlockSize(1.1 * max_write_buffer_size); impl->logfile_number_ = new_log_number; - impl->log_.reset(new log::Writer(std::move(lfile))); + impl->log_.reset(new log::Writer(&impl->db_options_, std::move(lfile), + new_log_number)); // set column family handles for (auto cf : column_families) { diff --git a/db/log_writer.cc b/db/log_writer.cc index d78de5e7..eeb0844f 100644 --- a/db/log_writer.cc +++ b/db/log_writer.cc @@ -11,15 +11,19 @@ #include #include "rocksdb/env.h" +#include "rocksdb/options.h" #include "util/coding.h" #include "util/crc32c.h" namespace rocksdb { namespace log { -Writer::Writer(unique_ptr&& dest) - : dest_(std::move(dest)), - block_offset_(0) { +Writer::Writer(const DBOptions *opt, unique_ptr&& dest, + int log_number) + : db_options_(opt), + dest_(std::move(dest)), + block_offset_(0), + log_number_(log_number) { for (int i = 0; i <= kMaxRecordType; i++) { char t = static_cast(i); type_crc_[i] = crc32c::Value(&t, 1); diff --git a/db/log_writer.h b/db/log_writer.h index 46226ec2..18319796 100644 --- a/db/log_writer.h +++ b/db/log_writer.h @@ -17,6 +17,7 @@ namespace rocksdb { class WritableFile; +class DBOptions; using std::unique_ptr; @@ -61,7 +62,9 @@ class Writer { // Create a writer that will append data to "*dest". // "*dest" must be initially empty. // "*dest" must remain live while this Writer is in use. - explicit Writer(unique_ptr&& dest); + explicit Writer(const DBOptions *opt, + unique_ptr&& dest, + int log_number); ~Writer(); Status AddRecord(const Slice& slice); @@ -70,8 +73,10 @@ class Writer { const WritableFile* file() const { return dest_.get(); } private: + const DBOptions *db_options_; unique_ptr dest_; int block_offset_; // Current offset in block + int log_number_; // crc32c values for all supported record types. These are // pre-computed to reduce the overhead of computing the crc of the diff --git a/db/repair.cc b/db/repair.cc index 8b15eaab..355150d9 100644 --- a/db/repair.cc +++ b/db/repair.cc @@ -405,7 +405,7 @@ class Repairer { //fprintf(stderr, "NewDescriptor:\n%s\n", edit_.DebugString().c_str()); { - log::Writer log(std::move(file)); + log::Writer log(&options_, std::move(file), 0); std::string record; edit_->EncodeTo(&record); status = log.AddRecord(record); diff --git a/db/version_set.cc b/db/version_set.cc index 7cf010a7..03ccb795 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1902,7 +1902,8 @@ Status VersionSet::LogAndApply(ColumnFamilyData* column_family_data, if (s.ok()) { descriptor_file->SetPreallocationBlockSize( db_options_->manifest_preallocation_size); - descriptor_log_.reset(new log::Writer(std::move(descriptor_file))); + descriptor_log_.reset(new log::Writer(db_options_, + std::move(descriptor_file), 0)); s = WriteSnapshot(descriptor_log_.get()); } } diff --git a/db/wal_manager_test.cc b/db/wal_manager_test.cc index 325f0d94..f6af6cb9 100644 --- a/db/wal_manager_test.cc +++ b/db/wal_manager_test.cc @@ -72,7 +72,7 @@ class WalManagerTest : public testing::Test { std::string fname = ArchivedLogFileName(dbname_, current_log_number_); unique_ptr file; ASSERT_OK(env_->NewWritableFile(fname, &file, env_options_)); - current_log_writer_.reset(new log::Writer(std::move(file))); + current_log_writer_.reset(new log::Writer(&db_options_, std::move(file))); } void CreateArchiveLogs(int num_logs, int entries_per_log) {