Skip to content

Conversation

@stelfrag
Copy link
Collaborator

@stelfrag stelfrag commented Dec 19, 2025

Summary
  • Refactor metadata label storage with unified callback and prepared statements
  • Replace SQL string concatenation with prepared statements for label storage.
  • Simplify host and chart label update logic by removing work buffer usage.

Summary by cubic

Refactors label metadata storage to use prepared statements with batched inserts and a single code path for host and chart labels. Collects labels under spinlock and writes them after release to avoid DB I/O while locked.

  • Refactors
    • Added store_labels + collect_label_callback with batched multi-row INSERTs via prepared statements.
    • Switched to UPSERTs (ON CONFLICT) for host_label and chart_label writes.
    • Simplified API: store_host_info_and_metadata(host); removed worker-level work_buffer plumbing and reuse an internal buffer.
    • Chart labels now update via store_labels; host labels are deleted then re-stored to handle removals.
    • Two-phase label storage with batching to reduce SQLite I/O.

Written for commit c2fac18. Summary will update on new commits.

@stelfrag
Copy link
Collaborator Author

@cubic-dev-ai review PR

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Jan 21, 2026

@cubic-dev-ai review PR

@stelfrag I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the metadata label storage mechanism for both host and chart labels by replacing SQL string concatenation with prepared statements and implementing a two-phase approach to avoid database I/O while holding spinlocks.

Changes:

  • Introduced store_labels() function with prepared statements to handle both host and chart labels via a unified code path
  • Replaced SQL string building with UPSERT statements (INSERT ... ON CONFLICT) for atomic label updates
  • Removed work_buffer parameter from multiple functions, simplifying the API

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/database/sqlite/sqlite_metadata.h Updated store_host_info_and_metadata() signature to remove work_buffer parameter
src/database/sqlite/sqlite_metadata.c Added new store_labels() function with two-phase label collection; refactored label storage to use prepared statements; removed work buffer usage throughout
src/database/rrdhost.c Updated call to store_host_info_and_metadata() to remove buffer creation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…atements

* Replace SQL string concatenation with prepared statements for label storage.
* Simplify host and chart label update logic by removing work buffer usage.
* Introduce `store_labels` function for unified label handling.
* Improve code readability and maintainability by reducing redundant callback implementations.
- Introduced a reusable buffer for building SQL statements.
- Replaced per-label operations with multi-row inserts using prepared statements.
- Enhanced scalability by adding a batch size definition.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant