Skip to content

Commit ae0c77c

Browse files
committed
input_chunk: set maximum input chunk size with configuration parameter
Added new function 'flb_input_chunk_get_max_size' that retrieves value of the 'storage.max_chunk_size' parameter from the fluent-bit configuration or sets default value of FLB_INPUT_CHUNK_FS_MAX_SIZE (when user have not set parameter or there is any problem in parsing). Function is exposed to other modules and can be used anywhere to get 'storage.max_chunk_size' parameter. Light optimization: validation of available space in buffer now uses integer division instead of floating point multiplication (should be faster). Signed-off-by: Castor Sky <csky57@gmail.com>
1 parent a5a3850 commit ae0c77c

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

include/fluent-bit/flb_input_chunk.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ struct cio_chunk;
4040
* Defines a maximum size for a Chunk in the file system: note that despite
4141
* this is considered a limit, a Chunk size might get greater than this.
4242
*/
43-
#define FLB_INPUT_CHUNK_FS_MAX_SIZE 2048000 /* 2MB */
43+
#define FLB_INPUT_CHUNK_FS_MAX_SIZE (size_t) 2048000 /* 2MB */
44+
45+
size_t flb_input_chunk_get_max_size(struct flb_config *config);
4446

4547
/* Number of bytes reserved for Metadata Header on Chunks */
4648
#define FLB_INPUT_CHUNK_META_HEADER 4

src/flb_input_chunk.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <fluent-bit/flb_metrics.h>
3838
#include <fluent-bit/stream_processor/flb_sp.h>
3939
#include <fluent-bit/flb_ring_buffer.h>
40+
#include <fluent-bit/flb_utils.h>
4041
#include <chunkio/chunkio.h>
4142
#include <monkey/mk_core.h>
4243
#include <string.h>
@@ -2632,6 +2633,7 @@ static int input_chunk_append_raw(struct flb_input_instance *in,
26322633
size_t filtered_data_size;
26332634
void *final_data_buffer;
26342635
size_t final_data_size;
2636+
size_t flb_input_chunk_max_size;
26352637

26362638
/* memory ring-buffer checker */
26372639
if (in->storage_type == FLB_STORAGE_MEMRB) {
@@ -2828,8 +2830,9 @@ static int input_chunk_append_raw(struct flb_input_instance *in,
28282830
real_diff = 0;
28292831
}
28302832

2831-
/* Lock buffers where size > 2MB */
2832-
if (content_size > FLB_INPUT_CHUNK_FS_MAX_SIZE) {
2833+
flb_input_chunk_max_size = flb_input_chunk_get_max_size(in->config);
2834+
2835+
if (content_size > flb_input_chunk_max_size) {
28332836
cio_chunk_lock(ic->chunk);
28342837
}
28352838

@@ -2896,8 +2899,8 @@ static int input_chunk_append_raw(struct flb_input_instance *in,
28962899
content_size = cio_chunk_get_content_size(ic->chunk);
28972900

28982901
/* Do we have less than 1% available ? */
2899-
min = (FLB_INPUT_CHUNK_FS_MAX_SIZE * 0.01);
2900-
if (FLB_INPUT_CHUNK_FS_MAX_SIZE - content_size < min) {
2902+
min = (flb_input_chunk_max_size / 100);
2903+
if (flb_input_chunk_max_size - content_size < min) {
29012904
cio_chunk_down(ic->chunk);
29022905
}
29032906
}
@@ -3286,3 +3289,24 @@ void flb_input_chunk_update_output_instances(struct flb_input_chunk *ic,
32863289
}
32873290
}
32883291
}
3292+
3293+
/*
3294+
* Get value of 'storage.max_chunk_size' from configuration or set default value.
3295+
*/
3296+
size_t flb_input_chunk_get_max_size(struct flb_config *config) {
3297+
int64_t config_input_chunk_max_size;
3298+
3299+
if (config != NULL) {
3300+
config_input_chunk_max_size = flb_utils_size_to_bytes(config->storage_max_chunk_size);
3301+
if (config_input_chunk_max_size > 0) {
3302+
flb_debug("[input chunk] using maximum chunk size: %" PRId64, config_input_chunk_max_size);
3303+
return (size_t) config_input_chunk_max_size;
3304+
} else if (config_input_chunk_max_size == 0) {
3305+
flb_debug("[input chunk] maximum chunk size was not set, using the default value: %zu", FLB_INPUT_CHUNK_FS_MAX_SIZE);
3306+
} else {
3307+
flb_debug("[input chunk] could not parse maximum chunk size, using the default value: %zu", FLB_INPUT_CHUNK_FS_MAX_SIZE);
3308+
}
3309+
}
3310+
3311+
return FLB_INPUT_CHUNK_FS_MAX_SIZE;
3312+
}

0 commit comments

Comments
 (0)