When tail input plugin enable Threaded, simultaneous generation of multiple files can lead to offset update errors. · Issue #9924 · fluent/fluent-bit · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
fluent-bit version: The latest version still has this issue.
plugin: tail input plugin
If Threaded is set to true, when create multiple files at the same time, the offset maybe update incorrectly.
To Reproduce
fluent-bit.conf
[SERVICE]
Flush 1
Log_Level info
Daemon off
[INPUT]
Name tail
Tag a
Threaded true
Path /usr/local/logs/*.a.log
DB /var/log/flb_kube.db
DB.Sync Off
[INPUT]
Name tail
Tag b
Threaded true
Path /usr/local/logs/*.b.log
DB /var/log/flb_kube.db
DB.Sync Off
[OUTPUT]
NAME null
Match *
main points:
Threaded is true.
two tail input plugin.
same db file.
reproduce steps:
execute ./fluent-bit -c fluent-bit.conf to start fluent-bit.
execute touch 1.a.log 1.b.log to create two files at the same time.
write something to the two files.
query the records in sqlite db, the offset of one file will always 0.
Expected behavior
The file offset should update correctly when the tail input plugin is running in threading mode.
Additional context
This issue may be caused by multi-threaded manipulation of the database when a new file is scanned, specifically within the method db_file_insert(). When a new file is scanned, this method performs two operations:
Inserts a new record into the SQLite database.
Retrieves the latest ID for subsequent update operations.
There is a time interval between these two operations, which may cause issues in multi-threaded scenarios. . For example:
A record representing file 1.a.log is inserted into the sqlite db, making the latest id in the db is 1.
A record representing file 1.b.log is inserted into the sqlite db, making the latest id in the db is 2.
When retrieving the latest id for 1.a.log, it incorrectly gets 2 instead of 1.
When retrieving the latest id for 1.b.log, it correctly gets 2.
To verify this guess, I added logging to the code and tested it:
add flb_plg_error(ctx->ins, "db instance address=%lu", ctx->db); to confirm that it is two different db instances in different input thread.
add sleep(10); between insert and get latest id operation to exaggerate this problem.
add flb_plg_error(ctx->ins, "file %s last id=%d", file->name, last_id); to print the file name and latest id.
Then I got:
logs:
[2025/02/06 08:10:55] [error] [input:tail:tail.0] db instance address=139646029844640
[2025/02/06 08:10:55] [error] [input:tail:tail.1] db instance address=139646096953504
[2025/02/06 08:11:05] [error] [input:tail:tail.0] file /usr/local/logs/1.a.log last id=2
[2025/02/06 08:11:05] [error] [input:tail:tail.1] file /usr/local/logs/1.b.log last id=2
The db id of the file 1.a.log does not match its actual id. No matter which file logs are written to, it always updates the offset of file 1.b.log, and it's probably wrong.
The text was updated successfully, but these errors were encountered:
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the exempt-stale label.
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
Describe the bug
fluent-bit version: The latest version still has this issue.
plugin: tail input plugin
If
Threaded
is set to true, when create multiple files at the same time, the offset maybe update incorrectly.To Reproduce
fluent-bit.conf
main points:
Threaded
is true.reproduce steps:
./fluent-bit -c fluent-bit.conf
to start fluent-bit.touch 1.a.log 1.b.log
to create two files at the same time.Expected behavior
The file offset should update correctly when the tail input plugin is running in threading mode.
Additional context
This issue may be caused by multi-threaded manipulation of the database when a new file is scanned, specifically within the method db_file_insert(). When a new file is scanned, this method performs two operations:
There is a time interval between these two operations, which may cause issues in multi-threaded scenarios. . For example:
To verify this guess, I added logging to the code and tested it:
flb_plg_error(ctx->ins, "db instance address=%lu", ctx->db);
to confirm that it is two different db instances in different input thread.sleep(10);
between insert and get latest id operation to exaggerate this problem.flb_plg_error(ctx->ins, "file %s last id=%d", file->name, last_id);
to print the file name and latest id.Then I got:
logs:
sqlite db records:
The db id of the file 1.a.log does not match its actual id. No matter which file logs are written to, it always updates the offset of file 1.b.log, and it's probably wrong.
The text was updated successfully, but these errors were encountered: