be/src/load/routine_load/consumer_helpers.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "load/routine_load/consumer_helpers.h" |
19 | | |
20 | | #include <algorithm> |
21 | | #include <thread> |
22 | | |
23 | | #include "common/metrics/doris_metrics.h" |
24 | | |
25 | | namespace doris { |
26 | | |
27 | | // ConsumerMetrics implementation |
28 | 0 | void ConsumerMetrics::track_get_msg(int64_t latency_us) { |
29 | 0 | _get_msg_count++; |
30 | 0 | DorisMetrics::instance()->routine_load_get_msg_count->increment(1); |
31 | 0 | DorisMetrics::instance()->routine_load_get_msg_latency->increment(latency_us / 1000); |
32 | 0 | } |
33 | | |
34 | 0 | void ConsumerMetrics::track_consume_bytes(int64_t bytes) { |
35 | 0 | _consume_bytes += bytes; |
36 | 0 | DorisMetrics::instance()->routine_load_consume_bytes->increment(bytes); |
37 | 0 | } |
38 | | |
39 | 0 | void ConsumerMetrics::track_consume_rows(int64_t rows) { |
40 | 0 | _consume_rows += rows; |
41 | 0 | DorisMetrics::instance()->routine_load_consume_rows->increment(rows); |
42 | 0 | } |
43 | | |
44 | | // RetryPolicy implementation |
45 | 0 | void RetryPolicy::retry_with_backoff() { |
46 | 0 | _retry_count++; |
47 | 0 | if (_retry_count <= _max_retries) { |
48 | 0 | std::this_thread::sleep_for(std::chrono::milliseconds(_backoff_ms)); |
49 | 0 | } |
50 | 0 | } |
51 | | |
52 | | // ThrottleBackoff implementation |
53 | 0 | void ThrottleBackoff::backoff_and_sleep() { |
54 | 0 | _throttle_count++; |
55 | | // Exponential backoff: initial_ms * 2^(count-1), capped at max_ms |
56 | 0 | int backoff_ms = std::min(_initial_backoff_ms * (1 << std::min(_throttle_count - 1, 3)), |
57 | 0 | _max_backoff_ms); |
58 | 0 | std::this_thread::sleep_for(std::chrono::milliseconds(backoff_ms)); |
59 | 0 | } |
60 | | |
61 | | } // namespace doris |