| 1 | //===----------------------------------------------------------------------===// |
| 2 | // DuckDB |
| 3 | // |
| 4 | // duckdb/storage/optimistic_data_writer.hpp |
| 5 | // |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "duckdb/storage/table/row_group_collection.hpp" |
| 12 | |
| 13 | namespace duckdb { |
| 14 | class PartialBlockManager; |
| 15 | |
| 16 | class OptimisticDataWriter { |
| 17 | public: |
| 18 | OptimisticDataWriter(DataTable &table); |
| 19 | OptimisticDataWriter(DataTable &table, OptimisticDataWriter &parent); |
| 20 | ~OptimisticDataWriter(); |
| 21 | |
| 22 | //! Write a new row group to disk (if possible) |
| 23 | void WriteNewRowGroup(RowGroupCollection &row_groups); |
| 24 | //! Write the last row group of a collection to disk |
| 25 | void WriteLastRowGroup(RowGroupCollection &row_groups); |
| 26 | //! Final flush of the optimistic writer - fully flushes the partial block manager |
| 27 | void FinalFlush(); |
| 28 | //! Flushes a specific row group to disk |
| 29 | void FlushToDisk(RowGroup *row_group); |
| 30 | //! Merge the partially written blocks from one optimistic writer into another |
| 31 | void Merge(OptimisticDataWriter &other); |
| 32 | //! Rollback |
| 33 | void Rollback(); |
| 34 | |
| 35 | private: |
| 36 | //! Prepare a write to disk |
| 37 | bool PrepareWrite(); |
| 38 | |
| 39 | private: |
| 40 | //! The table |
| 41 | DataTable &table; |
| 42 | //! The partial block manager (if we created one yet) |
| 43 | unique_ptr<PartialBlockManager> partial_manager; |
| 44 | }; |
| 45 | |
| 46 | } // namespace duckdb |
| 47 | |