Skip to content

Commit

Permalink
Robust schedule failover (#88)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael X. Grey <grey@openrobotics.org>
  • Loading branch information
mxgrey committed Sep 16, 2022
1 parent e60a256 commit 2cd3ec6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions rmf_traffic/include/rmf_traffic/Route.hpp
Expand Up @@ -25,6 +25,7 @@
#include <optional>
#include <set>
#include <map>
#include <unordered_map>

namespace rmf_traffic {

Expand Down
2 changes: 1 addition & 1 deletion rmf_traffic/include/rmf_traffic/schedule/Database.hpp
Expand Up @@ -116,7 +116,7 @@ class Database : public ItineraryViewer, public Writer, public Snappable
std::size_t participant_id) const final;

// Documentation inherited from Viewer
Version latest_version() const final;
Version latest_version() const;


//============================================================================
Expand Down
7 changes: 6 additions & 1 deletion rmf_traffic/include/rmf_traffic/schedule/Mirror.hpp
Expand Up @@ -58,7 +58,7 @@ class Mirror : public ItineraryViewer, public Snappable
std::size_t participant_id) const final;

// Documentation inherited from Viewer
Version latest_version() const final;
std::optional<Version> latest_version() const;


//============================================================================
Expand Down Expand Up @@ -106,6 +106,11 @@ class Mirror : public ItineraryViewer, public Snappable
/// patch does not match
bool update(const Patch& patch);

/// Tell this mirror that the upstream database is reseting its version
/// number. The next patch that this mirror receives will need to provide a
/// full update.
void reset();

/// Fork a new database off of this Mirror. The state of the new database
/// will match the last state of the upstream database that this Mirror knows
/// about.
Expand Down
2 changes: 1 addition & 1 deletion rmf_traffic/include/rmf_traffic/schedule/Viewer.hpp
Expand Up @@ -105,7 +105,7 @@ class Viewer
ParticipantId participant_id) const = 0;

/// Get the latest version number of this Database.
virtual Version latest_version() const = 0;
// virtual Version latest_version() const = 0;

// Virtual destructor
virtual ~Viewer() = default;
Expand Down
3 changes: 1 addition & 2 deletions rmf_traffic/src/rmf_traffic/schedule/Database.cpp
Expand Up @@ -1438,8 +1438,7 @@ std::shared_ptr<const Snapshot> Database::snapshot() const
return std::make_shared<SnapshotType>(
_pimpl->timeline.snapshot(check_relevant),
_pimpl->participant_ids,
_pimpl->descriptions,
_pimpl->schedule_version);
_pimpl->descriptions);
}

//==============================================================================
Expand Down
22 changes: 17 additions & 5 deletions rmf_traffic/src/rmf_traffic/schedule/Mirror.cpp
Expand Up @@ -69,7 +69,7 @@ class Mirror::Implementation

std::unordered_set<ParticipantId> participant_ids;

Version latest_version = 0;
std::optional<Version> latest_version = std::nullopt;

mutable DependencyTracker dependencies;

Expand Down Expand Up @@ -265,7 +265,7 @@ std::shared_ptr<const ParticipantDescription> Mirror::get_participant(
}

//==============================================================================
Version Mirror::latest_version() const
std::optional<Version> Mirror::latest_version() const
{
return _pimpl->latest_version;
}
Expand Down Expand Up @@ -386,8 +386,7 @@ std::shared_ptr<const Snapshot> Mirror::snapshot() const
return std::make_shared<SnapshotType>(
_pimpl->timeline.snapshot(nullptr),
_pimpl->participant_ids,
_pimpl->descriptions,
_pimpl->latest_version);
_pimpl->descriptions);
}

//==============================================================================
Expand Down Expand Up @@ -580,6 +579,19 @@ bool Mirror::update(const Patch& patch)
return true;
}

//==============================================================================
void Mirror::reset()
{
_pimpl->latest_version = std::nullopt;
for (auto& [id, state] : _pimpl->states)
{
state.storage.clear();
state.highest_storage = std::nullopt;
state.current_plan_id = std::numeric_limits<PlanId>::max();
state.itinerary_version = 0;
}
}

//==============================================================================
Database Mirror::fork() const
{
Expand Down Expand Up @@ -626,7 +638,7 @@ Database Mirror::fork() const
state.progress.version);
}

set_initial_fork_version(output, _pimpl->latest_version);
set_initial_fork_version(output, _pimpl->latest_version.value_or(0));
}
catch (const std::exception& e)
{
Expand Down
12 changes: 2 additions & 10 deletions rmf_traffic/src/rmf_traffic/schedule/internal_Snapshot.hpp
Expand Up @@ -67,20 +67,13 @@ class SnapshotImplementation : public Snapshot
return it->second;
}

Version latest_version() const final
{
return _version;
}

SnapshotImplementation(
std::shared_ptr<const TimelineView<const BaseRouteEntry>> timeline,
std::unordered_set<ParticipantId> ids,
ParticipantMap participants,
Version version)
ParticipantMap participants)
: _timeline(std::move(timeline)),
_ids(std::move(ids)),
_participants(std::move(participants)),
_version(version)
_participants(std::move(participants))
{
// Do nothing
}
Expand All @@ -90,7 +83,6 @@ class SnapshotImplementation : public Snapshot
std::shared_ptr<const TimelineView<const RouteEntry>> _timeline;
std::unordered_set<ParticipantId> _ids;
ParticipantMap _participants;
Version _version;

};

Expand Down

0 comments on commit 2cd3ec6

Please sign in to comment.