|
17 | 17 | * limitations under the License. |
18 | 18 | */ |
19 | 19 |
|
| 20 | +#include <math.h> |
20 | 21 | #include <stdio.h> |
21 | 22 | #include <stdlib.h> |
22 | 23 |
|
@@ -206,29 +207,22 @@ static inline int handle_input_event(flb_pipefd_t fd, uint64_t ts, |
206 | 207 | return 0; |
207 | 208 | } |
208 | 209 |
|
209 | | -static inline int handle_output_event(flb_pipefd_t fd, uint64_t ts, |
210 | | - struct flb_config *config) |
| 210 | +static inline int handle_output_event(uint64_t ts, |
| 211 | + struct flb_config *config, |
| 212 | + uint64_t val) |
211 | 213 | { |
212 | 214 | int ret; |
213 | | - int bytes; |
214 | 215 | int task_id; |
215 | 216 | int out_id; |
216 | 217 | int retries; |
217 | 218 | int retry_seconds; |
218 | 219 | uint32_t type; |
219 | 220 | uint32_t key; |
220 | | - uint64_t val; |
221 | 221 | char *name; |
222 | 222 | struct flb_task *task; |
223 | 223 | struct flb_task_retry *retry; |
224 | 224 | struct flb_output_instance *ins; |
225 | 225 |
|
226 | | - bytes = flb_pipe_r(fd, &val, sizeof(val)); |
227 | | - if (bytes == -1) { |
228 | | - flb_errno(); |
229 | | - return -1; |
230 | | - } |
231 | | - |
232 | 226 | /* Get type and key */ |
233 | 227 | type = FLB_BITS_U64_HIGH(val); |
234 | 228 | key = FLB_BITS_U64_LOW(val); |
@@ -441,6 +435,52 @@ static inline int handle_output_event(flb_pipefd_t fd, uint64_t ts, |
441 | 435 | return 0; |
442 | 436 | } |
443 | 437 |
|
| 438 | +static inline int handle_output_events(flb_pipefd_t fd, |
| 439 | + struct flb_config *config) |
| 440 | +{ |
| 441 | + uint64_t values[FLB_ENGINE_OUTPUT_EVENT_BATCH_SIZE]; |
| 442 | + int result; |
| 443 | + int bytes; |
| 444 | + size_t limit; |
| 445 | + size_t index; |
| 446 | + uint64_t ts; |
| 447 | + |
| 448 | + memset(&values, 0, sizeof(values)); |
| 449 | + |
| 450 | + bytes = flb_pipe_r(fd, &values, sizeof(values)); |
| 451 | + |
| 452 | + if (bytes == -1) { |
| 453 | + flb_errno(); |
| 454 | + return -1; |
| 455 | + } |
| 456 | + |
| 457 | + limit = floor(bytes / sizeof(uint64_t)); |
| 458 | + |
| 459 | + ts = cfl_time_now(); |
| 460 | + |
| 461 | + for (index = 0 ; |
| 462 | + index < limit && |
| 463 | + index < (sizeof(values) / sizeof(values[0])) ; |
| 464 | + index++) { |
| 465 | + if (values[index] == 0) { |
| 466 | + break; |
| 467 | + } |
| 468 | + |
| 469 | + result = handle_output_event(ts, config, values[index]); |
| 470 | + } |
| 471 | + |
| 472 | + /* This is wrong, in one hand, if handle_output_event_ fails we should |
| 473 | + * stop, on the other, we have already consumed the signals from the pipe |
| 474 | + * so we have to do whatever we can with them. |
| 475 | + * |
| 476 | + * And a side effect is that since we have N results but we are not aborting |
| 477 | + * as soon as we get an error there could be N results to this function which |
| 478 | + * not only are we not ready to handle but is not even checked at the moment. |
| 479 | + */ |
| 480 | + |
| 481 | + return result; |
| 482 | +} |
| 483 | + |
444 | 484 | static inline int flb_engine_manager(flb_pipefd_t fd, struct flb_config *config) |
445 | 485 | { |
446 | 486 | int bytes; |
@@ -982,13 +1022,11 @@ int flb_engine_start(struct flb_config *config) |
982 | 1022 | } |
983 | 1023 | } |
984 | 1024 | else if (event->type == FLB_ENGINE_EV_OUTPUT) { |
985 | | - ts = cfl_time_now(); |
986 | | - |
987 | 1025 | /* |
988 | 1026 | * Event originated by an output plugin. likely a Task return |
989 | 1027 | * status. |
990 | 1028 | */ |
991 | | - handle_output_event(event->fd, ts, config); |
| 1029 | + handle_output_events(event->fd, config); |
992 | 1030 | } |
993 | 1031 | else if (event->type == FLB_ENGINE_EV_INPUT) { |
994 | 1032 | ts = cfl_time_now(); |
@@ -1042,10 +1080,10 @@ int flb_engine_shutdown(struct flb_config *config) |
1042 | 1080 | flb_router_exit(config); |
1043 | 1081 |
|
1044 | 1082 | /* cleanup plugins */ |
1045 | | - flb_input_exit_all(config); |
1046 | 1083 | flb_filter_exit(config); |
1047 | 1084 | flb_output_exit(config); |
1048 | 1085 | flb_custom_exit(config); |
| 1086 | + flb_input_exit_all(config); |
1049 | 1087 |
|
1050 | 1088 | /* Destroy the storage context */ |
1051 | 1089 | flb_storage_destroy(config); |
|
0 commit comments