Skip to content

Commit d42742b

Browse files
committed
wip-nov2
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 8b7cfba commit d42742b

File tree

8 files changed

+1149
-36
lines changed

8 files changed

+1149
-36
lines changed

CHUNKS.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,47 @@ Content Data < | | records | |
9191
Fluent Bit API provides backward compatibility with the previous metadata and content
9292
format found on series v1.8.
9393

94+
Starting with the Fluent Bit release that introduces direct route persistence, the
95+
fourth metadata byte now carries feature flags. A zero value preserves the legacy
96+
layout, while a non-zero value indicates that additional structures follow the tag.
97+
When the ``FLB_CHUNK_FLAG_DIRECT_ROUTES`` bit is set the tag is terminated with a
98+
single ``\0`` byte and a routing payload is appended. Fluent Bit v3.0 and later
99+
also set the ``FLB_CHUNK_FLAG_DIRECT_ROUTE_LABELS`` bit to store each destination's
100+
alias (or generated name) alongside its numeric identifier so routes can survive
101+
configuration changes that renumber outputs:
102+
103+
```
104+
Metadata
105+
-- +---------+-------+
106+
/ | 0xF1 | 0x77 | <- Magic Bytes
107+
/ +---------+-------+
108+
< | Type | Flags | <- Chunk type and flag bits
109+
\ +---------+-------+
110+
\ | Tag | <- Tag string (no size prefix)
111+
+---------+-------+
112+
| 0x00 | | <- Tag terminator (present when flags != 0)
113+
+---------+-------+
114+
| Routing Length | <- uint16_t big endian
115+
+---------+-------+
116+
| Route Count | <- uint16_t big endian
117+
+---------+-------+
118+
| Output IDs ... | <- Each stored as uint16_t (big endian)
119+
+---------+-------+
120+
| Label Lens ... | <- Present when FLB_CHUNK_FLAG_DIRECT_ROUTE_LABELS
121+
+---------+-------+
122+
| Label Bytes ... | <- Concatenated label strings (no terminators)
123+
-- +-----------------+
124+
```
125+
126+
The routing payload captures the direct route mapping so that filesystem chunks
127+
loaded by the storage backlog re-use the same outputs after a restart. Chunks
128+
without direct routes keep the legacy layout (flags byte set to zero) and remain
129+
fully backwards compatible across Fluent Bit versions. When labels are stored the
130+
reader first reconstructs routes by matching aliases or numbered names and only
131+
falls back to numeric identifiers if the textual metadata cannot be matched. This
132+
ensures that chunks continue to flow to the intended destinations even when the
133+
output configuration is re-ordered.
134+
94135
### Fluent Bit <= v1.8
95136

96137
Up to Fluent Bit <= 1.8.x, the metadata and content data is simple, where metadata

include/fluent-bit/flb_input_chunk.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <fluent-bit/flb_config.h>
2626
#include <fluent-bit/flb_routes_mask.h>
2727

28+
struct cio_chunk;
29+
2830
#include <monkey/mk_core.h>
2931
#include <msgpack.h>
3032

@@ -42,6 +44,16 @@
4244
/* Number of bytes reserved for Metadata Header on Chunks */
4345
#define FLB_INPUT_CHUNK_META_HEADER 4
4446

47+
/* Chunk metadata flags */
48+
#define FLB_CHUNK_FLAG_DIRECT_ROUTES (1 << 0)
49+
#define FLB_CHUNK_FLAG_DIRECT_ROUTE_LABELS (1 << 1)
50+
51+
struct flb_chunk_direct_route {
52+
uint16_t id;
53+
uint16_t label_length;
54+
const char *label;
55+
};
56+
4557
/* Chunks magic bytes (starting from Fluent Bit v1.8.10) */
4658
#define FLB_INPUT_CHUNK_MAGIC_BYTE_0 (unsigned char) 0xF1
4759
#define FLB_INPUT_CHUNK_MAGIC_BYTE_1 (unsigned char) 0x77
@@ -110,6 +122,18 @@ int flb_input_chunk_get_event_type(struct flb_input_chunk *ic);
110122
int flb_input_chunk_get_tag(struct flb_input_chunk *ic,
111123
const char **tag_buf, int *tag_len);
112124

125+
int flb_input_chunk_write_header_v2(struct cio_chunk *chunk,
126+
int event_type,
127+
char *tag, int tag_len,
128+
const struct flb_chunk_direct_route *routes,
129+
int route_count);
130+
int flb_input_chunk_has_direct_routes(struct flb_input_chunk *ic);
131+
int flb_input_chunk_get_direct_routes(struct flb_input_chunk *ic,
132+
struct flb_chunk_direct_route **routes,
133+
int *route_count);
134+
void flb_input_chunk_destroy_direct_routes(struct flb_chunk_direct_route *routes,
135+
int route_count);
136+
113137
void flb_input_chunk_ring_buffer_cleanup(struct flb_input_instance *ins);
114138
void flb_input_chunk_ring_buffer_collector(struct flb_config *ctx, void *data);
115139
ssize_t flb_input_chunk_get_size(struct flb_input_chunk *ic);

lib/chunkio/src/cio_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ int cio_file_write_metadata(struct cio_chunk *ch, char *buf, size_t size)
11061106
/* set new position for the content data */
11071107
cur_content_data = cio_file_st_get_content(cf->map);
11081108
new_content_data = meta + size;
1109-
memmove(new_content_data, cur_content_data, size);
1109+
memmove(new_content_data, cur_content_data, cf->data_size);
11101110

11111111
/* copy new metadata */
11121112
memcpy(meta, buf, size);

0 commit comments

Comments
 (0)