Skip to content

Commit c1071ed

Browse files
committed
Merge branch 'master' into columnfamilies
2 parents 4bf2535 + 5d2c628 commit c1071ed

File tree

8 files changed

+574
-134
lines changed

8 files changed

+574
-134
lines changed

db/db_impl.cc

+22-5
Original file line numberDiff line numberDiff line change
@@ -3540,8 +3540,8 @@ bool DBImpl::GetProperty(const ColumnFamilyHandle& column_family,
35403540
// Pardon the long line but I think it is easier to read this way.
35413541
snprintf(buf, sizeof(buf),
35423542
" Compactions\n"
3543-
"Level Files Size(MB) Score Time(sec) Read(MB) Write(MB) Rn(MB) Rnp1(MB) Wnew(MB) RW-Amplify Read(MB/s) Write(MB/s) Rn Rnp1 Wnp1 NewW Count Ln-stall Stall-cnt\n"
3544-
"--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
3543+
"Level Files Size(MB) Score Time(sec) Read(MB) Write(MB) Rn(MB) Rnp1(MB) Wnew(MB) RW-Amplify Read(MB/s) Write(MB/s) Rn Rnp1 Wnp1 NewW Count msComp msStall Ln-stall Stall-cnt\n"
3544+
"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
35453545
);
35463546
value->append(buf);
35473547
for (int level = 0; level < current->NumberLevels(); level++) {
@@ -3561,9 +3561,21 @@ bool DBImpl::GetProperty(const ColumnFamilyHandle& column_family,
35613561
total_bytes_read += bytes_read;
35623562
total_bytes_written += stats_[level].bytes_written;
35633563

3564+
uint64_t stalls = level == 0 ?
3565+
(stall_level0_slowdown_count_ +
3566+
stall_level0_num_files_count_ +
3567+
stall_memtable_compaction_count_) :
3568+
stall_leveln_slowdown_count_[level];
3569+
3570+
double stall_us = level == 0 ?
3571+
(stall_level0_slowdown_ +
3572+
stall_level0_num_files_ +
3573+
stall_memtable_compaction_) :
3574+
stall_leveln_slowdown_[level];
3575+
35643576
snprintf(
35653577
buf, sizeof(buf),
3566-
"%3d %8d %8.0f %5.1f %9.0f %9.0f %9.0f %9.0f %9.0f %9.0f %10.1f %9.1f %11.1f %8d %8d %8d %8d %8d %9.1f %9lu\n",
3578+
"%3d %8d %8.0f %5.1f %9.0f %9.0f %9.0f %9.0f %9.0f %9.0f %10.1f %9.1f %11.1f %8d %8d %8d %8d %8d %8d %9.1f %9.1f %9lu\n",
35673579
level,
35683580
files,
35693581
current->NumLevelBytes(level) / 1048576.0,
@@ -3585,8 +3597,13 @@ bool DBImpl::GetProperty(const ColumnFamilyHandle& column_family,
35853597
stats_[level].files_out_levelnp1,
35863598
stats_[level].files_out_levelnp1 - stats_[level].files_in_levelnp1,
35873599
stats_[level].count,
3588-
stall_leveln_slowdown_[level] / 1000000.0,
3589-
(unsigned long) stall_leveln_slowdown_count_[level]);
3600+
(int) ((double) stats_[level].micros /
3601+
1000.0 /
3602+
(stats_[level].count + 1)),
3603+
(double) stall_us / 1000.0 / (stalls + 1),
3604+
stall_us / 1000000.0,
3605+
(unsigned long) stalls);
3606+
35903607
total_slowdown += stall_leveln_slowdown_[level];
35913608
total_slowdown_count += stall_leveln_slowdown_count_[level];
35923609
value->append(buf);

db/log_reader.cc

+68-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Reader::Reader(unique_ptr<SequentialFile>&& file, Reporter* reporter,
2828
backing_store_(new char[kBlockSize]),
2929
buffer_(),
3030
eof_(false),
31+
read_error_(false),
32+
eof_offset_(0),
3133
last_record_offset_(0),
3234
end_of_buffer_offset_(0),
3335
initial_offset_(initial_offset) {
@@ -170,6 +172,69 @@ uint64_t Reader::LastRecordOffset() {
170172
return last_record_offset_;
171173
}
172174

175+
void Reader::UnmarkEOF() {
176+
if (read_error_) {
177+
return;
178+
}
179+
180+
eof_ = false;
181+
182+
if (eof_offset_ == 0) {
183+
return;
184+
}
185+
186+
// If the EOF was in the middle of a block (a partial block was read) we have
187+
// to read the rest of the block as ReadPhysicalRecord can only read full
188+
// blocks and expects the file position indicator to be aligned to the start
189+
// of a block.
190+
//
191+
// consumed_bytes + buffer_size() + remaining == kBlockSize
192+
193+
size_t consumed_bytes = eof_offset_ - buffer_.size();
194+
size_t remaining = kBlockSize - eof_offset_;
195+
196+
// backing_store_ is used to concatenate what is left in buffer_ and
197+
// the remainder of the block. If buffer_ already uses backing_store_,
198+
// we just append the new data.
199+
if (buffer_.data() != backing_store_ + consumed_bytes) {
200+
// Buffer_ does not use backing_store_ for storage.
201+
// Copy what is left in buffer_ to backing_store.
202+
memmove(backing_store_ + consumed_bytes, buffer_.data(), buffer_.size());
203+
}
204+
205+
Slice read_buffer;
206+
Status status = file_->Read(remaining, &read_buffer,
207+
backing_store_ + eof_offset_);
208+
209+
size_t added = read_buffer.size();
210+
end_of_buffer_offset_ += added;
211+
212+
if (!status.ok()) {
213+
if (added > 0) {
214+
ReportDrop(added, status);
215+
}
216+
217+
read_error_ = true;
218+
return;
219+
}
220+
221+
if (read_buffer.data() != backing_store_ + eof_offset_) {
222+
// Read did not write to backing_store_
223+
memmove(backing_store_ + eof_offset_, read_buffer.data(),
224+
read_buffer.size());
225+
}
226+
227+
buffer_ = Slice(backing_store_ + consumed_bytes,
228+
eof_offset_ + added - consumed_bytes);
229+
230+
if (added < remaining) {
231+
eof_ = true;
232+
eof_offset_ += added;
233+
} else {
234+
eof_offset_ = 0;
235+
}
236+
}
237+
173238
void Reader::ReportCorruption(size_t bytes, const char* reason) {
174239
ReportDrop(bytes, Status::Corruption(reason));
175240
}
@@ -184,18 +249,19 @@ void Reader::ReportDrop(size_t bytes, const Status& reason) {
184249
unsigned int Reader::ReadPhysicalRecord(Slice* result) {
185250
while (true) {
186251
if (buffer_.size() < (size_t)kHeaderSize) {
187-
if (!eof_) {
252+
if (!eof_ && !read_error_) {
188253
// Last read was a full read, so this is a trailer to skip
189254
buffer_.clear();
190255
Status status = file_->Read(kBlockSize, &buffer_, backing_store_);
191256
end_of_buffer_offset_ += buffer_.size();
192257
if (!status.ok()) {
193258
buffer_.clear();
194259
ReportDrop(kBlockSize, status);
195-
eof_ = true;
260+
read_error_ = true;
196261
return kEof;
197262
} else if (buffer_.size() < (size_t)kBlockSize) {
198263
eof_ = true;
264+
eof_offset_ = buffer_.size();
199265
}
200266
continue;
201267
} else if (buffer_.size() == 0) {

db/log_reader.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ class Reader {
6969

7070
// when we know more data has been written to the file. we can use this
7171
// function to force the reader to look again in the file.
72-
void UnmarkEOF() {
73-
eof_ = false;
74-
}
72+
// Also aligns the file position indicator to the start of the next block
73+
// by reading the rest of the data from the EOF position to the end of the
74+
// block that was partially read.
75+
void UnmarkEOF();
7576

7677
SequentialFile* file() { return file_.get(); }
7778

@@ -82,6 +83,11 @@ class Reader {
8283
char* const backing_store_;
8384
Slice buffer_;
8485
bool eof_; // Last Read() indicated EOF by returning < kBlockSize
86+
bool read_error_; // Error occurred while reading from file
87+
88+
// Offset of the file position indicator within the last block when an
89+
// EOF was detected.
90+
size_t eof_offset_;
8591

8692
// Offset of the last record returned by ReadRecord.
8793
uint64_t last_record_offset_;

0 commit comments

Comments
 (0)