Skip to content

Commit 3a4879c

Browse files
committed
input_chunk: on destroy chunk, make sure is up
Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
1 parent 6d94c51 commit 3a4879c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/flb_input_chunk.c

+24-4
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ int flb_input_chunk_has_overlimit_routes(struct flb_input_chunk *ic,
287287
continue;
288288
}
289289

290-
flb_debug("[input chunk] chunk %s required %ld bytes and %ld bytes left in plugin %s",
290+
flb_debug("[input chunk] chunk %s required %ld bytes and %ld bytes left "
291+
"in plugin %s",
291292
flb_input_chunk_get_name(ic), chunk_size,
292293
o_ins->total_limit_size - o_ins->fs_chunks_size,
293294
o_ins->name);
@@ -477,8 +478,9 @@ struct flb_input_chunk *flb_input_chunk_create(struct flb_input_instance *in,
477478
int flb_input_chunk_destroy(struct flb_input_chunk *ic, int del)
478479
{
479480
int tag_len;
481+
int ret;
480482
ssize_t bytes;
481-
const char *tag_buf;
483+
const char *tag_buf = NULL;
482484
struct mk_list *head;
483485
struct flb_output_instance *o_ins;
484486

@@ -499,10 +501,28 @@ int flb_input_chunk_destroy(struct flb_input_chunk *ic, int del)
499501
}
500502
}
501503

504+
/*
505+
* When a chunk is going to be destroyed, this can be in a down state,
506+
* since the next step is to retrieve the Tag we need to have the
507+
* content up.
508+
*/
509+
ret = flb_input_chunk_is_up(ic);
510+
if (ret == FLB_FALSE) {
511+
ret = cio_chunk_up_force(ic->chunk);
512+
if (ret == -1) {
513+
flb_error("[input chunk] cannot load chunk: %s",
514+
flb_input_chunk_get_name(ic));
515+
}
516+
}
517+
502518
/* Retrieve Tag */
503-
flb_input_chunk_get_tag(ic, &tag_buf, &tag_len);
519+
ret = flb_input_chunk_get_tag(ic, &tag_buf, &tag_len);
520+
if (ret == -1) {
521+
flb_trace("[input chunk] could not retrieve chunk tag: %s",
522+
flb_input_chunk_get_name(ic));
523+
}
504524

505-
if (del == CIO_TRUE) {
525+
if (del == CIO_TRUE && tag_buf) {
506526
/*
507527
* "TRY" to delete any reference to this chunk ('ic') from the hash
508528
* table. Note that maybe the value is not longer available in the

0 commit comments

Comments
 (0)