Skip to content

fix: seat offset spanvec correctly after truncation - #644

Open
jakedipity wants to merge 1 commit into
masterfrom
jakedipity/LOG-21703
Open

fix: seat offset spanvec correctly after truncation#644
jakedipity wants to merge 1 commit into
masterfrom
jakedipity/LOG-21703

Conversation

@jakedipity

@jakedipity jakedipity commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

When truncating large files, the offsets SpanVec was incorrectly seeking to the beginning of the file instead of the new offset (the end of the file). Adds a new method to truncate SpanVec and utilize it during file truncation.

Additionally utils/stress_test since it's not used, the previous maintainer is not working on it anymore, and it's breaking our CI/CD tooling.

Ref: LOG-21703

@jakedipity
jakedipity force-pushed the jakedipity/LOG-21703 branch from ae1f319 to 0569f45 Compare April 30, 2025 17:10
@jakedipity
jakedipity force-pushed the jakedipity/LOG-21703 branch 3 times, most recently from 5b4977a to ef026df Compare May 13, 2025 20:10
Comment thread common/fs/src/cache/tailed_file.rs Outdated
let offset = inner.offset;

// truncate offsets to new file length
inner.offsets.truncate(offset);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, we may need to gate this behind Lookback::None, right? Otherwise the common case of truncate, write line, agent gets inotify, agent reads file would miss the line written immediately after the truncation as we've no way to determine the length the file was actually truncated to

@jakedipity jakedipity May 27, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not perfect, but it's significantly better than what it's currently doing now, i.e partial truncations are causing all lines to be re-ingested from the file start which is in turn causing odd behavior (possibly corrupted logs).

I don't believe there's an ideal solution here due to limitations with how inotify works and the inherent delay between events and state updates.

We could potentially stat the size of a file as soon as an event is registered and use that metadata in our decision making process - this would help minimize these issues but not remove them completely.

Alternatively we could tie the truncation logic to follow the configured lookback logic or add a new config option for different truncation strategies. Right now the truncation logic always uses a strategy which is effectively the same as lookback:smallfiles

@c-nixon c-nixon Jun 2, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right now the truncation logic always uses a strategy which is effectively the same as lookback:smallfiles

Yeh, that's always been a weird shortcut. I think if we're going to make this change we need to gate it behind a new piece of config, I don't know if it should be the default or not, but just enabling it will result in the standard copy-truncate losing any lines that skip it past the 8192 bytes heuristic. At least if we make it configurable/opt in then users can be aware of the trade off

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@c-nixon I've made the truncation strategy configurable and is set up similar to lookback. I've kept the default setting of smallfiles to be consistent with previous intended behavior, but it kind of sounded like you wanted to default to start - I still need to implement full testing of each truncate strategy, but wanted to get your thoughts on what's here now!

@jakedipity
jakedipity force-pushed the jakedipity/LOG-21703 branch 2 times, most recently from 4275835 to 71eb57b Compare May 27, 2025 16:55
@jakedipity
jakedipity force-pushed the jakedipity/LOG-21703 branch 4 times, most recently from 22572af to b0973f1 Compare June 11, 2025 22:30
When truncating large files, the offsets SpanVec was incorrectly seeking
to the beginning of the file instead of the new offset (the end of the
file). Adds a new method to truncate `SpanVec` and utilize it during
file truncation.

Additionally `utils/stress_test` since it's not used, the previous
maintainer is not working on it anymore, and it's breaking our CI/CD
tooling.

Ref: LOG-21703
Signed-off-by: Jacob Hull <jacob@planethull.com>
@jakedipity
jakedipity force-pushed the jakedipity/LOG-21703 branch from b0973f1 to b35ae8c Compare June 11, 2025 22:55
@c-nixon
c-nixon self-requested a review June 13, 2025 08:58
Comment thread api/src/tailer/mod.rs
.expect("Failed to assign tailer process to job.");

let tailer_stdout = tailer_process.stdout.take().ok_or_else(|| {
#[allow(clippy::io_other_error)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

World's most minor nit: We can update the call to the new std::io::Error::other(e) which rather than std::io::Error::new which will not trigger the lint

@c-nixon c-nixon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeh, this is looking great so far, maybe it's worth splitting the removal of the stress test into a separate PR? The truncation logic is all good, pity we can't just newtype Lookback, but we'd still end up having to reimplement it's Display etc, so no real benefit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants