Skip to content

Commit

Permalink
in_tail: create stream_id by file inode(#4190)
Browse files Browse the repository at this point in the history
If stream_id is created by filename, rotated file id will be same.
It causes releasing new multiline instance after file rotation.

Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Oct 26, 2021
1 parent 5eb5658 commit 4725fb2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions plugins/in_tail/tail_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
size_t tag_len;
struct flb_tail_file *file;
struct stat lst;
flb_sds_t inode_str;

if (!S_ISREG(st->st_mode)) {
return -1;
Expand Down Expand Up @@ -882,18 +883,30 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,

/* Multiline core mode */
if (ctx->ml_ctx) {
/*
* Create inode str to get stream_id.
*
* If stream_id is created by filename,
* it will be same after file rotation and it causes invalid destruction.
* https://github.com/fluent/fluent-bit/issues/4190
*
*/
inode_str = flb_sds_create_size(64);
flb_sds_printf(&inode_str, "%"PRIu64, file->inode);
/* Create a stream for this file */
ret = flb_ml_stream_create(ctx->ml_ctx,
file->name, file->name_len,
inode_str, flb_sds_len(inode_str),
ml_flush_callback, file,
&stream_id);
if (ret != 0) {
flb_plg_error(ctx->ins,
"could not create multiline stream for file: %s",
file->name);
inode_str);
flb_sds_destroy(inode_str);
goto error;
}
file->ml_stream_id = stream_id;
flb_sds_destroy(inode_str);
}

/* Local buffer */
Expand Down

0 comments on commit 4725fb2

Please sign in to comment.