Skip to content

fix: Automatically compact entity_store.jsonl after a large number of repeat topics#4173

Open
jarhodes314 wants to merge 5 commits into
thin-edge:mainfrom
jarhodes314:fix/entity-store-republish-growth
Open

fix: Automatically compact entity_store.jsonl after a large number of repeat topics#4173
jarhodes314 wants to merge 5 commits into
thin-edge:mainfrom
jarhodes314:fix/entity-store-republish-growth

Conversation

@jarhodes314
Copy link
Copy Markdown
Contributor

Proposed changes

Adds a compaction mechanism to the entity store file. This will trigger after we have written a significant number (currently 100) messages to topics that already exist in the file, preventing unbounded growth.

It also refactors the existing test for the readers/writers into well-defined unit tests.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Signed-off-by: James Rhodes <jarhodes314@gmail.com>
…ated topics

Signed-off-by: James Rhodes <jarhodes314@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 95.34161% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/core/tedge_api/src/store/message_log.rs 95.34% 0 Missing and 15 partials ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jarhodes314 jarhodes314 added the theme:entity_store Entity store related functionality label May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
916 0 4 916 100 2h39m6.550187s

@jarhodes314 jarhodes314 requested a review from a team as a code owner May 13, 2026 17:02
@jarhodes314 jarhodes314 temporarily deployed to Test Pull Request May 13, 2026 17:02 — with GitHub Actions Inactive
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
@jarhodes314 jarhodes314 force-pushed the fix/entity-store-republish-growth branch from 5ec42ba to d2d0cd7 Compare May 13, 2026 17:12
@jarhodes314 jarhodes314 temporarily deployed to Test Pull Request May 13, 2026 17:12 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

The code looks fine. Happy to approve once cleared message handling is also fixed. Also as an additional enhancement, how about doing an unconditional compaction on startup?

Comment thread crates/core/tedge_api/src/store/message_log.rs Outdated
Comment thread crates/core/tedge_api/src/store/message_log.rs Outdated
Comment thread crates/core/tedge_api/src/store/message_log.rs Outdated
Comment thread crates/core/tedge_api/src/store/message_log.rs Outdated
@jarhodes314 jarhodes314 force-pushed the fix/entity-store-republish-growth branch from 4d19be1 to f4becd5 Compare May 14, 2026 16:19
OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
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.

The behaviour of this is slightly altered. Previously, truncate mode meant we opened the file with truncate(true), then closed it, then opened it again (via MessageLogWriter::new). Now we just open it the one time with truncation. I believe this won't cause any dramatic behaviour changes as we didn't do anything to make the truncation fsync-durable, and it seemed from reading the code that we mostly did it for easy code reuse between the truncate and non-truncate paths.

This has the side-effect of us also failing if we fail to open the file with truncation (previously we ignored the result of opening the truncated file). I don't believe this will cause any major issues - if we can't open a file to truncate, we probably can't open it in append mode. There's a possible edge case where file system attributes might mean we can only append to a file, but in this case I think we're better off failing rather than pretending everything's working?

Comment thread crates/core/tedge_api/src/store/message_log.rs Outdated
@jarhodes314 jarhodes314 temporarily deployed to Test Pull Request May 15, 2026 09:42 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

LGTM

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

Labels

theme:entity_store Entity store related functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants