Skip to content

Commit

Permalink
add guarding logs for recordio
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesge committed Dec 18, 2020
1 parent 25b68db commit b34b776
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/butil/iobuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1794,13 +1794,13 @@ size_t IOBufCutter::cutn(butil::IOBuf* out, size_t n) {
_block };
out->_push_back_ref(r);
_data = (char*)_data + n;
return n;
return n;
} else if (size != 0) {
const IOBuf::BlockRef r = { (uint32_t)((char*)_data - _block->data),
(uint32_t)size,
_block };
out->_move_back_ref(r);
_buf->_moveout_front_ref();
out->_push_back_ref(r);
_buf->_pop_front_ref();
_data = NULL;
_data_end = NULL;
_block = NULL;
Expand Down
6 changes: 2 additions & 4 deletions src/butil/iobuf_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,9 @@ inline size_t IOBufCutter::pop_front(size_t n) {
_data = (char*)_data + n;
return saved_n;
}
if (size != 0) {
n -= size;
}
n -= size;
if (!load_next_ref()) {
return saved_n;
return saved_n - n;
}
} while (true);
}
Expand Down
7 changes: 6 additions & 1 deletion src/butil/recordio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ int RecordReader::CutRecord(Record* rec) {
_ncut += meta_size;
consumed_bytes += 5 + name_size + meta_size;
}
const size_t cut_bytes = _cutter.cutn(rec->MutablePayload(), data_size - consumed_bytes);
const size_t previous_payload_size = rec->Payload().size();
const size_t cut_bytes = _cutter.cutn(rec->MutablePayload(), data_size - consumed_bytes);
const size_t after_payload_size = rec->Payload().size();
if (cut_bytes != after_payload_size) {
LOG(ERROR) << "cut_bytes=" << cut_bytes << " does not match after_payload_size=" << after_payload_size << " previous_size=" << previous_payload_size << " data_size=" << data_size << " consumed_bytes=" << consumed_bytes;
}
if (cut_bytes != data_size - consumed_bytes) {
LOG(ERROR) << "cut_bytes=" << cut_bytes << " does not match input=" << data_size - consumed_bytes;
}
Expand Down

0 comments on commit b34b776

Please sign in to comment.