Skip to content

Commit a8b7f5d

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

File tree

8 files changed

+795
-36
lines changed

8 files changed

+795
-36
lines changed

CHUNKS.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,36 @@ 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:
99+
100+
```
101+
Metadata
102+
-- +---------+-------+
103+
/ | 0xF1 | 0x77 | <- Magic Bytes
104+
/ +---------+-------+
105+
< | Type | Flags | <- Chunk type and flag bits
106+
\ +---------+-------+
107+
\ | Tag | <- Tag string (no size prefix)
108+
+---------+-------+
109+
| 0x00 | | <- Tag terminator (present when flags != 0)
110+
+---------+-------+
111+
| Routing Length | <- uint16_t big endian
112+
+---------+-------+
113+
| Route Count | <- uint16_t big endian
114+
+---------+-------+
115+
| Output IDs ... | <- Each stored as uint8_t
116+
-- +-----------------+
117+
```
118+
119+
The routing payload captures the direct route mapping so that filesystem chunks
120+
loaded by the storage backlog re-use the same outputs after a restart. Chunks
121+
without direct routes keep the legacy layout (flags byte set to zero) and remain
122+
fully backwards compatible across Fluent Bit versions.
123+
94124
### Fluent Bit <= v1.8
95125

96126
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: 14 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,9 @@
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+
4550
/* Chunks magic bytes (starting from Fluent Bit v1.8.10) */
4651
#define FLB_INPUT_CHUNK_MAGIC_BYTE_0 (unsigned char) 0xF1
4752
#define FLB_INPUT_CHUNK_MAGIC_BYTE_1 (unsigned char) 0x77
@@ -110,6 +115,15 @@ int flb_input_chunk_get_event_type(struct flb_input_chunk *ic);
110115
int flb_input_chunk_get_tag(struct flb_input_chunk *ic,
111116
const char **tag_buf, int *tag_len);
112117

118+
int flb_input_chunk_write_header_v2(struct cio_chunk *chunk,
119+
int event_type,
120+
char *tag, int tag_len,
121+
uint8_t *output_ids, int route_count);
122+
int flb_input_chunk_has_direct_routes(struct flb_input_chunk *ic);
123+
int flb_input_chunk_get_direct_routes(struct flb_input_chunk *ic,
124+
uint8_t **output_ids,
125+
int *route_count);
126+
113127
void flb_input_chunk_ring_buffer_cleanup(struct flb_input_instance *ins);
114128
void flb_input_chunk_ring_buffer_collector(struct flb_config *ctx, void *data);
115129
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)