Allow renaming logged channels for replay
If we change an application to use a new channel for an existing
message, we need a way to support replaying old logs through it.
RenameLoggedChannel() provides an API to map the original channel to
the new one, updating the logged configuration as needed.
Since global maps for the new channel need not follow the same patterns
as the old one, any relevant maps must be specified by the user.
Change-Id: I68e9d2fe16bceaa60972a3f762f955e583c80255
Signed-off-by: Sanjay Narayanan <sanjay.narayanan@bluerivertech.com>
diff --git a/aos/events/logging/log_reader.h b/aos/events/logging/log_reader.h
index d4936f1..6a0fcea 100644
--- a/aos/events/logging/log_reader.h
+++ b/aos/events/logging/log_reader.h
@@ -32,8 +32,7 @@
class EventNotifier;
// Vector of pair of name and type of the channel
-using ReplayChannels =
- std::vector<std::pair<std::string, std::string>>;
+using ReplayChannels = std::vector<std::pair<std::string, std::string>>;
// Vector of channel indices
using ReplayChannelIndices = std::vector<size_t>;
@@ -198,7 +197,6 @@
RemapLoggedChannel(name, T::GetFullyQualifiedName(), add_prefix, new_type,
conflict_handling);
}
-
// Remaps the provided channel, though this respects node mappings, and
// preserves them too. This makes it so if /aos -> /pi1/aos on one node,
// /original/aos -> /original/pi1/aos on the same node after renaming, just
@@ -221,11 +219,40 @@
new_type, conflict_handling);
}
+ // Similar to RemapLoggedChannel(), but lets you specify a name for the new
+ // channel without constraints. This is useful when an application has been
+ // updated to use new channels but you want to support replaying old logs. By
+ // default, this will not add any maps for the new channel. Use add_maps to
+ // specify any maps you'd like added.
+ void RenameLoggedChannel(std::string_view name, std::string_view type,
+ std::string_view new_name,
+ const std::vector<MapT> &add_maps = {});
+ template <typename T>
+ void RenameLoggedChannel(std::string_view name, std::string_view new_name,
+ const std::vector<MapT> &add_maps = {}) {
+ RenameLoggedChannel(name, T::GetFullyQualifiedName(), new_name, add_maps);
+ }
+ // The following overloads are more suitable for multi-node configurations,
+ // and let you rename a channel on a specific node.
+ void RenameLoggedChannel(std::string_view name, std::string_view type,
+ const Node *node, std::string_view new_name,
+ const std::vector<MapT> &add_maps = {});
+ template <typename T>
+ void RenameLoggedChannel(std::string_view name, const Node *node,
+ std::string_view new_name,
+ const std::vector<MapT> &add_maps = {}) {
+ RenameLoggedChannel(name, T::GetFullyQualifiedName(), node, new_name,
+ add_maps);
+ }
+
template <typename T>
bool HasChannel(std::string_view name, const Node *node = nullptr) {
- return configuration::GetChannel(logged_configuration(), name,
- T::GetFullyQualifiedName(), "", node,
- true) != nullptr;
+ return HasChannel(name, T::GetFullyQualifiedName(), node);
+ }
+ bool HasChannel(std::string_view name, std::string_view type,
+ const Node *node) {
+ return configuration::GetChannel(logged_configuration(), name, type, "",
+ node, true) != nullptr;
}
template <typename T>
@@ -235,6 +262,14 @@
RemapLoggedChannel<T>(name, node);
}
}
+ template <typename T>
+ void MaybeRenameLoggedChannel(std::string_view name, const Node *node,
+ std::string_view new_name,
+ const std::vector<MapT> &add_maps = {}) {
+ if (HasChannel<T>(name, node)) {
+ RenameLoggedChannel<T>(name, node, new_name, add_maps);
+ }
+ }
// Returns true if the channel exists on the node and was logged.
template <typename T>