Skip to content

Commit 50d836f

Browse files
committed
buffer: add description about evacuate chunk feature
Signed-off-by: Daijiro Fukuda <[email protected]>
1 parent a9e71f7 commit 50d836f

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

buffer/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,37 @@ Fluentd will abort the attempt to transfer the failing chunks on the following c
7777

7878
\(default: `72h`\)
7979

80-
In these events, **all chunks in the queue are discarded.** If you want to avoid this, you can enable `retry_forever` to make Fluentd retry indefinitely.
80+
Before v1.19.0 (fluent-package v6), **all chunks in the queue are discarded** in these events.
81+
If you want to avoid this, you can enable `retry_forever` to make Fluentd retry indefinitely or enable `secondary` output.
82+
83+
Since v1.19.0 (fluent-package v6), the file buffer plugins ([`buf_file`](file.md) and [`buf_file_single`](file_single.md)) provides a safer and more user-friendly feature.
84+
They evacuates the chunk files in the queue to the following directory before clearing the queue.
85+
86+
```text
87+
${root_dir}/buffer/${plugin_id}/
88+
```
89+
90+
`${root_dir}` is determined by the parameter `root_dir` in `<system>`.
91+
If you do not configure this parameter, it will be `/tmp/fluent/`.
92+
93+
After the issues, such as network failures, are resolved, you can recover these chunks by moving the evacuated chunk files back to the plugin's buffer directory and restarting Fluentd.
94+
95+
{% hint style='info' %}
96+
If the plugin runs with multi-worker, the original buffer directory should be separated per worker. The evacuated chunk files can be restored to any worker's directory.
97+
{% endhint %}
98+
99+
{% hint style='info' %}
100+
You can use [zero-downtime restart](../deployment/zero-downtime-restart.md) to prevent downtime of some input plugins like `in_tcp`.
101+
{% endhint %}
102+
103+
{% hint style='info' %}
104+
For third-party buffer plugins, it is necessary to implement a function to support this feature.
105+
Please see [How to Write Buffer Plugin](../plugin-development/api-plugin-buffer.md) for details.
106+
{% endhint %}
107+
108+
{% hint style='warning' %}
109+
Please note that [`buf_memory`](memory.md) does not support this feature.
110+
{% endhint %}
81111

82112
### Handling Unrecoverable Errors
83113

plugin-development/api-plugin-buffer.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,28 @@
22

33
TODO: Write
44

5+
## Methods
6+
7+
### evacuate_chunk
8+
9+
You can override this method to add feature to evacuate chunks before clearing the queue when reaching the retry limit.
10+
See [Buffer - Handling Successive Failures](../buffer/README.md#handling-successive-failures) for details.
11+
12+
```ruby
13+
def evacuate_chunk(chunk)
14+
unless chunk.is_a?(Fluent::Plugin::Buffer::FileChunk)
15+
raise ArgumentError, "The chunk must be FileChunk, but it was #{chunk.class}."
16+
end
17+
18+
backup_dir = File.join(backup_base_dir, 'buffer', safe_owner_id)
19+
FileUtils.mkdir_p(backup_dir, mode: system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION) unless Dir.exist?(backup_dir)
20+
21+
FileUtils.copy([chunk.path, chunk.meta_path], backup_dir)
22+
log.warn "chunk files are evacuated to #{backup_dir}.", chunk_id: dump_unique_id_hex(chunk.unique_id)
23+
rescue => e
24+
log.error "unexpected error while evacuating chunk files.", error: e
25+
end
26+
```
27+
528
If this article is incorrect or outdated, or omits critical information, please [let us know](https://github.com/fluent/fluentd-docs-gitbook/issues?state=open). [Fluentd](http://www.fluentd.org/) is an open-source project under [Cloud Native Computing Foundation \(CNCF\)](https://cncf.io/). All components are available under the Apache 2 License.
629

0 commit comments

Comments
 (0)