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

Abort when the max_file_size is too small #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ class DDSRECORDER_PARTICIPANTS_DllAPI McapWriter
// Whether the writer can write to the MCAP library
bool enabled_{false};

// Whether the output file is open
bool opened_{false};

// Track the size of the current MCAP file
McapSizeTracker size_tracker_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ void McapWriter::write(
on_disk_full_();
}
}
catch (const FullDiskException& e)
{
logError(DDSRECORDER_MCAP_HANDLER,
"FAIL_MCAP_WRITE | Disk is full. Error message:\n " << e.what());
on_disk_full_();
}
}

} /* namespace participants */
Expand Down
62 changes: 57 additions & 5 deletions ddsrecorder_participants/src/cpp/recorder/mcap/McapWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ void McapWriter::update_dynamic_types(
on_disk_full_();
}
}
catch (const FullDiskException& e)
{
logError(DDSRECORDER_MCAP_HANDLER,
"FAIL_MCAP_WRITE | Disk is full. Error message:\n " << e.what());
on_disk_full_();
}

dynamic_types_payload_.reset(const_cast<fastrtps::rtps::SerializedPayload_t*>(&dynamic_types_payload));
file_tracker_->set_current_file_size(size_tracker_.get_potential_mcap_size());
Expand All @@ -159,6 +165,11 @@ void McapWriter::set_on_disk_full_callback(
void McapWriter::open_new_file_nts_(
const std::uint64_t min_file_size)
{
if (opened_)
{
return;
}

try
{
file_tracker_->new_file(min_file_size);
Expand All @@ -169,6 +180,10 @@ void McapWriter::open_new_file_nts_(
"The minimum MCAP size (" + utils::from_bytes(min_file_size) + ") is greater than the maximum MCAP "
"size (" + utils::from_bytes(configuration_.max_file_size) + ").");
}
catch (const utils::InconsistencyException& e)
{
throw FullDiskException(e.what());
}

const auto filename = file_tracker_->get_current_filename();
const auto status = writer_.open(filename, mcap_configuration_);
Expand All @@ -182,6 +197,8 @@ void McapWriter::open_new_file_nts_(
throw utils::InitializationException(error_msg);
}

opened_ = true;

// Set the file's maximum size
const auto max_file_size = std::min(
configuration_.max_file_size,
Expand All @@ -204,6 +221,11 @@ void McapWriter::open_new_file_nts_(

void McapWriter::close_current_file_nts_()
{
if (!opened_)
{
return;
}

if (record_types_ && dynamic_types_payload_ != nullptr)
{
// NOTE: This write should never fail since the minimum size accounts for it.
Expand All @@ -214,13 +236,20 @@ void McapWriter::close_current_file_nts_()
size_tracker_.reset(file_tracker_->get_current_filename());

writer_.close();
opened_ = false;

file_tracker_->close_file();
}

template <>
void McapWriter::write_nts_(
const mcap::Attachment& attachment)
{
if (!opened_)
{
return;
}

logInfo(DDSRECORDER_MCAP_WRITER,
"MCAP_WRITE | Writing attachment: " << attachment.name << " (" << utils::from_bytes(attachment.dataSize) <<
").");
Expand All @@ -243,6 +272,11 @@ template <>
void McapWriter::write_nts_(
const mcap::Channel& channel)
{
if (!opened_)
{
return;
}

logInfo(DDSRECORDER_MCAP_WRITER,
"MCAP_WRITE | Writing channel " << channel.topic << ".");

Expand All @@ -264,10 +298,8 @@ template <>
void McapWriter::write_nts_(
const McapMessage& msg)
{
if (!enabled_)
if (!opened_ || !enabled_)
{
logWarning(DDSRECORDER_MCAP_WRITER,
"MCAP_WRITE | Attempting to write a message in a disabled writer.");
return;
}

Expand All @@ -291,6 +323,11 @@ template <>
void McapWriter::write_nts_(
const mcap::Metadata& metadata)
{
if (!opened_)
{
return;
}

logInfo(DDSRECORDER_MCAP_WRITER,
"MCAP_WRITE | Writing metadata: " << metadata.name << ".");

Expand All @@ -312,6 +349,11 @@ template <>
void McapWriter::write_nts_(
const mcap::Schema& schema)
{
if (!opened_)
{
return;
}

logInfo(DDSRECORDER_MCAP_WRITER,
"MCAP_WRITE | Writing schema: " << schema.name << ".");

Expand All @@ -327,6 +369,11 @@ void McapWriter::write_nts_(

void McapWriter::write_attachment_nts_()
{
if (!opened_)
{
return;
}

mcap::Attachment attachment;

// Write down the attachment with the dynamic types
Expand All @@ -342,7 +389,7 @@ void McapWriter::write_attachment_nts_()

void McapWriter::write_channels_nts_()
{
if (channels_.empty())
if (!opened_ || channels_.empty())
{
return;
}
Expand All @@ -359,6 +406,11 @@ void McapWriter::write_channels_nts_()

void McapWriter::write_metadata_nts_()
{
if (!opened_)
{
return;
}

mcap::Metadata metadata;

// Write down the metadata with the version
Expand All @@ -371,7 +423,7 @@ void McapWriter::write_metadata_nts_()

void McapWriter::write_schemas_nts_()
{
if (schemas_.empty())
if (!opened_ || schemas_.empty())
{
return;
}
Expand Down
Loading