Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 1 | #include "aos/events/logging/log_namer.h" |
| 2 | |
| 3 | #include <functional> |
| 4 | #include <map> |
| 5 | #include <memory> |
| 6 | #include <string_view> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include "absl/strings/str_cat.h" |
| 10 | #include "aos/events/logging/logfile_utils.h" |
| 11 | #include "aos/events/logging/logger_generated.h" |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 12 | #include "aos/flatbuffer_merge.h" |
Austin Schuh | 4385b14 | 2021-03-14 21:31:13 -0700 | [diff] [blame] | 13 | #include "aos/uuid.h" |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 14 | #include "flatbuffers/flatbuffers.h" |
| 15 | #include "glog/logging.h" |
| 16 | |
Austin Schuh | 8bdfc49 | 2023-02-11 12:53:13 -0800 | [diff] [blame] | 17 | DECLARE_int32(flush_size); |
| 18 | |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 19 | namespace aos { |
| 20 | namespace logger { |
| 21 | |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 22 | NewDataWriter::NewDataWriter(LogNamer *log_namer, const Node *node, |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 23 | const Node *logger_node, |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 24 | std::function<void(NewDataWriter *)> reopen, |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 25 | std::function<void(NewDataWriter *)> close, |
| 26 | size_t max_message_size) |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 27 | : node_(node), |
| 28 | node_index_(configuration::GetNodeIndex(log_namer->configuration_, node)), |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 29 | logger_node_index_( |
| 30 | configuration::GetNodeIndex(log_namer->configuration_, logger_node)), |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 31 | log_namer_(log_namer), |
| 32 | reopen_(std::move(reopen)), |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 33 | close_(std::move(close)), |
| 34 | max_message_size_(max_message_size) { |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 35 | state_.resize(configuration::NodesCount(log_namer->configuration_)); |
| 36 | CHECK_LT(node_index_, state_.size()); |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | NewDataWriter::~NewDataWriter() { |
| 40 | if (writer) { |
| 41 | Close(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void NewDataWriter::Rotate() { |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 46 | // No need to rotate if nothing has been written. |
| 47 | if (header_written_) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 48 | VLOG(1) << "Rotated " << filename(); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 49 | ++parts_index_; |
| 50 | reopen_(this); |
| 51 | header_written_ = false; |
| 52 | QueueHeader(MakeHeader()); |
| 53 | } |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 56 | void NewDataWriter::Reboot(const UUID &source_node_boot_uuid) { |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 57 | parts_uuid_ = UUID::Random(); |
| 58 | ++parts_index_; |
| 59 | reopen_(this); |
| 60 | header_written_ = false; |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 61 | for (State &state : state_) { |
| 62 | state.boot_uuid = UUID::Zero(); |
| 63 | state.oldest_remote_monotonic_timestamp = monotonic_clock::max_time; |
| 64 | state.oldest_local_monotonic_timestamp = monotonic_clock::max_time; |
| 65 | state.oldest_remote_unreliable_monotonic_timestamp = |
| 66 | monotonic_clock::max_time; |
| 67 | state.oldest_local_unreliable_monotonic_timestamp = |
| 68 | monotonic_clock::max_time; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 69 | state.oldest_remote_reliable_monotonic_timestamp = |
| 70 | monotonic_clock::max_time; |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 71 | state.oldest_local_reliable_monotonic_timestamp = monotonic_clock::max_time; |
| 72 | state.oldest_logger_remote_unreliable_monotonic_timestamp = |
| 73 | monotonic_clock::max_time; |
| 74 | state.oldest_logger_local_unreliable_monotonic_timestamp = |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 75 | monotonic_clock::max_time; |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | state_[node_index_].boot_uuid = source_node_boot_uuid; |
| 79 | |
| 80 | VLOG(1) << "Rebooted " << filename(); |
| 81 | } |
| 82 | |
| 83 | void NewDataWriter::UpdateBoot(const UUID &source_node_boot_uuid) { |
| 84 | if (state_[node_index_].boot_uuid != source_node_boot_uuid) { |
| 85 | state_[node_index_].boot_uuid = source_node_boot_uuid; |
| 86 | if (header_written_) { |
| 87 | Reboot(source_node_boot_uuid); |
| 88 | } |
| 89 | } |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 92 | void NewDataWriter::UpdateRemote( |
| 93 | const size_t remote_node_index, const UUID &remote_node_boot_uuid, |
| 94 | const monotonic_clock::time_point monotonic_remote_time, |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 95 | const monotonic_clock::time_point monotonic_event_time, const bool reliable, |
| 96 | monotonic_clock::time_point monotonic_timestamp_time) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 97 | // Trigger rotation if anything in the header changes. |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 98 | bool rotate = false; |
| 99 | CHECK_LT(remote_node_index, state_.size()); |
| 100 | State &state = state_[remote_node_index]; |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 101 | |
| 102 | // Did the remote boot UUID change? |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 103 | if (state.boot_uuid != remote_node_boot_uuid) { |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 104 | VLOG(1) << filename() << " Remote " << remote_node_index << " updated to " |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 105 | << remote_node_boot_uuid << " from " << state.boot_uuid; |
| 106 | state.boot_uuid = remote_node_boot_uuid; |
| 107 | state.oldest_remote_monotonic_timestamp = monotonic_clock::max_time; |
| 108 | state.oldest_local_monotonic_timestamp = monotonic_clock::max_time; |
| 109 | state.oldest_remote_unreliable_monotonic_timestamp = |
| 110 | monotonic_clock::max_time; |
| 111 | state.oldest_local_unreliable_monotonic_timestamp = |
| 112 | monotonic_clock::max_time; |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 113 | state.oldest_remote_reliable_monotonic_timestamp = |
| 114 | monotonic_clock::max_time; |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 115 | state.oldest_local_reliable_monotonic_timestamp = monotonic_clock::max_time; |
| 116 | state.oldest_logger_remote_unreliable_monotonic_timestamp = |
| 117 | monotonic_clock::max_time; |
| 118 | state.oldest_logger_local_unreliable_monotonic_timestamp = |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 119 | monotonic_clock::max_time; |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 120 | rotate = true; |
| 121 | } |
| 122 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 123 | // Did the unreliable timestamps change? |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 124 | if (!reliable) { |
| 125 | if (state.oldest_remote_unreliable_monotonic_timestamp > |
| 126 | monotonic_remote_time) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 127 | VLOG(1) << filename() << " Remote " << remote_node_index |
| 128 | << " oldest_remote_unreliable_monotonic_timestamp updated from " |
| 129 | << state.oldest_remote_unreliable_monotonic_timestamp << " to " |
| 130 | << monotonic_remote_time; |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 131 | state.oldest_remote_unreliable_monotonic_timestamp = |
| 132 | monotonic_remote_time; |
| 133 | state.oldest_local_unreliable_monotonic_timestamp = monotonic_event_time; |
| 134 | rotate = true; |
| 135 | } |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 136 | } else { |
| 137 | if (state.oldest_remote_reliable_monotonic_timestamp > |
| 138 | monotonic_remote_time) { |
| 139 | VLOG(1) << filename() << " Remote " << remote_node_index |
| 140 | << " oldest_remote_reliable_monotonic_timestamp updated from " |
| 141 | << state.oldest_remote_reliable_monotonic_timestamp << " to " |
| 142 | << monotonic_remote_time; |
| 143 | state.oldest_remote_reliable_monotonic_timestamp = monotonic_remote_time; |
| 144 | state.oldest_local_reliable_monotonic_timestamp = monotonic_event_time; |
| 145 | rotate = true; |
| 146 | } |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 149 | // Track the logger timestamps too. |
| 150 | if (monotonic_timestamp_time != monotonic_clock::min_time) { |
| 151 | State &logger_state = state_[node_index_]; |
| 152 | CHECK_EQ(remote_node_index, logger_node_index_); |
| 153 | if (monotonic_event_time < |
| 154 | logger_state.oldest_logger_remote_unreliable_monotonic_timestamp) { |
| 155 | VLOG(1) |
| 156 | << filename() << " Remote " << node_index_ |
| 157 | << " oldest_logger_remote_unreliable_monotonic_timestamp updated " |
| 158 | "from " |
| 159 | << logger_state.oldest_logger_remote_unreliable_monotonic_timestamp |
| 160 | << " to " << monotonic_event_time; |
| 161 | logger_state.oldest_logger_remote_unreliable_monotonic_timestamp = |
| 162 | monotonic_event_time; |
| 163 | logger_state.oldest_logger_local_unreliable_monotonic_timestamp = |
| 164 | monotonic_timestamp_time; |
| 165 | |
| 166 | rotate = true; |
| 167 | } |
| 168 | } |
| 169 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 170 | // Did any of the timestamps change? |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 171 | if (state.oldest_remote_monotonic_timestamp > monotonic_remote_time) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 172 | VLOG(1) << filename() << " Remote " << remote_node_index |
| 173 | << " oldest_remote_monotonic_timestamp updated from " |
| 174 | << state.oldest_remote_monotonic_timestamp << " to " |
| 175 | << monotonic_remote_time; |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 176 | state.oldest_remote_monotonic_timestamp = monotonic_remote_time; |
| 177 | state.oldest_local_monotonic_timestamp = monotonic_event_time; |
| 178 | rotate = true; |
| 179 | } |
| 180 | |
| 181 | if (rotate) { |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 182 | Rotate(); |
| 183 | } |
| 184 | } |
| 185 | |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 186 | void NewDataWriter::CopyMessage(DataEncoder::Copier *coppier, |
| 187 | const UUID &source_node_boot_uuid, |
| 188 | aos::monotonic_clock::time_point now) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 189 | // Trigger a reboot if we detect the boot UUID change. |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 190 | UpdateBoot(source_node_boot_uuid); |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 191 | |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 192 | if (!header_written_) { |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 193 | QueueHeader(MakeHeader()); |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 194 | } |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 195 | |
| 196 | // If the start time has changed for this node, trigger a rotation. |
| 197 | if (log_namer_->monotonic_start_time(node_index_, source_node_boot_uuid) != |
Austin Schuh | 5e14d84 | 2022-01-21 12:02:15 -0800 | [diff] [blame] | 198 | monotonic_start_time_) { |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 199 | CHECK(header_written_); |
| 200 | Rotate(); |
| 201 | } |
| 202 | |
| 203 | CHECK_EQ(log_namer_->monotonic_start_time(node_index_, source_node_boot_uuid), |
| 204 | monotonic_start_time_); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 205 | CHECK_EQ(state_[node_index_].boot_uuid, source_node_boot_uuid); |
milind-u | a50344f | 2021-08-25 18:22:20 -0700 | [diff] [blame] | 206 | CHECK(writer); |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 207 | CHECK(header_written_) << ": Attempting to write message before header to " |
| 208 | << writer->filename(); |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 209 | writer->CopyMessage(coppier, now); |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 212 | aos::SizePrefixedFlatbufferDetachedBuffer<LogFileHeader> |
| 213 | NewDataWriter::MakeHeader() { |
| 214 | const size_t logger_node_index = log_namer_->logger_node_index(); |
| 215 | const UUID &logger_node_boot_uuid = log_namer_->logger_node_boot_uuid(); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 216 | if (state_[logger_node_index].boot_uuid == UUID::Zero()) { |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 217 | VLOG(1) << filename() << " Logger node is " << logger_node_index |
| 218 | << " and uuid is " << logger_node_boot_uuid; |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 219 | state_[logger_node_index].boot_uuid = logger_node_boot_uuid; |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 220 | } else { |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 221 | CHECK_EQ(state_[logger_node_index].boot_uuid, logger_node_boot_uuid); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 222 | } |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 223 | return log_namer_->MakeHeader(node_index_, state_, parts_uuid(), |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 224 | parts_index_); |
| 225 | } |
| 226 | |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 227 | void NewDataWriter::QueueHeader( |
| 228 | aos::SizePrefixedFlatbufferDetachedBuffer<LogFileHeader> &&header) { |
| 229 | CHECK(!header_written_) << ": Attempting to write duplicate header to " |
| 230 | << writer->filename(); |
| 231 | CHECK(header.message().has_source_node_boot_uuid()); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 232 | CHECK_EQ(state_[node_index_].boot_uuid, |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 233 | UUID::FromString(header.message().source_node_boot_uuid())); |
Austin Schuh | 510dc62 | 2021-08-06 18:47:30 -0700 | [diff] [blame] | 234 | if (!writer) { |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 235 | // Since we haven't opened the first time, it's still not too late to update |
| 236 | // the max message size. Make sure the header fits. |
| 237 | // |
| 238 | // This won't work well on reboots, but the structure of the header is fixed |
| 239 | // by that point in time, so it's size is fixed too. |
| 240 | // |
| 241 | // Most of the time, the minimum buffer size inside the encoder of around |
| 242 | // 128k will make this a non-issue. |
| 243 | UpdateMaxMessageSize(header.span().size()); |
| 244 | |
Austin Schuh | 510dc62 | 2021-08-06 18:47:30 -0700 | [diff] [blame] | 245 | reopen_(this); |
| 246 | } |
| 247 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 248 | VLOG(1) << "Writing to " << filename() << " " |
| 249 | << aos::FlatbufferToJson( |
| 250 | header, {.multi_line = false, .max_vector_size = 100}); |
| 251 | |
Austin Schuh | 510dc62 | 2021-08-06 18:47:30 -0700 | [diff] [blame] | 252 | CHECK(writer); |
Austin Schuh | 7ef11a4 | 2023-02-04 17:15:12 -0800 | [diff] [blame] | 253 | DataEncoder::SpanCopier coppier(header.span()); |
| 254 | writer->CopyMessage(&coppier, aos::monotonic_clock::now()); |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 255 | header_written_ = true; |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 256 | monotonic_start_time_ = log_namer_->monotonic_start_time( |
| 257 | node_index_, state_[node_index_].boot_uuid); |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void NewDataWriter::Close() { |
| 261 | CHECK(writer); |
| 262 | close_(this); |
| 263 | writer.reset(); |
| 264 | header_written_ = false; |
| 265 | } |
| 266 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 267 | LogNamer::NodeState *LogNamer::GetNodeState(size_t node_index, |
| 268 | const UUID &boot_uuid) { |
| 269 | auto it = node_states_.find(std::make_pair(node_index, boot_uuid)); |
| 270 | if (it == node_states_.end()) { |
| 271 | it = |
| 272 | node_states_.emplace(std::make_pair(node_index, boot_uuid), NodeState()) |
| 273 | .first; |
| 274 | } |
| 275 | return &it->second; |
| 276 | } |
| 277 | |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 278 | aos::SizePrefixedFlatbufferDetachedBuffer<LogFileHeader> LogNamer::MakeHeader( |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 279 | size_t node_index, const std::vector<NewDataWriter::State> &state, |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 280 | const UUID &parts_uuid, int parts_index) { |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 281 | const UUID &source_node_boot_uuid = state[node_index].boot_uuid; |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 282 | const Node *const source_node = |
| 283 | configuration::GetNode(configuration_, node_index); |
Austin Schuh | fa71268 | 2022-05-11 16:43:42 -0700 | [diff] [blame] | 284 | CHECK_EQ(LogFileHeader::MiniReflectTypeTable()->num_elems, 34u); |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 285 | flatbuffers::FlatBufferBuilder fbb; |
| 286 | fbb.ForceDefaults(true); |
| 287 | |
| 288 | flatbuffers::Offset<flatbuffers::String> config_sha256_offset; |
| 289 | flatbuffers::Offset<aos::Configuration> configuration_offset; |
| 290 | if (header_.message().has_configuration()) { |
| 291 | CHECK(!header_.message().has_configuration_sha256()); |
| 292 | configuration_offset = |
| 293 | CopyFlatBuffer(header_.message().configuration(), &fbb); |
| 294 | } else { |
| 295 | CHECK(!header_.message().has_configuration()); |
| 296 | CHECK(header_.message().has_configuration_sha256()); |
| 297 | config_sha256_offset = fbb.CreateString( |
| 298 | header_.message().configuration_sha256()->string_view()); |
| 299 | } |
| 300 | |
| 301 | CHECK(header_.message().has_name()); |
| 302 | const flatbuffers::Offset<flatbuffers::String> name_offset = |
| 303 | fbb.CreateString(header_.message().name()->string_view()); |
Austin Schuh | fa71268 | 2022-05-11 16:43:42 -0700 | [diff] [blame] | 304 | const flatbuffers::Offset<flatbuffers::String> logger_sha1_offset = |
| 305 | header_.message().has_logger_sha1() |
| 306 | ? fbb.CreateString(header_.message().logger_sha1()->string_view()) |
| 307 | : 0; |
| 308 | const flatbuffers::Offset<flatbuffers::String> logger_version_offset = |
| 309 | header_.message().has_logger_version() |
| 310 | ? fbb.CreateString(header_.message().logger_version()->string_view()) |
| 311 | : 0; |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 312 | |
| 313 | CHECK(header_.message().has_log_event_uuid()); |
| 314 | const flatbuffers::Offset<flatbuffers::String> log_event_uuid_offset = |
| 315 | fbb.CreateString(header_.message().log_event_uuid()->string_view()); |
| 316 | |
| 317 | CHECK(header_.message().has_logger_instance_uuid()); |
| 318 | const flatbuffers::Offset<flatbuffers::String> logger_instance_uuid_offset = |
| 319 | fbb.CreateString(header_.message().logger_instance_uuid()->string_view()); |
| 320 | |
| 321 | flatbuffers::Offset<flatbuffers::String> log_start_uuid_offset; |
| 322 | if (header_.message().has_log_start_uuid()) { |
| 323 | log_start_uuid_offset = |
| 324 | fbb.CreateString(header_.message().log_start_uuid()->string_view()); |
| 325 | } |
| 326 | |
| 327 | CHECK(header_.message().has_logger_node_boot_uuid()); |
| 328 | const flatbuffers::Offset<flatbuffers::String> logger_node_boot_uuid_offset = |
| 329 | fbb.CreateString( |
| 330 | header_.message().logger_node_boot_uuid()->string_view()); |
| 331 | |
| 332 | CHECK_NE(source_node_boot_uuid, UUID::Zero()); |
| 333 | const flatbuffers::Offset<flatbuffers::String> source_node_boot_uuid_offset = |
| 334 | source_node_boot_uuid.PackString(&fbb); |
| 335 | |
| 336 | const flatbuffers::Offset<flatbuffers::String> parts_uuid_offset = |
| 337 | parts_uuid.PackString(&fbb); |
| 338 | |
| 339 | flatbuffers::Offset<Node> node_offset; |
| 340 | flatbuffers::Offset<Node> logger_node_offset; |
| 341 | |
| 342 | if (configuration::MultiNode(configuration_)) { |
| 343 | node_offset = RecursiveCopyFlatBuffer(source_node, &fbb); |
| 344 | logger_node_offset = RecursiveCopyFlatBuffer(node_, &fbb); |
| 345 | } |
| 346 | |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 347 | std::vector<flatbuffers::Offset<flatbuffers::String>> boot_uuid_offsets; |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 348 | boot_uuid_offsets.reserve(state.size()); |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 349 | |
Austin Schuh | 4db9ec9 | 2021-09-22 13:11:12 -0700 | [diff] [blame] | 350 | int64_t *unused; |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 351 | flatbuffers::Offset<flatbuffers::Vector<int64_t>> |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 352 | oldest_remote_monotonic_timestamps_offset = |
| 353 | fbb.CreateUninitializedVector(state.size(), &unused); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 354 | |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 355 | flatbuffers::Offset<flatbuffers::Vector<int64_t>> |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 356 | oldest_local_monotonic_timestamps_offset = |
| 357 | fbb.CreateUninitializedVector(state.size(), &unused); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 358 | |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 359 | flatbuffers::Offset<flatbuffers::Vector<int64_t>> |
| 360 | oldest_remote_unreliable_monotonic_timestamps_offset = |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 361 | fbb.CreateUninitializedVector(state.size(), &unused); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 362 | |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 363 | flatbuffers::Offset<flatbuffers::Vector<int64_t>> |
| 364 | oldest_local_unreliable_monotonic_timestamps_offset = |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 365 | fbb.CreateUninitializedVector(state.size(), &unused); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 366 | |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 367 | flatbuffers::Offset<flatbuffers::Vector<int64_t>> |
| 368 | oldest_remote_reliable_monotonic_timestamps_offset = |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 369 | fbb.CreateUninitializedVector(state.size(), &unused); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 370 | |
| 371 | flatbuffers::Offset<flatbuffers::Vector<int64_t>> |
| 372 | oldest_local_reliable_monotonic_timestamps_offset = |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 373 | fbb.CreateUninitializedVector(state.size(), &unused); |
| 374 | |
| 375 | flatbuffers::Offset<flatbuffers::Vector<int64_t>> |
| 376 | oldest_logger_remote_unreliable_monotonic_timestamps_offset = |
| 377 | fbb.CreateUninitializedVector(state.size(), &unused); |
| 378 | |
| 379 | flatbuffers::Offset<flatbuffers::Vector<int64_t>> |
| 380 | oldest_logger_local_unreliable_monotonic_timestamps_offset = |
| 381 | fbb.CreateUninitializedVector(state.size(), &unused); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 382 | |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 383 | for (size_t i = 0; i < state.size(); ++i) { |
Austin Schuh | 4db9ec9 | 2021-09-22 13:11:12 -0700 | [diff] [blame] | 384 | if (state[i].boot_uuid != UUID::Zero()) { |
| 385 | boot_uuid_offsets.emplace_back(state[i].boot_uuid.PackString(&fbb)); |
| 386 | } else { |
| 387 | boot_uuid_offsets.emplace_back(fbb.CreateString("")); |
| 388 | } |
Austin Schuh | 5ae8f4a | 2021-09-11 19:09:50 -0700 | [diff] [blame] | 389 | if (state[i].boot_uuid == UUID::Zero()) { |
| 390 | CHECK_EQ(state[i].oldest_remote_monotonic_timestamp, |
| 391 | monotonic_clock::max_time); |
| 392 | CHECK_EQ(state[i].oldest_local_monotonic_timestamp, |
| 393 | monotonic_clock::max_time); |
| 394 | CHECK_EQ(state[i].oldest_remote_unreliable_monotonic_timestamp, |
| 395 | monotonic_clock::max_time); |
| 396 | CHECK_EQ(state[i].oldest_local_unreliable_monotonic_timestamp, |
| 397 | monotonic_clock::max_time); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 398 | CHECK_EQ(state[i].oldest_remote_reliable_monotonic_timestamp, |
| 399 | monotonic_clock::max_time); |
| 400 | CHECK_EQ(state[i].oldest_local_reliable_monotonic_timestamp, |
| 401 | monotonic_clock::max_time); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 402 | CHECK_EQ(state[i].oldest_logger_remote_unreliable_monotonic_timestamp, |
| 403 | monotonic_clock::max_time); |
| 404 | CHECK_EQ(state[i].oldest_logger_local_unreliable_monotonic_timestamp, |
| 405 | monotonic_clock::max_time); |
Austin Schuh | 5ae8f4a | 2021-09-11 19:09:50 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Austin Schuh | 4db9ec9 | 2021-09-22 13:11:12 -0700 | [diff] [blame] | 408 | flatbuffers::GetMutableTemporaryPointer( |
| 409 | fbb, oldest_remote_monotonic_timestamps_offset) |
| 410 | ->Mutate(i, state[i] |
| 411 | .oldest_remote_monotonic_timestamp.time_since_epoch() |
| 412 | .count()); |
| 413 | flatbuffers::GetMutableTemporaryPointer( |
| 414 | fbb, oldest_local_monotonic_timestamps_offset) |
| 415 | ->Mutate(i, state[i] |
| 416 | .oldest_local_monotonic_timestamp.time_since_epoch() |
| 417 | .count()); |
| 418 | flatbuffers::GetMutableTemporaryPointer( |
| 419 | fbb, oldest_remote_unreliable_monotonic_timestamps_offset) |
| 420 | ->Mutate(i, state[i] |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 421 | .oldest_remote_unreliable_monotonic_timestamp |
| 422 | .time_since_epoch() |
Austin Schuh | 4db9ec9 | 2021-09-22 13:11:12 -0700 | [diff] [blame] | 423 | .count()); |
| 424 | flatbuffers::GetMutableTemporaryPointer( |
| 425 | fbb, oldest_local_unreliable_monotonic_timestamps_offset) |
| 426 | ->Mutate(i, state[i] |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 427 | .oldest_local_unreliable_monotonic_timestamp |
| 428 | .time_since_epoch() |
Austin Schuh | 4db9ec9 | 2021-09-22 13:11:12 -0700 | [diff] [blame] | 429 | .count()); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 430 | |
| 431 | flatbuffers::GetMutableTemporaryPointer( |
| 432 | fbb, oldest_remote_reliable_monotonic_timestamps_offset) |
| 433 | ->Mutate(i, state[i] |
| 434 | .oldest_remote_reliable_monotonic_timestamp |
| 435 | .time_since_epoch() |
| 436 | .count()); |
| 437 | flatbuffers::GetMutableTemporaryPointer( |
| 438 | fbb, oldest_local_reliable_monotonic_timestamps_offset) |
| 439 | ->Mutate( |
| 440 | i, state[i] |
| 441 | .oldest_local_reliable_monotonic_timestamp.time_since_epoch() |
| 442 | .count()); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 443 | |
| 444 | flatbuffers::GetMutableTemporaryPointer( |
| 445 | fbb, oldest_logger_remote_unreliable_monotonic_timestamps_offset) |
| 446 | ->Mutate(i, state[i] |
| 447 | .oldest_logger_remote_unreliable_monotonic_timestamp |
| 448 | .time_since_epoch() |
| 449 | .count()); |
| 450 | flatbuffers::GetMutableTemporaryPointer( |
| 451 | fbb, oldest_logger_local_unreliable_monotonic_timestamps_offset) |
| 452 | ->Mutate(i, state[i] |
| 453 | .oldest_logger_local_unreliable_monotonic_timestamp |
| 454 | .time_since_epoch() |
| 455 | .count()); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Austin Schuh | 4db9ec9 | 2021-09-22 13:11:12 -0700 | [diff] [blame] | 458 | flatbuffers::Offset< |
| 459 | flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> |
| 460 | boot_uuids_offset = fbb.CreateVector(boot_uuid_offsets); |
| 461 | |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 462 | aos::logger::LogFileHeader::Builder log_file_header_builder(fbb); |
| 463 | |
| 464 | log_file_header_builder.add_name(name_offset); |
Austin Schuh | fa71268 | 2022-05-11 16:43:42 -0700 | [diff] [blame] | 465 | if (!logger_sha1_offset.IsNull()) { |
| 466 | log_file_header_builder.add_logger_sha1(logger_sha1_offset); |
| 467 | } |
| 468 | if (!logger_version_offset.IsNull()) { |
| 469 | log_file_header_builder.add_logger_version(logger_version_offset); |
| 470 | } |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 471 | |
| 472 | // Only add the node if we are running in a multinode configuration. |
| 473 | if (!logger_node_offset.IsNull()) { |
| 474 | log_file_header_builder.add_node(node_offset); |
| 475 | log_file_header_builder.add_logger_node(logger_node_offset); |
| 476 | } |
| 477 | |
| 478 | if (!configuration_offset.IsNull()) { |
| 479 | log_file_header_builder.add_configuration(configuration_offset); |
| 480 | } |
| 481 | log_file_header_builder.add_max_out_of_order_duration( |
| 482 | header_.message().max_out_of_order_duration()); |
| 483 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 484 | NodeState *node_state = GetNodeState(node_index, source_node_boot_uuid); |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 485 | log_file_header_builder.add_monotonic_start_time( |
| 486 | std::chrono::duration_cast<std::chrono::nanoseconds>( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 487 | node_state->monotonic_start_time.time_since_epoch()) |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 488 | .count()); |
| 489 | if (source_node == node_) { |
| 490 | log_file_header_builder.add_realtime_start_time( |
| 491 | std::chrono::duration_cast<std::chrono::nanoseconds>( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 492 | node_state->realtime_start_time.time_since_epoch()) |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 493 | .count()); |
| 494 | } else { |
| 495 | // Fill out the legacy start times. Since these were implemented to never |
| 496 | // change on reboot, they aren't very helpful in tracking what happened. |
| 497 | log_file_header_builder.add_logger_monotonic_start_time( |
| 498 | std::chrono::duration_cast<std::chrono::nanoseconds>( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 499 | node_state->logger_monotonic_start_time.time_since_epoch()) |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 500 | .count()); |
| 501 | log_file_header_builder.add_logger_realtime_start_time( |
| 502 | std::chrono::duration_cast<std::chrono::nanoseconds>( |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 503 | node_state->logger_realtime_start_time.time_since_epoch()) |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 504 | .count()); |
| 505 | } |
| 506 | |
| 507 | // TODO(austin): Add more useful times. When was this part started? What do |
| 508 | // we know about both the logger and remote then? |
| 509 | |
| 510 | log_file_header_builder.add_log_event_uuid(log_event_uuid_offset); |
| 511 | log_file_header_builder.add_logger_instance_uuid(logger_instance_uuid_offset); |
| 512 | if (!log_start_uuid_offset.IsNull()) { |
| 513 | log_file_header_builder.add_log_start_uuid(log_start_uuid_offset); |
| 514 | } |
| 515 | log_file_header_builder.add_logger_node_boot_uuid( |
| 516 | logger_node_boot_uuid_offset); |
| 517 | log_file_header_builder.add_source_node_boot_uuid( |
| 518 | source_node_boot_uuid_offset); |
| 519 | |
| 520 | log_file_header_builder.add_parts_uuid(parts_uuid_offset); |
| 521 | log_file_header_builder.add_parts_index(parts_index); |
| 522 | |
| 523 | if (!config_sha256_offset.IsNull()) { |
| 524 | log_file_header_builder.add_configuration_sha256(config_sha256_offset); |
| 525 | } |
| 526 | |
Austin Schuh | e46492f | 2021-07-31 19:49:41 -0700 | [diff] [blame] | 527 | log_file_header_builder.add_boot_uuids(boot_uuids_offset); |
Austin Schuh | a499cea | 2021-07-31 19:49:53 -0700 | [diff] [blame] | 528 | log_file_header_builder.add_logger_part_monotonic_start_time( |
| 529 | std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 530 | event_loop_->monotonic_now().time_since_epoch()) |
| 531 | .count()); |
| 532 | log_file_header_builder.add_logger_part_realtime_start_time( |
| 533 | std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 534 | event_loop_->realtime_now().time_since_epoch()) |
| 535 | .count()); |
Austin Schuh | 72211ae | 2021-08-05 14:02:30 -0700 | [diff] [blame] | 536 | log_file_header_builder.add_oldest_remote_monotonic_timestamps( |
| 537 | oldest_remote_monotonic_timestamps_offset); |
| 538 | log_file_header_builder.add_oldest_local_monotonic_timestamps( |
| 539 | oldest_local_monotonic_timestamps_offset); |
| 540 | log_file_header_builder.add_oldest_remote_unreliable_monotonic_timestamps( |
| 541 | oldest_remote_unreliable_monotonic_timestamps_offset); |
| 542 | log_file_header_builder.add_oldest_local_unreliable_monotonic_timestamps( |
| 543 | oldest_local_unreliable_monotonic_timestamps_offset); |
Austin Schuh | bfe6c57 | 2022-01-27 20:48:20 -0800 | [diff] [blame] | 544 | log_file_header_builder.add_oldest_remote_reliable_monotonic_timestamps( |
| 545 | oldest_remote_reliable_monotonic_timestamps_offset); |
| 546 | log_file_header_builder.add_oldest_local_reliable_monotonic_timestamps( |
| 547 | oldest_local_reliable_monotonic_timestamps_offset); |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 548 | log_file_header_builder |
| 549 | .add_oldest_logger_remote_unreliable_monotonic_timestamps( |
| 550 | oldest_logger_remote_unreliable_monotonic_timestamps_offset); |
| 551 | log_file_header_builder |
| 552 | .add_oldest_logger_local_unreliable_monotonic_timestamps( |
| 553 | oldest_logger_local_unreliable_monotonic_timestamps_offset); |
Austin Schuh | 7334084 | 2021-07-30 22:32:06 -0700 | [diff] [blame] | 554 | fbb.FinishSizePrefixed(log_file_header_builder.Finish()); |
| 555 | aos::SizePrefixedFlatbufferDetachedBuffer<LogFileHeader> result( |
| 556 | fbb.Release()); |
| 557 | |
| 558 | CHECK(result.Verify()) << ": Built a corrupted header."; |
| 559 | |
| 560 | return result; |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 563 | MultiNodeLogNamer::MultiNodeLogNamer(std::string_view base_name, |
Austin Schuh | a499cea | 2021-07-31 19:49:53 -0700 | [diff] [blame] | 564 | EventLoop *event_loop) |
Austin Schuh | 5b728b7 | 2021-06-16 14:57:15 -0700 | [diff] [blame] | 565 | : MultiNodeLogNamer(base_name, event_loop->configuration(), event_loop, |
| 566 | event_loop->node()) {} |
| 567 | |
| 568 | MultiNodeLogNamer::MultiNodeLogNamer(std::string_view base_name, |
| 569 | const Configuration *configuration, |
| 570 | EventLoop *event_loop, const Node *node) |
| 571 | : LogNamer(configuration, event_loop, node), |
| 572 | base_name_(base_name), |
Austin Schuh | 8bdfc49 | 2023-02-11 12:53:13 -0800 | [diff] [blame] | 573 | old_base_name_(), |
| 574 | encoder_factory_([](size_t max_message_size) { |
| 575 | // TODO(austin): For slow channels, can we allocate less memory? |
| 576 | return std::make_unique<DummyEncoder>(max_message_size, |
| 577 | FLAGS_flush_size); |
| 578 | }) {} |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 579 | |
Brian Silverman | 48deab1 | 2020-09-30 18:39:28 -0700 | [diff] [blame] | 580 | MultiNodeLogNamer::~MultiNodeLogNamer() { |
| 581 | if (!ran_out_of_space_) { |
| 582 | // This handles renaming temporary files etc. |
| 583 | Close(); |
| 584 | } |
| 585 | } |
| 586 | |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 587 | void MultiNodeLogNamer::Rotate(const Node *node) { |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 588 | if (node == this->node()) { |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 589 | if (data_writer_) { |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 590 | data_writer_->Rotate(); |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 591 | } |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 592 | } else { |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 593 | for (std::pair<const Channel *const, NewDataWriter> &data_writer : |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 594 | data_writers_) { |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 595 | if (node == data_writer.second.node()) { |
| 596 | data_writer.second.Rotate(); |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 602 | void MultiNodeLogNamer::WriteConfiguration( |
| 603 | aos::SizePrefixedFlatbufferDetachedBuffer<LogFileHeader> *header, |
| 604 | std::string_view config_sha256) { |
| 605 | if (ran_out_of_space_) { |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | const std::string_view separator = base_name_.back() == '/' ? "" : "_"; |
| 610 | const std::string filename = absl::StrCat( |
| 611 | base_name_, separator, config_sha256, ".bfbs", extension_, temp_suffix_); |
| 612 | |
| 613 | std::unique_ptr<DetachedBufferWriter> writer = |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 614 | std::make_unique<DetachedBufferWriter>( |
| 615 | filename, encoder_factory_(header->span().size())); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 616 | |
Austin Schuh | 7ef11a4 | 2023-02-04 17:15:12 -0800 | [diff] [blame] | 617 | DataEncoder::SpanCopier coppier(header->span()); |
| 618 | writer->CopyMessage(&coppier, aos::monotonic_clock::now()); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 619 | |
| 620 | if (!writer->ran_out_of_space()) { |
Austin Schuh | 5b728b7 | 2021-06-16 14:57:15 -0700 | [diff] [blame] | 621 | all_filenames_.emplace_back( |
| 622 | absl::StrCat(config_sha256, ".bfbs", extension_)); |
Austin Schuh | 8c39996 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 623 | } |
| 624 | CloseWriter(&writer); |
| 625 | } |
| 626 | |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 627 | NewDataWriter *MultiNodeLogNamer::MakeWriter(const Channel *channel) { |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 628 | // See if we can read the data on this node at all. |
| 629 | const bool is_readable = |
| 630 | configuration::ChannelIsReadableOnNode(channel, this->node()); |
| 631 | if (!is_readable) { |
| 632 | return nullptr; |
| 633 | } |
| 634 | |
| 635 | // Then, see if we are supposed to log the data here. |
| 636 | const bool log_message = |
| 637 | configuration::ChannelMessageIsLoggedOnNode(channel, this->node()); |
| 638 | |
| 639 | if (!log_message) { |
| 640 | return nullptr; |
| 641 | } |
| 642 | |
| 643 | // Now, sort out if this is data generated on this node, or not. It is |
| 644 | // generated if it is sendable on this node. |
| 645 | if (configuration::ChannelIsSendableOnNode(channel, this->node())) { |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 646 | if (!data_writer_) { |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 647 | MakeDataWriter(); |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 648 | } |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 649 | data_writer_->UpdateMaxMessageSize(PackMessageSize( |
| 650 | LogType::kLogRemoteMessage, channel->max_size())); |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 651 | return data_writer_.get(); |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | // Ok, we have data that is being forwarded to us that we are supposed to |
| 655 | // log. It needs to be logged with send timestamps, but be sorted enough |
| 656 | // to be able to be processed. |
| 657 | CHECK(data_writers_.find(channel) == data_writers_.end()); |
| 658 | |
| 659 | // Track that this node is being logged. |
| 660 | const Node *source_node = configuration::GetNode( |
| 661 | configuration_, channel->source_node()->string_view()); |
| 662 | |
| 663 | if (std::find(nodes_.begin(), nodes_.end(), source_node) == nodes_.end()) { |
| 664 | nodes_.emplace_back(source_node); |
| 665 | } |
| 666 | |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 667 | NewDataWriter data_writer( |
| 668 | this, source_node, node_, |
| 669 | [this, channel](NewDataWriter *data_writer) { |
| 670 | OpenWriter(channel, data_writer); |
| 671 | }, |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 672 | [this](NewDataWriter *data_writer) { CloseWriter(&data_writer->writer); }, |
| 673 | PackMessageSize(LogType::kLogRemoteMessage, channel->max_size())); |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 674 | return &( |
| 675 | data_writers_.emplace(channel, std::move(data_writer)).first->second); |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 678 | NewDataWriter *MultiNodeLogNamer::MakeForwardedTimestampWriter( |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 679 | const Channel *channel, const Node *node) { |
| 680 | // See if we can read the data on this node at all. |
| 681 | const bool is_readable = |
| 682 | configuration::ChannelIsReadableOnNode(channel, this->node()); |
| 683 | CHECK(is_readable) << ": " << configuration::CleanedChannelToString(channel); |
| 684 | |
| 685 | CHECK(data_writers_.find(channel) == data_writers_.end()); |
| 686 | |
| 687 | if (std::find(nodes_.begin(), nodes_.end(), node) == nodes_.end()) { |
| 688 | nodes_.emplace_back(node); |
| 689 | } |
| 690 | |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 691 | NewDataWriter data_writer( |
| 692 | this, configuration::GetNode(configuration_, node), node_, |
| 693 | [this, channel](NewDataWriter *data_writer) { |
| 694 | OpenForwardedTimestampWriter(channel, data_writer); |
| 695 | }, |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 696 | [this](NewDataWriter *data_writer) { CloseWriter(&data_writer->writer); }, |
| 697 | PackRemoteMessageSize()); |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 698 | return &( |
| 699 | data_writers_.emplace(channel, std::move(data_writer)).first->second); |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 702 | NewDataWriter *MultiNodeLogNamer::MakeTimestampWriter(const Channel *channel) { |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 703 | bool log_delivery_times = false; |
| 704 | if (this->node() != nullptr) { |
| 705 | log_delivery_times = configuration::ConnectionDeliveryTimeIsLoggedOnNode( |
| 706 | channel, this->node(), this->node()); |
| 707 | } |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 708 | if (!log_delivery_times) { |
| 709 | return nullptr; |
| 710 | } |
| 711 | |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 712 | if (!data_writer_) { |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 713 | MakeDataWriter(); |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 714 | } |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 715 | data_writer_->UpdateMaxMessageSize( |
| 716 | PackMessageSize(LogType::kLogDeliveryTimeOnly, 0)); |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 717 | return data_writer_.get(); |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 720 | void MultiNodeLogNamer::Close() { |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 721 | data_writers_.clear(); |
| 722 | data_writer_.reset(); |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | void MultiNodeLogNamer::ResetStatistics() { |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 726 | for (std::pair<const Channel *const, NewDataWriter> &data_writer : |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 727 | data_writers_) { |
Austin Schuh | ad0cfc3 | 2020-12-21 12:34:26 -0800 | [diff] [blame] | 728 | if (!data_writer.second.writer) continue; |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 729 | data_writer.second.writer->ResetStatistics(); |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 730 | } |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 731 | if (data_writer_) { |
| 732 | data_writer_->writer->ResetStatistics(); |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 733 | } |
| 734 | max_write_time_ = std::chrono::nanoseconds::zero(); |
| 735 | max_write_time_bytes_ = -1; |
| 736 | max_write_time_messages_ = -1; |
| 737 | total_write_time_ = std::chrono::nanoseconds::zero(); |
| 738 | total_write_count_ = 0; |
| 739 | total_write_messages_ = 0; |
| 740 | total_write_bytes_ = 0; |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 743 | void MultiNodeLogNamer::OpenForwardedTimestampWriter( |
| 744 | const Channel *channel, NewDataWriter *data_writer) { |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 745 | std::string filename = |
Austin Schuh | e715eae | 2020-10-10 15:39:30 -0700 | [diff] [blame] | 746 | absl::StrCat("timestamps", channel->name()->string_view(), "/", |
Brian Silverman | a621f52 | 2020-09-30 16:52:43 -0700 | [diff] [blame] | 747 | channel->type()->string_view(), ".part", |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 748 | data_writer->parts_index(), ".bfbs", extension_); |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 749 | CreateBufferWriter(filename, data_writer->max_message_size(), |
| 750 | &data_writer->writer); |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | void MultiNodeLogNamer::OpenWriter(const Channel *channel, |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 754 | NewDataWriter *data_writer) { |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 755 | const std::string filename = absl::StrCat( |
Austin Schuh | e715eae | 2020-10-10 15:39:30 -0700 | [diff] [blame] | 756 | CHECK_NOTNULL(channel->source_node())->string_view(), "_data", |
Brian Silverman | a621f52 | 2020-09-30 16:52:43 -0700 | [diff] [blame] | 757 | channel->name()->string_view(), "/", channel->type()->string_view(), |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 758 | ".part", data_writer->parts_index(), ".bfbs", extension_); |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 759 | CreateBufferWriter(filename, data_writer->max_message_size(), |
| 760 | &data_writer->writer); |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 763 | void MultiNodeLogNamer::MakeDataWriter() { |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 764 | if (!data_writer_) { |
| 765 | data_writer_ = std::make_unique<NewDataWriter>( |
Austin Schuh | f5f99f3 | 2022-02-07 20:05:37 -0800 | [diff] [blame] | 766 | this, node_, node_, |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 767 | [this](NewDataWriter *writer) { |
| 768 | std::string name; |
| 769 | if (node() != nullptr) { |
| 770 | name = absl::StrCat(name, node()->name()->string_view(), "_"); |
| 771 | } |
Austin Schuh | 572924a | 2021-07-30 22:32:12 -0700 | [diff] [blame] | 772 | absl::StrAppend(&name, "data.part", writer->parts_index(), ".bfbs", |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 773 | extension_); |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 774 | CreateBufferWriter(name, writer->max_message_size(), &writer->writer); |
Austin Schuh | b8bca73 | 2021-07-30 22:32:00 -0700 | [diff] [blame] | 775 | }, |
| 776 | [this](NewDataWriter *data_writer) { |
| 777 | CloseWriter(&data_writer->writer); |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 778 | }, |
| 779 | // Default size is 0 so it will be obvious if something doesn't fix it |
| 780 | // afterwards. |
| 781 | 0); |
Brian Silverman | 7af8c90 | 2020-09-29 16:14:04 -0700 | [diff] [blame] | 782 | } |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 785 | void MultiNodeLogNamer::CreateBufferWriter( |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 786 | std::string_view path, size_t max_message_size, |
| 787 | std::unique_ptr<DetachedBufferWriter> *destination) { |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 788 | if (ran_out_of_space_) { |
| 789 | // Refuse to open any new files, which might skip data. Any existing files |
| 790 | // are in the same folder, which means they're on the same filesystem, which |
| 791 | // means they're probably going to run out of space and get stuck too. |
Austin Schuh | a426f1f | 2021-03-31 22:27:41 -0700 | [diff] [blame] | 792 | if (!destination->get()) { |
| 793 | // But avoid leaving a nullptr writer if we're out of space when |
| 794 | // attempting to open the first file. |
| 795 | *destination = std::make_unique<DetachedBufferWriter>( |
| 796 | DetachedBufferWriter::already_out_of_space_t()); |
| 797 | } |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 798 | return; |
| 799 | } |
Austin Schuh | e715eae | 2020-10-10 15:39:30 -0700 | [diff] [blame] | 800 | const std::string_view separator = base_name_.back() == '/' ? "" : "_"; |
| 801 | const std::string filename = |
| 802 | absl::StrCat(base_name_, separator, path, temp_suffix_); |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 803 | if (!destination->get()) { |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 804 | if (ran_out_of_space_) { |
| 805 | *destination = std::make_unique<DetachedBufferWriter>( |
| 806 | DetachedBufferWriter::already_out_of_space_t()); |
| 807 | return; |
| 808 | } |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 809 | *destination = std::make_unique<DetachedBufferWriter>( |
| 810 | filename, encoder_factory_(max_message_size)); |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 811 | if (!destination->get()->ran_out_of_space()) { |
| 812 | all_filenames_.emplace_back(path); |
| 813 | } |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 814 | return; |
| 815 | } |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 816 | |
| 817 | CloseWriter(destination); |
| 818 | if (ran_out_of_space_) { |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 819 | *destination->get() = |
| 820 | DetachedBufferWriter(DetachedBufferWriter::already_out_of_space_t()); |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 821 | return; |
| 822 | } |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 823 | |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 824 | *destination->get() = |
| 825 | DetachedBufferWriter(filename, encoder_factory_(max_message_size)); |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 826 | if (!destination->get()->ran_out_of_space()) { |
| 827 | all_filenames_.emplace_back(path); |
| 828 | } |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Brian Silverman | 48deab1 | 2020-09-30 18:39:28 -0700 | [diff] [blame] | 831 | void MultiNodeLogNamer::RenameTempFile(DetachedBufferWriter *destination) { |
| 832 | if (temp_suffix_.empty()) { |
| 833 | return; |
| 834 | } |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 835 | std::string current_filename = std::string(destination->filename()); |
Brian Silverman | 48deab1 | 2020-09-30 18:39:28 -0700 | [diff] [blame] | 836 | CHECK(current_filename.size() > temp_suffix_.size()); |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 837 | std::string final_filename = |
Brian Silverman | 48deab1 | 2020-09-30 18:39:28 -0700 | [diff] [blame] | 838 | current_filename.substr(0, current_filename.size() - temp_suffix_.size()); |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 839 | int result = rename(current_filename.c_str(), final_filename.c_str()); |
| 840 | |
| 841 | // When changing the base name, we rename the log folder while there active |
| 842 | // buffer writers. Therefore, the name of that active buffer may still refer |
| 843 | // to the old file location rather than the new one. This minimized changes to |
| 844 | // existing code. |
| 845 | if (result != 0 && errno != ENOSPC && !old_base_name_.empty()) { |
| 846 | auto offset = current_filename.find(old_base_name_); |
| 847 | if (offset != std::string::npos) { |
| 848 | current_filename.replace(offset, old_base_name_.length(), base_name_); |
| 849 | } |
| 850 | offset = final_filename.find(old_base_name_); |
| 851 | if (offset != std::string::npos) { |
| 852 | final_filename.replace(offset, old_base_name_.length(), base_name_); |
| 853 | } |
| 854 | result = rename(current_filename.c_str(), final_filename.c_str()); |
| 855 | } |
| 856 | |
Brian Silverman | 48deab1 | 2020-09-30 18:39:28 -0700 | [diff] [blame] | 857 | if (result != 0) { |
| 858 | if (errno == ENOSPC) { |
| 859 | ran_out_of_space_ = true; |
| 860 | return; |
| 861 | } else { |
| 862 | PLOG(FATAL) << "Renaming " << current_filename << " to " << final_filename |
| 863 | << " failed"; |
| 864 | } |
Austin Schuh | 6bb8a82 | 2021-03-31 23:04:39 -0700 | [diff] [blame] | 865 | } else { |
| 866 | VLOG(1) << "Renamed " << current_filename << " -> " << final_filename; |
Brian Silverman | 48deab1 | 2020-09-30 18:39:28 -0700 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 870 | void MultiNodeLogNamer::CloseWriter( |
| 871 | std::unique_ptr<DetachedBufferWriter> *writer_pointer) { |
| 872 | DetachedBufferWriter *const writer = writer_pointer->get(); |
| 873 | if (!writer) { |
| 874 | return; |
| 875 | } |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 876 | const bool was_open = writer->is_open(); |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 877 | writer->Close(); |
| 878 | |
| 879 | if (writer->max_write_time() > max_write_time_) { |
| 880 | max_write_time_ = writer->max_write_time(); |
| 881 | max_write_time_bytes_ = writer->max_write_time_bytes(); |
| 882 | max_write_time_messages_ = writer->max_write_time_messages(); |
| 883 | } |
| 884 | total_write_time_ += writer->total_write_time(); |
| 885 | total_write_count_ += writer->total_write_count(); |
| 886 | total_write_messages_ += writer->total_write_messages(); |
| 887 | total_write_bytes_ += writer->total_write_bytes(); |
| 888 | |
| 889 | if (writer->ran_out_of_space()) { |
| 890 | ran_out_of_space_ = true; |
| 891 | writer->acknowledge_out_of_space(); |
| 892 | } |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 893 | if (was_open) { |
| 894 | RenameTempFile(writer); |
| 895 | } else { |
| 896 | CHECK(access(std::string(writer->filename()).c_str(), F_OK) == -1) |
| 897 | << ": File should not exist: " << writer->filename(); |
| 898 | } |
Brian Silverman | cb80582 | 2020-10-06 17:43:35 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Austin Schuh | cb5601b | 2020-09-10 15:29:59 -0700 | [diff] [blame] | 901 | } // namespace logger |
| 902 | } // namespace aos |