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

Split update code into own module and refactor it #3785

Merged
merged 8 commits into from
Mar 10, 2017
Merged

Conversation

TheMarex
Copy link
Member

@TheMarex TheMarex commented Mar 7, 2017

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 #3737

Update: 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

Requirements / Relations

This is need for #3782 because the current update code assumes the edges are in the same order as in the osrm-extract code.

@TheMarex TheMarex force-pushed the refactor/update branch 6 times, most recently from 20a406b to f044be7 Compare March 9, 2017 15:21
@@ -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();
Copy link
Member

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);
}

Copy link
Member Author

@TheMarex TheMarex Mar 9, 2017

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.

{

template <>
void read(const boost::filesystem::path &path, SegmentDataContainer &segment_data)
Copy link
Member

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)?

Copy link
Member Author

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.

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());
Copy link
Member

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);

Copy link
Member Author

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.

Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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>;
Copy link
Member

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...

Copy link
Member

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!

Copy link
Member Author

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.

#3799


EdgeID LoadAndUpdateEdgeExpandedGraph(
std::vector<extractor::EdgeBasedEdge> &edge_based_edge_list,
std::vector<EdgeWeight> &node_weights) const;
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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. 👍

std::vector<EdgeWeight> &node_weights) const;

private:
UpdaterConfig config;
Copy link
Member

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) {}
Copy link
Member

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?

Copy link
Member Author

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);
Copy link
Member

Choose a reason for hiding this comment

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

assert not dead

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))
Copy link
Member

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

Copy link
Contributor

@oxidase oxidase left a 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
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

}
}

void CheckWeightsConsistency(
Copy link
Contributor

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

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();
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Member

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


// 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());
Copy link
Contributor

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);

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());
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member Author

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. 👍

@TheMarex
Copy link
Member Author

@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 🍏 .

@TheMarex TheMarex merged commit ffd6311 into master Mar 10, 2017
@TheMarex TheMarex deleted the refactor/update branch March 10, 2017 14:43
@TheMarex TheMarex mentioned this pull request Mar 11, 2017
3 tasks
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.

4 participants