-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Split update code into own module and refactor it #3785
Conversation
20a406b
to
f044be7
Compare
f044be7
to
a4da1a7
Compare
@@ -58,21 +59,19 @@ class CompressedEdgeContainer | |||
NodeID GetLastEdgeTargetID(const EdgeID edge_id) const; | |||
NodeID GetLastEdgeSourceID(const EdgeID edge_id) const; | |||
|
|||
// Invalidates the internal storage | |||
SegmentDataContainer ToSegmentData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Urgh this is a bit weird - can you do the following in the function impl.
void fn() {
static bool dead = false;
assert !dead;
dead = true;
return move(data);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm I can put it in a unique_ptr
, I guess that is what it would be for.
include/extractor/io.hpp
Outdated
{ | ||
|
||
template <> | ||
void read(const boost::filesystem::path &path, SegmentDataContainer &segment_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a template (specialization)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because SegmentDataContainer = detail::SegmentDataContainer<UseSharedMemory=false>
. This could extended to allow the shared memory version, I'm not sure this makes sense though.
include/extractor/io.hpp
Outdated
writer.WriteFrom(segment_data.fwd_weights.data(), segment_data.fwd_weights.size()); | ||
writer.WriteFrom(segment_data.rev_weights.data(), segment_data.rev_weights.size()); | ||
writer.WriteFrom(segment_data.fwd_durations.data(), segment_data.fwd_durations.size()); | ||
writer.WriteFrom(segment_data.rev_durations.data(), segment_data.rev_durations.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm here and above - we should probably provide a range-based read/write function for contiguous containers. Pointer and size is such a common pattern, this all should be
reader.ReadInto(myvec);
writer.WriteFrom(myvec);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we already had that for reading, added it for writing too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have FileWriter::SerializeVector()
and FileReader::DeserializeVector()
those should probably be used here. Maybe not the best names, but they're already used elsewhere, so we should stay consistent until we have a better interface.
return rev_weights[index[id] + offset]; | ||
} | ||
// TODO we only need this for the datasource file since it breaks this | ||
// abstraction, but uses this index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to ticket al TODOs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Captured in #3797
} | ||
|
||
using SegmentDataView = detail::SegmentDataContainerImpl<true>; | ||
using SegmentDataContainer = detail::SegmentDataContainerImpl<false>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm generating two types for this is a bit weird but I can see how it has to be done for the shm vec...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw what we should do (not only here) is to stick to enums and specialize based on the enums instead of true / false.
SegmentDataContainerImpl<false> // ?? what is false? I have to look this up
SegmentDataContainerImpl<DoNotUseSharedMemory> // ah!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we should do this in a sweep that changes it everywhere consistently.
include/updater/updater.hpp
Outdated
|
||
EdgeID LoadAndUpdateEdgeExpandedGraph( | ||
std::vector<extractor::EdgeBasedEdge> &edge_based_edge_list, | ||
std::vector<EdgeWeight> &node_weights) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm should this be split into loading (can be re-used) and updating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also from looking at the interface only what is the return edge id supposed to mean? max id I guess but it's not clear from the decl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm not done with the refactor, there will be more splits here. Just wanted to get the big move into master
. 👍
include/updater/updater.hpp
Outdated
std::vector<EdgeWeight> &node_weights) const; | ||
|
||
private: | ||
UpdaterConfig config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing by const ref? Otherwise take by value and move in. Because now a ocpy is always made. If you take a value and move in users can move in, too. No copy is made.
@@ -34,6 +34,7 @@ class ShMemIterator | |||
typedef typename base_t::reference reference; | |||
typedef std::random_access_iterator_tag iterator_category; | |||
|
|||
explicit ShMemIterator() : m_value(nullptr) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm why the default ctor now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this for the boost::adapters::reverse
range.
|
||
SegmentDataContainer CompressedEdgeContainer::ToSegmentData() | ||
{ | ||
return std::move(segment_data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert not dead
src/updater/csv_source.cpp
Outdated
via)(decltype(osrm::updater::Turn::to), to)) | ||
BOOST_FUSION_ADAPT_STRUCT(osrm::updater::PenaltySource, | ||
(decltype(osrm::updater::PenaltySource::duration), | ||
duration)(decltype(osrm::updater::PenaltySource::weight), weight)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
urgh format seems to be broken here, what about
// clang-format off
manually format
// clang-format on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
if (std::isfinite(weight)) | ||
return std::round(weight * weight_multiplier); | ||
|
||
return duration == MAXIMAL_EDGE_DURATION ? INVALID_EDGE_WEIGHT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a regression that i personally missed: traffic updates without weights will silently change to the "duration"
weight type, so somehow this should be made explicit with correct decision:
- assertion
profile_properties.IsFallbackToDurationAllowed()
- returning
INVALID_EDGE_WEIGHT
if!profile_properties.IsFallbackToDurationAllowed()
- or make weights field in CSV files required
ATM it messes up updated edge weights when they are different wrt "duration"
weights.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the problem however that we depend on this functionality right now on our traffic processing. This is not a real problem for us right, since our weights are duration based still anyway.
We should re-think the whole approach on how we ingest weight/duration data though. It is much too easy to screw this up. Can you ticket this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/updater/updater.cpp
Outdated
} | ||
} | ||
|
||
void CheckWeightsConsistency( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the function in #if !defined(NDEBUG) .. #endif
to avoid unused function warnings
src/updater/updater.cpp
Outdated
storage::io::FileReader profile_properties_file(config.profile_properties_path, | ||
storage::io::FileReader::HasNoFingerprint); | ||
profile_properties_file.ReadInto<extractor::ProfileProperties>(&profile_properties, 1); | ||
weight_multiplier = profile_properties.GetWeightMultiplier(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto weight_multiplier = profile_properties.GetWeightMultiplier();
and remove L167
@@ -0,0 +1,81 @@ | |||
/* | |||
|
|||
Copyright (c) 2016, Project OSRM contributors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious about license boilerplate, would be enough just to reference LICENSE.txt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we removed it everywhere except for public headers we install. But even then it's questionable..
Also it's 2017 already, who wants to s/2016/2017/g ? :D
include/extractor/io.hpp
Outdated
|
||
// FIXME this _should_ just be size and the senitel below need to be removed | ||
writer.WriteElementCount32(segment_data.index.size() + 1); | ||
writer.WriteFrom(segment_data.index.data(), segment_data.index.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writer.WriteFrom(segment_data.index);
include/extractor/io.hpp
Outdated
writer.WriteElementCount32(segment_data.index.size() + 1); | ||
writer.WriteFrom(segment_data.index.data(), segment_data.index.size()); | ||
// FIMXE remove unnecessary senitel | ||
writer.WriteElementCount32(segment_data.nodes.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not remove it now? it will require only segment_data.index.push_back(num_entries) // add sentinel
on L25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, originally I didn't want to break the data format but I'm doing this with #3797 anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I found the real reason the code was added at the time: The way CompressedEdgeContainer
constructs the index was broken, so somehow a fix for this landed in the IO layer. Fixed now. 👍
@daniel-j-h @oxidase pushed some fixes to address your PR comments. Please let me know if that works for you and merge this once travis gives it a 🍏 . |
Issue
Splits out the update code into an own module in preparation to be used in the customizer as well as in the contractor.
Aim is to implement #3737Update: Implementing issue #3737 would require a few invasive changes that I don't want to include in this PR since it moves a lot of code. Splitting this off in a separate PR.
Tasklist
Implement update method based on Refactor segment update code #3737Requirements / Relations
This is need for #3782 because the current update code assumes the edges are in the same order as in theosrm-extract
code.