Skip to content

Conversation

@cosmo0920
Copy link
Contributor

@cosmo0920 cosmo0920 commented Aug 26, 2025

This should be needed for compilation with the recent version of gcc.
gcc-14 or later checks that kind of glitches and make an error.

This is also occurred on my dev box's archlinux WSL2 environment.

[ 56%] Building C object src/CMakeFiles/fluent-bit-static.dir/config_format/flb_config_format.c.o
/tmp/fluent-bit/src/flb_blob_db.c: In function 'flb_blob_db_file_part_insert':
/tmp/fluent-bit/src/flb_blob_db.c:912:52: error: passing argument 1 of 'sqlite3_last_insert_rowid' from incompatible pointer type [-Wincompatible-pointer-types]
912 | *out_id = sqlite3_last_insert_rowid(context->db);
| ~~~~~~~^~~~
| |
| __internal_flb_sqldb * {aka struct flb_sqldb *}
In file included from /tmp/fluent-bit/include/fluent-bit/flb_sqldb.h:23,
from /tmp/fluent-bit/src/flb_blob_db.c:22:
/tmp/fluent-bit/lib/sqlite-amalgamation-3450200/sqlite3.h:2588:52: note: expected 'sqlite3 *' but argument is of type '__internal_flb_sqldb *' {aka 'struct flb_sqldb '}
2588 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3
);
| ^~~~~~~~
[ 56%] Building C object src/CMakeFiles/fluent-bit-static.dir/config_format/flb_cf_fluentbit.c.o
make[2]: *** [src/CMakeFiles/fluent-bit-static.dir/build.make:1325: src/CMakeFiles/fluent-bit-static.dir/flb_blob_db.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:12446: src/CMakeFiles/fluent-bit-static.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

This issue was initially reported in #10728 (comment).


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when saving data by ensuring the correct record ID is returned after inserts, reducing rare cases of mismatched IDs and subsequent operation failures.
    • Enhances stability around database write operations without altering existing behavior or workflows.
    • No changes to public interfaces; upgrades are backward compatible.

@cosmo0920 cosmo0920 requested a review from edsiper as a code owner August 26, 2025 10:55
@cosmo0920 cosmo0920 changed the title blob: Plug a sdldb encapsulation leak blob: Plug a sqldb encapsulation leak Aug 26, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 26, 2025

Walkthrough

flb_blob_db_file_part_insert now retrieves the inserted row ID using flb_sqldb_last_id(context->db) instead of sqlite3_last_insert_rowid(context->db). Error handling, cleanup, and output initialization remain unchanged.

Changes

Cohort / File(s) Summary
Blob DB insert ID retrieval
src/flb_blob_db.c
Replace sqlite3_last_insert_rowid(...) with flb_sqldb_last_id(...) to obtain the last inserted ID after a successful insert; no other logic or signatures changed.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant BlobDB as flb_blob_db_file_part_insert
  participant SQL as SQLite DB

  Caller->>BlobDB: insert(file_part)
  BlobDB->>SQL: EXECUTE INSERT
  alt success
    BlobDB->>SQL: flb_sqldb_last_id(db)
    SQL-->>BlobDB: last_id
    BlobDB-->>Caller: out_id = last_id
  else error
    BlobDB-->>Caller: out_id = -1 (error)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibbled the code with careful bite,
Swapped a call to fetch IDs right.
From sqlite whispers to sqldb’s tune,
The row’s new number hops in soon.
Thump-thump, my paws approve the stride—
A tiny hop for cleaner guide. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cosmo0920-plug-sdldb-encapsulation-leak-for-blob

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/flb_blob_db.c (1)

881-921: Minor: consider documenting/defending out_id contract

Current code assigns -1 on error and a valid rowid on success. Since you’re touching this function, consider briefly documenting that out_id must be non-NULL, or defensively initializing it to -1 at function entry when non-NULL. Not urgent; just helps avoid stale values if future early-returns are introduced.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between eb77790 and e2a94a9.

📒 Files selected for processing (1)
  • src/flb_blob_db.c (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/flb_blob_db.c (1)
src/flb_sqldb.c (1)
  • flb_sqldb_last_id (168-171)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (28)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: PR - fuzzing test
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
  • GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
🔇 Additional comments (1)
src/flb_blob_db.c (1)

912-912: No stray sqlite3_last_insert_rowid() calls found – change approved

The use of flb_sqldb_last_id(context->db) properly replaces direct sqlite3_last_insert_rowid() calls and aligns with the existing pattern (e.g., in flb_blob_db_file_insert). The wrapper is defined only once in src/flb_sqldb.c and no other direct calls remain in the project code. Locking is correctly held around the insert/last-id pair.

– Change is good to merge.

@edsiper edsiper merged commit dfcad24 into master Aug 26, 2025
67 checks passed
@edsiper edsiper deleted the cosmo0920-plug-sdldb-encapsulation-leak-for-blob branch August 26, 2025 13:08
@cosmo0920
Copy link
Contributor Author

flb_blob_db.c is not included in 4.0. So, we needn't backport to 4.0.

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.

3 participants