Skip to content

Commit

Permalink
XrdTpc: Always populate error buffer with messages.
Browse files Browse the repository at this point in the history
Even when there's an internal logic error, make sure the Write
method populates the error message - if nothing else, will be useful
for debugging.
  • Loading branch information
bbockelm committed Jan 30, 2021
1 parent 3d28dd5 commit 3b40aa1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/XrdTpc/XrdTpcStream.cc
Expand Up @@ -67,10 +67,14 @@ Stream::Write(off_t offset, const char *buf, size_t size, bool force)
m_log.Emsg("Stream::Write", ss.str().c_str());
DumpBuffers();
*/
if (!m_open_for_write) return SFS_ERROR;
if (!m_open_for_write) {
if (!m_error_buf.size()) {m_error_buf = "Logic error: writing to a buffer not opened for write";}
return SFS_ERROR;
}
size_t bytes_accepted = 0;
int retval = size;
if (offset < m_offset) {
if (!m_error_buf.size()) {m_error_buf = "Logic error: writing to a prior offset";}
return SFS_ERROR;
}
// If this is write is appending to the stream and
Expand Down Expand Up @@ -107,6 +111,7 @@ Stream::Write(off_t offset, const char *buf, size_t size, bool force)
// going to force a flush even if things are not MB-aligned.
int retval2 = (*entry_iter)->Write(*this, size == 0);
if (retval2 == SFS_ERROR) {
if (!m_error_buf.size()) {m_error_buf = "Unknown filesystem write failure.";}
return retval2;
}
buffer_was_written |= retval2 > 0;
Expand All @@ -133,10 +138,13 @@ Stream::Write(off_t offset, const char *buf, size_t size, bool force)
m_avail_count = avail_count;

if (bytes_accepted != size && size) { // No place for this data in allocated buffers
if (!avail_entry) { // No available buffers to allocate.
if (!avail_entry) { // No available buffers to allocate; logic error, should not happen.
DumpBuffers();
m_error_buf = "No empty buffers available to place unordered data.";
return SFS_ERROR;
}
if (avail_entry->Accept(offset + bytes_accepted, buf, size - bytes_accepted) != size - bytes_accepted) { // Empty buffer cannot accept?!?
m_error_buf = "Empty re-ordering buffer was unable to to accept data; internal logic error.";
return SFS_ERROR;
}
m_avail_count --;
Expand Down Expand Up @@ -177,6 +185,11 @@ void
Stream::DumpBuffers() const
{
m_log.Emsg("Stream::DumpBuffers", "Beginning dump of stream buffers.");
{
std::stringstream ss;
ss << "Stream offset: " << m_offset;
m_log.Emsg("Stream::DumpBuffers", ss.str().c_str());
}
size_t idx = 0;
for (std::vector<Entry*>::const_iterator entry_iter = m_buffers.begin();
entry_iter!= m_buffers.end();
Expand Down

0 comments on commit 3b40aa1

Please sign in to comment.