Skip to content

feat(datastore): add batch metadata API and fix platform-specific errno#4871

Open
SURUJ404 wants to merge 2 commits into
bottlerocket-os:developfrom
SURUJ404:develop
Open

feat(datastore): add batch metadata API and fix platform-specific errno#4871
SURUJ404 wants to merge 2 commits into
bottlerocket-os:developfrom
SURUJ404:develop

Conversation

@SURUJ404

Copy link
Copy Markdown
  • Batch metadata writes — Added set_metadata_batch() to the DataStore trait. The migration helper previously wrote metadata one entry at a time in a nested loop, noted with // Set metadata in a loop (currently no batch API). Now it builds a batch map and calls the new method, keeping the per-entry logic in a single place. Future backends can override this for true batch transactions.
  1. Cross-platform directory check — Replaced e.raw_os_error() != Some(39) (Linux's ENOTEMPTY, value 39) with e.kind() != io::ErrorKind::DirectoryNotEmpty, stable since Rust 1.71. Eliminates a magic number and works on all platforms.
  2. Migration helper cleanup — Consolidated metadata key construction and serialization into the batch map, then delegates to set_metadata_batch. Same behavior, clearer code.
  • Add set_metadata_batch() to DataStore trait with default implementation
  • Use the new batch API in migration-helpers datastore_helper
  • Replace raw os error 39 with io::ErrorKind::DirectoryNotEmpty

Issue number:

Closes #

Description of changes:

Testing done:

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

- Add set_metadata_batch() to DataStore trait with default implementation
- Use the new batch API in migration-helpers datastore_helper
- Replace raw os error 39 with io::ErrorKind::DirectoryNotEmpty
@SURUJ404

Copy link
Copy Markdown
Author

These changes improve the datastore API's extensibility and code correctness. Adding set_metadata_batch to the DataStore trait provides a proper extension point — future backends (e.g. a database-backed datastore) can batch metadata writes into a single atomic operation, while existing filesystem and in-memory backends continue to work via the default implementation. This also cleans up the migration helper, removing the old "no batch API" workaround and keeping the looping logic in one canonical place. Replacing the hardcoded raw OS error 39 with io::ErrorKind::DirectoryNotEmpty eliminates a Linux-specific magic number that would silently misbehave on other platforms, making the codebase more portable and maintainable.

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.

1 participant