Handle non-sequential writes in MultiuserFile#61
Conversation
…dating offset correctly
There was a problem hiding this comment.
Pull request overview
This PR updates MultiuserFile::Write to tolerate non-sequential writes by disabling on-write checksum calculation instead of rejecting the write, and it corrects how the next expected write offset is tracked.
Changes:
- Disable checksum calculation when a non-sequential write is detected (instead of returning
-ENOTSUP). - Update
m_nextofftooffset + bytes_writtenafter each successful write.
Comments suppressed due to low confidence (1)
src/multiuser.cpp:191
- Checksum updates use the requested
sizeinstead of the actual number of bytes written (result). If the underlying write is partial, the checksum state (and its internal offset) will advance too far and the final checksum will not match the file contents. Update the checksum with exactly the bytes successfully written (and only whenresult > 0).
auto result = m_wrapped->Write(buffer, offset, size);
if (result >= 0) {m_nextoff = offset + result;}
if (m_state)
{
m_state->Update(static_cast<const unsigned char*>(buffer), size);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…#61 logic Co-authored-by: bbockelm <1093447+bbockelm@users.noreply.github.com>
|
hi @djw8605! We have another useful application for this functionality -- do you think this PR needs more work or can we merge it? |
Co-authored-by: jthiltges <jthiltges2@unl.edu>
| delete m_state; | ||
| m_state = NULL; |
| if (m_state && result >= 0) | ||
| { | ||
| m_nextoff += result; | ||
| m_state->Update(static_cast<const unsigned char*>(buffer), size); |
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/opensciencegrid/xrootd-multiuser/sessions/8b48c00b-4671-4e36-809e-ce4ba10d7afd Co-authored-by: djw8605 <79268+djw8605@users.noreply.github.com>
Implemented in f78bdd0. I applied the requested thread fixes: non-sequential writes now invalidate existing checksum metadata after a successful write, and checksum state updates now use the actual bytes written (handling short writes correctly). |
|
|
||
| ssize_t MultiuserFile::Write(const void *buffer, off_t offset, size_t size) | ||
| { | ||
| bool checksum_abandoned = false; |
| int ChecksumManager::Del(const char *lfn, unsigned digests) | ||
| { | ||
| std::string pfn = this->LFN2PFN(lfn); | ||
| auto del_digest = [&](const char *digest_name) { | ||
| std::string checksum_name = ATTR_PREFIX; |
| int Set(const char *pfn, const ChecksumState &state); | ||
| int Set(const char *pfn, const char *cksname, const char *chksvalue); | ||
| int Del(const char *pfn, unsigned digests); |
Disable checksum calculation for non-sequential writes and update the offset correctly after writing.