Skip to content

Conversation

duizendnegen
Copy link
Contributor

@duizendnegen duizendnegen commented Apr 5, 2017

Issue

#3520

Tasklist

  • convert serialization to use fingerprint generation and validation
  • replace Count32 with Count64
  • review
  • adjust for comments

Requirements / Relations

This should go in after #3892 (the other way around is too much hassle)

@duizendnegen duizendnegen force-pushed the feature/fingerprint-all-files branch from bc8647d to 196742c Compare April 7, 2017 09:02
io::FileReader reader(config.geometries_path, io::FileReader::HasNoFingerprint);
io::FileReader reader(config.geometries_path, io::FileReader::VerifyFingerprint);

const auto number_of_geometries_indices = reader.ReadVectorSize<unsigned>();
Copy link
Contributor Author

@duizendnegen duizendnegen Apr 7, 2017

Choose a reason for hiding this comment

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

What is the logic behind ReadVectorSize reading CountElement64, then skipping T (in this case unsigned)? Naming doesn't cover what's actually happening here.

Ideally I'd also take this through a files layer, any input as to how?

Copy link
Member

Choose a reason for hiding this comment

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

We need to extract the file size in order to pre-allocate the shared memory block. For this we need to extract the size of every block/vector.

I couldn't come up with a good abstraction for this yet. But yeah having a dedicated function in files:: would be good.

@duizendnegen duizendnegen mentioned this pull request Apr 7, 2017
3 tasks
auto mem = storage::makeSharedMemory(barrier.data().region);
auto layout = reinterpret_cast<storage::DataLayout *>(mem->Ptr());
return layout->GetBlockSize(storage::DataLayout::CH_CORE_MARKER) > 4;
return layout->GetBlockSize(storage::DataLayout::CH_CORE_MARKER) > 16;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This (and underlying sizeof(std::uint64_t) + sizeof(util::FingerPrint);) can really bite... Any suggestions for a more understandable naming, to get rid of these magic numbers?

The least we should do is add some comments to both sections.

@duizendnegen
Copy link
Contributor Author

Would like to unify file names between storage_config and extract_config - any objections?

@danpat
Copy link
Member

danpat commented Apr 7, 2017

@duizendnegen no objections - we have way too much repetition

@duizendnegen duizendnegen changed the title Feature/fingerprint all files Unify fingerprinting, Count64, storage_config Apr 8, 2017
using boost::interprocess::mapped_region;

{
storage::io::FileReader file(filename, storage::io::FileReader::VerifyFingerprint);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opening this file with the FileReader just for verifying the fingerprint seems a bit clumsy. On Windows this fails in a way since a subsequent call from file_mapping results in Access denied.

Is there a way to read just the Fingerprint from the mapped_region? Should we implement an explicit Close function for the FileReader/FileWriter, or do an implicit fclose on the destructor?

Copy link
Member

Choose a reason for hiding this comment

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

or do an implicit fclose on the destructor

Wait we don't close file handles? This is definitely a bug that should be fixed.

/cc @danpat I think these might be the reason we saw the file handle exhaustion.

Copy link
Member

@TheMarex TheMarex Apr 13, 2017

Choose a reason for hiding this comment

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

Okay just looked at the implementation: We just wrap ifstream which closes on destruction, which still begs the question of why this fails here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it should be close-on-destroy. The errors on appveyor seem to be around mmap calls though - perhaps we're not unmapping at some point? Multiple mappings should work though.....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wrong anyway, commented out the file reader fingerprint verification and errors still occur. I'll skip fingerprinting these mmap'ed files for now (just one file) to get this to land and open a ticket.

@duizendnegen duizendnegen force-pushed the feature/fingerprint-all-files branch from dd08505 to e445ddc Compare April 8, 2017 19:28
@duizendnegen
Copy link
Contributor Author

Ready for review / feedback. I'm tackling config normalization in a separate PR.

@duizendnegen duizendnegen mentioned this pull request Apr 8, 2017
9 tasks
@duizendnegen duizendnegen changed the title Unify fingerprinting, Count64, storage_config Unify fingerprinting & Count64 Apr 12, 2017
Copy link
Member

@TheMarex TheMarex left a comment

Choose a reason for hiding this comment

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

Looks good to me, but travis is failing because the formatting is broken.

const auto level_size = order_file.ReadElementCount32();
node_levels.resize(level_size);
order_file.ReadInto(node_levels);
files::readLevels(config.level_output_path, node_levels);
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the refactor! I think we can remove Contractor::ReadNodeLevels entirely now and directly call files::readLevels.

storage::io::FileWriter::HasNoFingerprint);

storage::serialization::write(writer, node_levels);
files::writeLevels(config.level_output_path, node_levels);
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

io::FileReader reader(config.geometries_path, io::FileReader::HasNoFingerprint);
io::FileReader reader(config.geometries_path, io::FileReader::VerifyFingerprint);

const auto number_of_geometries_indices = reader.ReadVectorSize<unsigned>();
Copy link
Member

Choose a reason for hiding this comment

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

We need to extract the file size in order to pre-allocate the shared memory block. For this we need to extract the size of every block/vector.

I couldn't come up with a good abstraction for this yet. But yeah having a dedicated function in files:: would be good.

mapped_region region{mapping, mode};

// map region started at an offset of util::FingerPrint size
mapped_region region{mapping, mode, 8};
Copy link
Member

Choose a reason for hiding this comment

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

instead of 8 what about using sizeof(Fingerprint)?

@TheMarex
Copy link
Member

Windows tests seem to fail during updating. I suspect the 8 bytes for the fingerprint are not working cross platform?

@duizendnegen
Copy link
Contributor Author

@TheMarex it's not about the 8 bytes part - see #3904 (comment) - it's opening and not explicitly closing the file, then re-opening (somehow). To get things to work I can leave out fingerprint checking .turn_penalties_index, or figure out a different way to read the fingerprint, or close the file explicitly somewhere. Open for suggestions.

@duizendnegen
Copy link
Contributor Author

Skipped the problematic .turn_penalties_index for another PR. Ready to merge from my side.

@TheMarex TheMarex merged commit e85c4f8 into Project-OSRM:master Apr 18, 2017
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.

3 participants