Skip to content

Commit

Permalink
even better error messages in file I/O errors, update util
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbr committed Sep 26, 2024
1 parent 909f961 commit bb73b3e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
44 changes: 39 additions & 5 deletions src/spatialjoin/Sweeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,14 @@ void Sweeper::flush() {
}
}

writeAll(_file, _outBuffer, _obufpos);
ssize_t r = writeAll(_file, _outBuffer, _obufpos);
if (r < 0) {
std::stringstream ss;
ss << "Could not write to events file '" << _fname << "'\n";
ss << strerror(errno) << std::endl;
throw std::runtime_error(ss.str());
}

_obufpos = 0;

_pointCache.flush();
Expand All @@ -856,7 +863,14 @@ void Sweeper::flush() {
#ifdef __unix__
posix_fadvise(newFile, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
util::externalSort(_file, newFile, sizeof(BoxVal), _curSweepId, boxCmp);
r = util::externalSort(_file, newFile, sizeof(BoxVal), _curSweepId, boxCmp);

if (r < 0) {
std::stringstream ss;
ss << "Could not sort events file '" << _fname << "'\n";
ss << strerror(errno) << std::endl;
throw std::runtime_error(ss.str());
}

fsync(newFile);

Expand All @@ -877,7 +891,13 @@ void Sweeper::diskAdd(const BoxVal& bv) {
_obufpos += sizeof(BoxVal);

if (_obufpos + sizeof(BoxVal) > BUFFER_S) {
writeAll(_file, _outBuffer, _obufpos);
ssize_t r = writeAll(_file, _outBuffer, _obufpos);
if (r < 0) {
std::stringstream ss;
ss << "Could not write to events file '" << _fname << "'\n";
ss << strerror(errno) << std::endl;
throw std::runtime_error(ss.str());
}
_obufpos = 0;
}
_curSweepId++;
Expand Down Expand Up @@ -927,7 +947,14 @@ void Sweeper::sortCache() {
size_t numEvents = _curSweepId;
_curSweepId = 0;

while ((len = util::readAll(oldFile, buf, sizeof(BoxVal) * RBUF_SIZE)) > 0) {
while ((len = util::readAll(oldFile, buf, sizeof(BoxVal) * RBUF_SIZE)) != 0) {
if (len < 0) {
std::stringstream ss;
ss << "Could not read from events file '" << _fname << "'\n";
ss << strerror(errno) << std::endl;
throw std::runtime_error(ss.str());
}

for (ssize_t i = 0; i < len; i += sizeof(BoxVal)) {
auto cur = reinterpret_cast<const BoxVal*>(buf + i);
jj++;
Expand Down Expand Up @@ -1069,7 +1096,14 @@ RelStats Sweeper::sweep() {

ssize_t len;

while ((len = util::readAll(_file, buf, sizeof(BoxVal) * RBUF_SIZE)) > 0) {
while ((len = util::readAll(_file, buf, sizeof(BoxVal) * RBUF_SIZE)) != 0) {
if (len < 0) {
std::stringstream ss;
ss << "Could not read from events file '" << _fname << "'\n";
ss << strerror(errno) << std::endl;
throw std::runtime_error(ss.str());
}

for (ssize_t i = 0; i < len; i += sizeof(BoxVal)) {
auto cur = reinterpret_cast<const BoxVal*>(buf + i);
jj++;
Expand Down
2 changes: 1 addition & 1 deletion src/util
Submodule util updated 1 files
+15 −9 Misc.h

0 comments on commit bb73b3e

Please sign in to comment.