diff --git a/db/log_format.h b/db/log_format.h index 356e69fca2..10d3aa9263 100644 --- a/db/log_format.h +++ b/db/log_format.h @@ -24,8 +24,6 @@ enum RecordType { }; static const int kMaxRecordType = kLastType; -static const int kBlockSize = 32768; - // Header is checksum (4 bytes), length (2 bytes), type (1 byte). static const int kHeaderSize = 4 + 2 + 1; diff --git a/db/log_reader.cc b/db/log_reader.cc index 988027919f..9741f39087 100644 --- a/db/log_reader.cc +++ b/db/log_reader.cc @@ -20,7 +20,7 @@ Reader::Reader(SequentialFile* file, Reporter* reporter, bool checksum, : file_(file), reporter_(reporter), checksum_(checksum), - backing_store_(new char[kBlockSize]), + backing_store_(new char[port::kLogBlockSize]), buffer_(), eof_(false), last_record_offset_(0), @@ -31,12 +31,12 @@ Reader::Reader(SequentialFile* file, Reporter* reporter, bool checksum, Reader::~Reader() { delete[] backing_store_; } bool Reader::SkipToInitialBlock() { - const size_t offset_in_block = initial_offset_ % kBlockSize; + const size_t offset_in_block = initial_offset_ % port::kLogBlockSize; uint64_t block_start_location = initial_offset_ - offset_in_block; // Don't search a block if we'd be in the trailer - if (offset_in_block > kBlockSize - 6) { - block_start_location += kBlockSize; + if (offset_in_block > port::kLogBlockSize - 6) { + block_start_location += port::kLogBlockSize; } end_of_buffer_offset_ = block_start_location; @@ -192,14 +192,14 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result) { if (!eof_) { // Last read was a full read, so this is a trailer to skip buffer_.clear(); - Status status = file_->Read(kBlockSize, &buffer_, backing_store_); + Status status = file_->Read(port::kLogBlockSize, &buffer_, backing_store_); end_of_buffer_offset_ += buffer_.size(); if (!status.ok()) { buffer_.clear(); - ReportDrop(kBlockSize, status); + ReportDrop(port::kLogBlockSize, status); eof_ = true; return kEof; - } else if (buffer_.size() < kBlockSize) { + } else if (buffer_.size() < port::kLogBlockSize) { eof_ = true; } continue; diff --git a/db/log_reader.h b/db/log_reader.h index ba711f88ca..20941c74aa 100644 --- a/db/log_reader.h +++ b/db/log_reader.h @@ -90,7 +90,7 @@ class Reader { bool const checksum_; char* const backing_store_; Slice buffer_; - bool eof_; // Last Read() indicated EOF by returning < kBlockSize + bool eof_; // Last Read() indicated EOF by returning < port::kLogBlockSize // Offset of the last record returned by ReadRecord. uint64_t last_record_offset_; diff --git a/db/log_writer.cc b/db/log_writer.cc index ad66bfb8a1..f5beaa9103 100644 --- a/db/log_writer.cc +++ b/db/log_writer.cc @@ -25,7 +25,7 @@ Writer::Writer(WritableFile* dest) : dest_(dest), block_offset_(0) { } Writer::Writer(WritableFile* dest, uint64_t dest_length) - : dest_(dest), block_offset_(dest_length % kBlockSize) { + : dest_(dest), block_offset_(dest_length % port::kLogBlockSize) { InitTypeCrc(type_crc_); } @@ -41,7 +41,7 @@ Status Writer::AddRecord(const Slice& slice) { Status s; bool begin = true; do { - const int leftover = kBlockSize - block_offset_; + const int leftover = port::kLogBlockSize - block_offset_; assert(leftover >= 0); if (leftover < kHeaderSize) { // Switch to a new block @@ -54,9 +54,9 @@ Status Writer::AddRecord(const Slice& slice) { } // Invariant: we never leave < kHeaderSize bytes in a block. - assert(kBlockSize - block_offset_ - kHeaderSize >= 0); + assert(port::kLogBlockSize - block_offset_ - kHeaderSize >= 0); - const size_t avail = kBlockSize - block_offset_ - kHeaderSize; + const size_t avail = port::kLogBlockSize - block_offset_ - kHeaderSize; const size_t fragment_length = (left < avail) ? left : avail; RecordType type; @@ -82,7 +82,7 @@ Status Writer::AddRecord(const Slice& slice) { Status Writer::EmitPhysicalRecord(RecordType t, const char* ptr, size_t length) { assert(length <= 0xffff); // Must fit in two bytes - assert(block_offset_ + kHeaderSize + length <= kBlockSize); + assert(block_offset_ + kHeaderSize + length <= port::kLogBlockSize); // Format the header char buf[kHeaderSize]; diff --git a/port/port_example.h b/port/port_example.h index 5d50ffaab0..deed77c658 100644 --- a/port/port_example.h +++ b/port/port_example.h @@ -18,6 +18,9 @@ namespace port { // TODO(jorlow): Many of these belong more in the environment class rather than // here. We should try moving them and see if it affects perf. +// Buffer size for log +static const int kLogBlockSize = 32768; + // ------------------ Threading ------------------- // A Mutex represents an exclusive lock. diff --git a/port/port_stdcxx.h b/port/port_stdcxx.h index 6f503f695b..72dacdef11 100644 --- a/port/port_stdcxx.h +++ b/port/port_stdcxx.h @@ -47,6 +47,8 @@ namespace port { class CondVar; +static const int kLogBlockSize = 32768; + // Thinly wraps std::mutex. class LOCKABLE Mutex { public: