1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/storage/meta_block_writer.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/common.hpp" |
12 | #include "duckdb/common/serializer.hpp" |
13 | #include "duckdb/storage/block.hpp" |
14 | #include "duckdb/storage/block_manager.hpp" |
15 | #include "duckdb/common/set.hpp" |
16 | |
17 | namespace duckdb { |
18 | class DatabaseInstance; |
19 | |
20 | //! This struct is responsible for writing data to disk in a stream of blocks. |
21 | class MetaBlockWriter : public Serializer { |
22 | public: |
23 | MetaBlockWriter(BlockManager &block_manager, block_id_t initial_block_id = INVALID_BLOCK); |
24 | ~MetaBlockWriter() override; |
25 | |
26 | BlockManager &block_manager; |
27 | |
28 | protected: |
29 | unique_ptr<Block> block; |
30 | set<block_id_t> written_blocks; |
31 | idx_t offset; |
32 | |
33 | public: |
34 | BlockPointer GetBlockPointer(); |
35 | virtual void Flush(); |
36 | |
37 | void WriteData(const_data_ptr_t buffer, idx_t write_size) override; |
38 | |
39 | void MarkWrittenBlocks() { |
40 | for (auto &block_id : written_blocks) { |
41 | block_manager.MarkBlockAsModified(block_id); |
42 | } |
43 | } |
44 | |
45 | protected: |
46 | virtual block_id_t GetNextBlockId(); |
47 | void AdvanceBlock(); |
48 | }; |
49 | |
50 | } // namespace duckdb |
51 |