@@ -76,14 +76,34 @@ int flb_fstore_file_meta_set(struct flb_fstore *fs,
7676 void * meta , size_t size )
7777{
7878 int ret ;
79+ int set_down = FLB_FALSE ;
80+
81+ /* Check if the chunk is up */
82+ if (cio_chunk_is_up (fsf -> chunk ) == CIO_FALSE ) {
83+ ret = cio_chunk_up_force (fsf -> chunk );
84+ if (ret != CIO_OK ) {
85+ flb_error ("[fstore] error loading up file chunk" );
86+ return -1 ;
87+ }
88+ set_down = FLB_TRUE ;
89+ }
7990
8091 ret = cio_meta_write (fsf -> chunk , meta , size );
8192 if (ret == -1 ) {
8293 flb_error ("[fstore] could not write metadata to file: %s:%s" ,
8394 fsf -> stream -> name , fsf -> chunk -> name );
95+
96+ if (set_down == FLB_TRUE ) {
97+ cio_chunk_down (fsf -> chunk );
98+ }
99+
84100 return -1 ;
85101 }
86102
103+ if (set_down == FLB_TRUE ) {
104+ cio_chunk_down (fsf -> chunk );
105+ }
106+
87107 return meta_set (fsf , meta , size );
88108}
89109
@@ -254,13 +274,33 @@ int flb_fstore_file_content_copy(struct flb_fstore *fs,
254274int flb_fstore_file_append (struct flb_fstore_file * fsf , void * data , size_t size )
255275{
256276 int ret ;
277+ int set_down = FLB_FALSE ;
278+
279+ /* Check if the chunk is up */
280+ if (cio_chunk_is_up (fsf -> chunk ) == CIO_FALSE ) {
281+ ret = cio_chunk_up_force (fsf -> chunk );
282+ if (ret != CIO_OK ) {
283+ flb_error ("[fstore] error loading up file chunk" );
284+ return -1 ;
285+ }
286+ set_down = FLB_TRUE ;
287+ }
257288
258289 ret = cio_chunk_write (fsf -> chunk , data , size );
259290 if (ret != CIO_OK ) {
260291 flb_error ("[fstore] could not write data to file %s" , fsf -> name );
292+
293+ if (set_down == FLB_TRUE ) {
294+ cio_chunk_down (fsf -> chunk );
295+ }
296+
261297 return -1 ;
262298 }
263299
300+ if (set_down == FLB_TRUE ) {
301+ cio_chunk_down (fsf -> chunk );
302+ }
303+
264304 return 0 ;
265305}
266306
0 commit comments