@@ -802,6 +802,17 @@ static struct cio_stream *get_or_create_rejected_stream(struct flb_config *ctx)
802802#endif
803803}
804804
805+ static inline int flb_storage_chunk_restore_state (struct cio_chunk * src , int was_up , int ret_val )
806+ {
807+ if (!was_up ) {
808+ if (cio_chunk_down (src ) != CIO_OK ) {
809+ flb_debug ("[storage] failed to bring chunk back down" );
810+ }
811+ }
812+
813+ return ret_val ;
814+ }
815+
805816int flb_storage_quarantine_chunk (struct flb_config * ctx ,
806817 struct cio_chunk * src ,
807818 const char * tag ,
@@ -846,37 +857,30 @@ int flb_storage_quarantine_chunk(struct flb_config *ctx,
846857
847858 if (cio_chunk_get_content_copy (src , & buf , & size ) != CIO_OK || size == 0 ) {
848859 flb_warn ("[storage] cannot read content for DLQ copy (size=%zu)" , size );
849- return -1 ;
860+ return flb_storage_chunk_restore_state ( src , was_up , -1 ) ;
850861 }
851862
852863 /* Create + write the DLQ copy */
853864 dst = cio_chunk_open (ctx -> cio , dlq , name , CIO_OPEN , size , & err );
854865 if (!dst ) {
855866 flb_warn ("[storage] DLQ open failed (err=%d)" , err );
856867 flb_free (buf );
857- return -1 ;
868+ return flb_storage_chunk_restore_state ( src , was_up , -1 ) ;
858869 }
859870 if (cio_chunk_write (dst , buf , size ) != CIO_OK ||
860871 cio_chunk_sync (dst ) != CIO_OK ) {
861872 flb_warn ("[storage] DLQ write/sync failed" );
862873 cio_chunk_close (dst , CIO_TRUE );
863874 flb_free (buf );
864- return -1 ;
875+ return flb_storage_chunk_restore_state ( src , was_up , -1 ) ;
865876 }
866877
867878 cio_chunk_close (dst , CIO_FALSE );
868879 flb_free (buf );
869880
870881 flb_info ("[storage] quarantined rejected chunk into DLQ stream (bytes=%zu)" , size );
871882
872- /* Restore original state if we brought the chunk up */
873- if (!was_up ) {
874- if (cio_chunk_down (src ) != CIO_OK ) {
875- flb_debug ("[storage] failed to bring chunk back down after DLQ copy" );
876- }
877- }
878-
879- return 0 ;
883+ return flb_storage_chunk_restore_state (src , was_up , 0 );
880884#else
881885 FLB_UNUSED (ctx );
882886 FLB_UNUSED (src );
0 commit comments