Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileWriter and some FileReader refactoring #3383

Merged
merged 1 commit into from
Dec 6, 2016

Conversation

duizendnegen
Copy link
Contributor

@duizendnegen duizendnegen commented Nov 30, 2016

Issue

FileWriter counterpart to FileReader and one example implementation.

Tasklist

  • add regression / cucumber cases (see docs/testing.md)
  • review
  • adjust for comments

Requirements / Relations

@duizendnegen
Copy link
Contributor Author

I'd be happy to get input as for how tests should be conducted for this specific part of infrastructure - iirc @daniel-j-h mentioned that all Cucumber tests cover the IO layer implicitly anyway, and I couldn't find additional existing unit tests for the FileReader.

}

FileWriter(const boost::filesystem::path &filename_, const FingerprintFlag flag)
: filename(filename_.string())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we store a boost::fs::path to begin with? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do so across both FileReader and FileWriter.

{
output_stream.open(filename_, std::ios::binary);
if (!output_stream)
throw util::exception("Error opening " + filename + ":" + std::strerror(errno));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have separate IO exceptions? (Check the Gist in #2242 (comment)).

(btw all those commends apply to the FileReader, too cc @ghoshkaj @danpat)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I generally agree, however, I'd suggest opening another issue for that - at the moment exception (https://github.com/Project-OSRM/osrm-backend/blob/master/include/util/exception.hpp) is marked final, we'd be better of differentiating exceptions across the board in a refactor.

const auto &result = output_stream.write(reinterpret_cast<char *>(src), count * sizeof(T));
if (!result)
{
throw util::exception("Error writing to " + filename + ": " + std::strerror(errno));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm does an error here really set errno?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, will remove.

@@ -54,7 +54,8 @@ template <typename simple_type>
bool serializeVectorIntoAdjacencyArray(const std::string &filename,
const std::vector<std::vector<simple_type>> &data)
{
std::ofstream out_stream(filename, std::ios::binary);
storage::io::FileWriter file(filename, storage::io::FileWriter::HasNoFingerprint);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a clang-format script at scripts/format.sh - once your done with changes it would be great to run this.

(if you don't have clang-format we can do this for you before merging, too)

@duizendnegen
Copy link
Contributor Author

@daniel-j-h for further review

@duizendnegen duizendnegen changed the title (WIP) Feature/file writer FileWriter and some FileReader refactoring Dec 1, 2016
@daniel-j-h
Copy link
Member

Travis fails because of variant include path. I think @danpat fixed it yesterday.

Try squashing, rebasing, force pushing.

if (!result)
{
throw util::exception("Error writing to " + filepath.string() + ": " +
std::strerror(errno));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still can't find the documentation for o(f)streams setting errno.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I dropped it from the FileWriter but forgot to remove it from the FileReader, will do so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI it does set errno, at least, based on the tests it does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duizendnegen it is an ad-hoc platform-dependent result that may not correspond to a stream method call.

@daniel-j-h errno shows the thread-local result of the last syscall and without knowing stream internals it can be unrelated and will not be fixed in gcc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer @oxidase, I updated the PR again to reflect these learnings.

@daniel-j-h
Copy link
Member

cc @danpat @ghoshkaj please check in the context of your IO endeavour and then merge at will.

@duizendnegen
Copy link
Contributor Author

Rebased, squashed, let's do this! 🎉

@TheMarex
Copy link
Member

TheMarex commented Dec 6, 2016

Looks good to me 👍 merging.

@TheMarex TheMarex merged commit 6f4c6e8 into Project-OSRM:master Dec 6, 2016
@duizendnegen duizendnegen deleted the feature/file-writer branch December 6, 2016 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants