Skip to content

Commit 91bbf16

Browse files
dango-msftyabmek-msft
authored andcommitted
Allow per-platform log buffer size
1 parent 23e35d7 commit 91bbf16

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

db/log_format.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ enum RecordType {
2424
};
2525
static const int kMaxRecordType = kLastType;
2626

27-
static const int kBlockSize = 32768;
28-
2927
// Header is checksum (4 bytes), length (2 bytes), type (1 byte).
3028
static const int kHeaderSize = 4 + 2 + 1;
3129

db/log_reader.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Reader::Reader(SequentialFile* file, Reporter* reporter, bool checksum,
2020
: file_(file),
2121
reporter_(reporter),
2222
checksum_(checksum),
23-
backing_store_(new char[kBlockSize]),
23+
backing_store_(new char[port::kLogBlockSize]),
2424
buffer_(),
2525
eof_(false),
2626
last_record_offset_(0),
@@ -31,12 +31,12 @@ Reader::Reader(SequentialFile* file, Reporter* reporter, bool checksum,
3131
Reader::~Reader() { delete[] backing_store_; }
3232

3333
bool Reader::SkipToInitialBlock() {
34-
const size_t offset_in_block = initial_offset_ % kBlockSize;
34+
const size_t offset_in_block = initial_offset_ % port::kLogBlockSize;
3535
uint64_t block_start_location = initial_offset_ - offset_in_block;
3636

3737
// Don't search a block if we'd be in the trailer
38-
if (offset_in_block > kBlockSize - 6) {
39-
block_start_location += kBlockSize;
38+
if (offset_in_block > port::kLogBlockSize - 6) {
39+
block_start_location += port::kLogBlockSize;
4040
}
4141

4242
end_of_buffer_offset_ = block_start_location;
@@ -192,14 +192,14 @@ unsigned int Reader::ReadPhysicalRecord(Slice* result) {
192192
if (!eof_) {
193193
// Last read was a full read, so this is a trailer to skip
194194
buffer_.clear();
195-
Status status = file_->Read(kBlockSize, &buffer_, backing_store_);
195+
Status status = file_->Read(port::kLogBlockSize, &buffer_, backing_store_);
196196
end_of_buffer_offset_ += buffer_.size();
197197
if (!status.ok()) {
198198
buffer_.clear();
199-
ReportDrop(kBlockSize, status);
199+
ReportDrop(port::kLogBlockSize, status);
200200
eof_ = true;
201201
return kEof;
202-
} else if (buffer_.size() < kBlockSize) {
202+
} else if (buffer_.size() < port::kLogBlockSize) {
203203
eof_ = true;
204204
}
205205
continue;

db/log_reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Reader {
9090
bool const checksum_;
9191
char* const backing_store_;
9292
Slice buffer_;
93-
bool eof_; // Last Read() indicated EOF by returning < kBlockSize
93+
bool eof_; // Last Read() indicated EOF by returning < port::kLogBlockSize
9494

9595
// Offset of the last record returned by ReadRecord.
9696
uint64_t last_record_offset_;

db/log_writer.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Writer::Writer(WritableFile* dest) : dest_(dest), block_offset_(0) {
2525
}
2626

2727
Writer::Writer(WritableFile* dest, uint64_t dest_length)
28-
: dest_(dest), block_offset_(dest_length % kBlockSize) {
28+
: dest_(dest), block_offset_(dest_length % port::kLogBlockSize) {
2929
InitTypeCrc(type_crc_);
3030
}
3131

@@ -41,7 +41,7 @@ Status Writer::AddRecord(const Slice& slice) {
4141
Status s;
4242
bool begin = true;
4343
do {
44-
const int leftover = kBlockSize - block_offset_;
44+
const int leftover = port::kLogBlockSize - block_offset_;
4545
assert(leftover >= 0);
4646
if (leftover < kHeaderSize) {
4747
// Switch to a new block
@@ -54,9 +54,9 @@ Status Writer::AddRecord(const Slice& slice) {
5454
}
5555

5656
// Invariant: we never leave < kHeaderSize bytes in a block.
57-
assert(kBlockSize - block_offset_ - kHeaderSize >= 0);
57+
assert(port::kLogBlockSize - block_offset_ - kHeaderSize >= 0);
5858

59-
const size_t avail = kBlockSize - block_offset_ - kHeaderSize;
59+
const size_t avail = port::kLogBlockSize - block_offset_ - kHeaderSize;
6060
const size_t fragment_length = (left < avail) ? left : avail;
6161

6262
RecordType type;
@@ -82,7 +82,7 @@ Status Writer::AddRecord(const Slice& slice) {
8282
Status Writer::EmitPhysicalRecord(RecordType t, const char* ptr,
8383
size_t length) {
8484
assert(length <= 0xffff); // Must fit in two bytes
85-
assert(block_offset_ + kHeaderSize + length <= kBlockSize);
85+
assert(block_offset_ + kHeaderSize + length <= port::kLogBlockSize);
8686

8787
// Format the header
8888
char buf[kHeaderSize];

port/port_example.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace port {
1818
// TODO(jorlow): Many of these belong more in the environment class rather than
1919
// here. We should try moving them and see if it affects perf.
2020

21+
// Buffer size for log
22+
static const int kLogBlockSize = 32768;
23+
2124
// ------------------ Threading -------------------
2225

2326
// A Mutex represents an exclusive lock.

port/port_stdcxx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace port {
4747

4848
class CondVar;
4949

50+
static const int kLogBlockSize = 32768;
51+
5052
// Thinly wraps std::mutex.
5153
class LOCKABLE Mutex {
5254
public:

0 commit comments

Comments
 (0)