From 309d9614de64e55aa5f55632f723a85830a7ad71 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Thu, 11 Jan 2024 05:27:26 +0900 Subject: [PATCH] storage: recreate cio_stream if storage type is different(#8259) (#8290) * storage: recreate cio_stream if storage type is different(#8259) cio_load creates storage stream if directory exists. It prevents to create memory stream by input plugins. This patch is to recreate stream if the type is different. Signed-off-by: Takahiro Yamashita * storage: modify log message Signed-off-by: Takahiro Yamashita --------- Signed-off-by: Takahiro Yamashita --- src/flb_storage.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/flb_storage.c b/src/flb_storage.c index 24cb79b6cdb..4148be66781 100644 --- a/src/flb_storage.c +++ b/src/flb_storage.c @@ -532,6 +532,22 @@ int flb_storage_input_create(struct cio_ctx *cio, return -1; } } + else if (stream->type != cio_storage_type) { + flb_debug("[storage] storage type mismatch. input type=%s", + flb_storage_get_type(in->storage_type)); + if (stream->type == FLB_STORAGE_FS) { + flb_warn("[storage] Need to remove '%s/%s' if it is empty", cio->options.root_path, in->name); + } + + cio_stream_destroy(stream); + stream = cio_stream_create(cio, in->name, cio_storage_type); + if (!stream) { + flb_error("[storage] cannot create stream for instance %s", + in->name); + return -1; + } + flb_info("[storage] re-create stream type=%s", flb_storage_get_type(in->storage_type)); + } /* allocate storage context for the input instance */ si = flb_malloc(sizeof(struct flb_storage_input));