Skip to content

Commit 62df481

Browse files
committed
storage: Restore status of chunks for error paths
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 120c3aa commit 62df481

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/flb_storage.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -844,37 +844,41 @@ int flb_storage_quarantine_chunk(struct flb_config *ctx,
844844
"%s_%d_%s_%p.flb",
845845
safe_tag, status_code, safe_out, (void *) src);
846846

847+
/* Helper to restore state if we changed it */
848+
#define CHUNK_RESTORE_AND_RETURN(ret_val) do { \
849+
if (!was_up && cio_chunk_down(src) != CIO_OK) { \
850+
flb_debug("[storage] failed to bring chunk back down"); \
851+
} \
852+
return (ret_val); \
853+
} while(0)
854+
847855
if (cio_chunk_get_content_copy(src, &buf, &size) != CIO_OK || size == 0) {
848856
flb_warn("[storage] cannot read content for DLQ copy (size=%zu)", size);
849-
return -1;
857+
CHUNK_RESTORE_AND_RETURN(-1);
850858
}
851859

852860
/* Create + write the DLQ copy */
853861
dst = cio_chunk_open(ctx->cio, dlq, name, CIO_OPEN, size, &err);
854862
if (!dst) {
855863
flb_warn("[storage] DLQ open failed (err=%d)", err);
856864
flb_free(buf);
857-
return -1;
865+
CHUNK_RESTORE_AND_RETURN(-1);
858866
}
859867
if (cio_chunk_write(dst, buf, size) != CIO_OK ||
860868
cio_chunk_sync(dst) != CIO_OK) {
861869
flb_warn("[storage] DLQ write/sync failed");
862870
cio_chunk_close(dst, CIO_TRUE);
863871
flb_free(buf);
864-
return -1;
872+
CHUNK_RESTORE_AND_RETURN(-1);
865873
}
866874

867875
cio_chunk_close(dst, CIO_FALSE);
868876
flb_free(buf);
869877

870878
flb_info("[storage] quarantined rejected chunk into DLQ stream (bytes=%zu)", size);
871879

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-
}
880+
CHUNK_RESTORE_AND_RETURN(0);
881+
#undef CHUNK_RESTORE_AND_RETURN
878882

879883
return 0;
880884
#else

0 commit comments

Comments
 (0)