be/src/io/fs/broker_file_writer.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 <gen_cpp/PaloBrokerService_types.h> |
21 | | #include <gen_cpp/Types_types.h> |
22 | | |
23 | | #include <map> |
24 | | #include <string> |
25 | | |
26 | | #include "common/status.h" |
27 | | #include "io/fs/file_writer.h" |
28 | | #include "util/hash_util.hpp" // IWYU pragma: keep |
29 | | #include "util/slice.h" |
30 | | |
31 | | namespace doris { |
32 | | |
33 | | class ExecEnv; |
34 | | |
35 | | namespace io { |
36 | | struct FileCacheAllocatorBuilder; |
37 | | class BrokerFileWriter final : public FileWriter { |
38 | | public: |
39 | | // Create and open file writer |
40 | | static Result<FileWriterPtr> create(ExecEnv* env, const TNetworkAddress& broker_address, |
41 | | const std::map<std::string, std::string>& properties, |
42 | | Path path); |
43 | | |
44 | | BrokerFileWriter(ExecEnv* env, const TNetworkAddress& broker_address, Path path, TBrokerFD fd); |
45 | | ~BrokerFileWriter() override; |
46 | | Status close(bool non_block = false) override; |
47 | | |
48 | | Status appendv(const Slice* data, size_t data_cnt) override; |
49 | 0 | const Path& path() const override { return _path; } |
50 | 0 | size_t bytes_appended() const override { return _cur_offset; } |
51 | 0 | State state() const override { return _state; } |
52 | | |
53 | | private: |
54 | | Status _write(const uint8_t* buf, size_t buf_len, size_t* written_bytes); |
55 | | Status _close_impl(); |
56 | | |
57 | | ExecEnv* _env = nullptr; |
58 | | const TNetworkAddress _address; |
59 | | Path _path; |
60 | | size_t _cur_offset = 0; |
61 | | TBrokerFD _fd; |
62 | | State _state {State::OPENED}; |
63 | | }; |
64 | | |
65 | | } // end namespace io |
66 | | } // end namespace doris |