be/src/load/message_body_sink.h
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 | | #pragma once |
19 | | |
20 | | #include <stddef.h> |
21 | | |
22 | | #include <memory> |
23 | | #include <string> |
24 | | #include <utility> |
25 | | |
26 | | #include "common/status.h" |
27 | | #include "util/byte_buffer.h" |
28 | | |
29 | | namespace doris { |
30 | | |
31 | | class MessageBodySink { |
32 | | public: |
33 | 2.46k | virtual ~MessageBodySink() = default; |
34 | | virtual Status append(const char* data, size_t size) = 0; |
35 | 26 | virtual Status append(const ByteBufferPtr& buf) { return append(buf->ptr, buf->remaining()); } |
36 | | // called when all data has been append |
37 | 0 | virtual Status finish() { return Status::OK(); } |
38 | | // called when read HTTP failed |
39 | 0 | virtual void cancel(const std::string& reason) {} |
40 | | |
41 | 0 | bool finished() const { return _finished; } |
42 | 48 | bool cancelled() const { return _cancelled; } |
43 | | |
44 | | protected: |
45 | | bool _finished = false; |
46 | | bool _cancelled = false; |
47 | | std::string _cancelled_reason; |
48 | | }; |
49 | | |
50 | | // write message to a local file |
51 | | class MessageBodyFileSink : public MessageBodySink { |
52 | | public: |
53 | 19 | MessageBodyFileSink(std::string path) : _path(std::move(path)) {} |
54 | | ~MessageBodyFileSink() override; |
55 | | |
56 | | Status open(); |
57 | | |
58 | | Status append(const char* data, size_t size) override; |
59 | | Status finish() override; |
60 | | void cancel(const std::string& reason) override; |
61 | | |
62 | | private: |
63 | | std::string _path; |
64 | | int _fd = -1; |
65 | | }; |
66 | | |
67 | | } // namespace doris |