duckdb 0.8.2-dev2673.0 → 0.8.2-dev2700.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +1 -0
- package/package.json +1 -1
- package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +6 -6
- package/src/duckdb/src/common/field_writer.cpp +1 -0
- package/src/duckdb/src/common/local_file_system.cpp +5 -0
- package/src/duckdb/src/common/types/interval.cpp +3 -0
- package/src/duckdb/src/execution/index/art/art.cpp +6 -9
- package/src/duckdb/src/execution/index/art/leaf.cpp +4 -4
- package/src/duckdb/src/execution/index/art/node.cpp +9 -12
- package/src/duckdb/src/execution/index/art/node16.cpp +4 -4
- package/src/duckdb/src/execution/index/art/node256.cpp +4 -4
- package/src/duckdb/src/execution/index/art/node4.cpp +4 -5
- package/src/duckdb/src/execution/index/art/node48.cpp +4 -4
- package/src/duckdb/src/execution/index/art/prefix.cpp +4 -6
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +4 -4
- package/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +6 -4
- package/src/duckdb/src/include/duckdb/execution/index/art/node16.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/index/art/node4.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/block.hpp +27 -4
- package/src/duckdb/src/include/duckdb/storage/block_manager.hpp +9 -9
- package/src/duckdb/src/include/duckdb/storage/checkpoint/row_group_writer.hpp +5 -5
- package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_reader.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +3 -3
- package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +19 -16
- package/src/duckdb/src/include/duckdb/storage/data_pointer.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/in_memory_block_manager.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/index.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/metadata/metadata_manager.hpp +88 -0
- package/src/duckdb/src/include/duckdb/storage/metadata/metadata_reader.hpp +54 -0
- package/src/duckdb/src/include/duckdb/storage/metadata/metadata_writer.hpp +45 -0
- package/src/duckdb/src/include/duckdb/storage/partial_block_manager.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/single_file_block_manager.hpp +6 -5
- package/src/duckdb/src/include/duckdb/storage/storage_info.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/storage_manager.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +2 -0
- package/src/duckdb/src/include/duckdb/storage/table/row_group_segment_tree.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/table/table_index_list.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table_io_manager.hpp +3 -0
- package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +3 -4
- package/src/duckdb/src/storage/buffer/block_manager.cpp +10 -9
- package/src/duckdb/src/storage/checkpoint/row_group_writer.cpp +1 -1
- package/src/duckdb/src/storage/checkpoint/table_data_reader.cpp +3 -4
- package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +7 -7
- package/src/duckdb/src/storage/checkpoint_manager.cpp +49 -43
- package/src/duckdb/src/storage/index.cpp +1 -1
- package/src/duckdb/src/storage/metadata/metadata_manager.cpp +267 -0
- package/src/duckdb/src/storage/metadata/metadata_reader.cpp +80 -0
- package/src/duckdb/src/storage/metadata/metadata_writer.cpp +86 -0
- package/src/duckdb/src/storage/single_file_block_manager.cpp +47 -52
- package/src/duckdb/src/storage/storage_info.cpp +1 -1
- package/src/duckdb/src/storage/storage_manager.cpp +4 -3
- package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +3 -3
- package/src/duckdb/src/storage/table/persistent_table_data.cpp +1 -2
- package/src/duckdb/src/storage/table/row_group.cpp +9 -10
- package/src/duckdb/src/storage/table/row_group_collection.cpp +6 -3
- package/src/duckdb/src/storage/table_index_list.cpp +1 -1
- package/src/duckdb/src/storage/wal_replay.cpp +3 -2
- package/src/duckdb/src/storage/write_ahead_log.cpp +3 -2
- package/src/duckdb/ub_src_storage.cpp +0 -4
- package/src/duckdb/ub_src_storage_metadata.cpp +6 -0
- package/src/duckdb/src/include/duckdb/storage/meta_block_reader.hpp +0 -46
- package/src/duckdb/src/include/duckdb/storage/meta_block_writer.hpp +0 -50
- package/src/duckdb/src/storage/meta_block_reader.cpp +0 -69
- package/src/duckdb/src/storage/meta_block_writer.cpp +0 -80
@@ -32,7 +32,7 @@ public:
|
|
32
32
|
|
33
33
|
virtual void WriteColumnDataPointers(ColumnCheckpointState &column_checkpoint_state) = 0;
|
34
34
|
|
35
|
-
virtual
|
35
|
+
virtual MetadataWriter &GetPayloadWriter() = 0;
|
36
36
|
|
37
37
|
void RegisterPartialBlock(PartialBlockAllocation &&allocation);
|
38
38
|
PartialBlockAllocation GetBlockAllocation(uint32_t segment_size);
|
@@ -50,18 +50,18 @@ protected:
|
|
50
50
|
class SingleFileRowGroupWriter : public RowGroupWriter {
|
51
51
|
public:
|
52
52
|
SingleFileRowGroupWriter(TableCatalogEntry &table, PartialBlockManager &partial_block_manager,
|
53
|
-
|
53
|
+
MetadataWriter &table_data_writer)
|
54
54
|
: RowGroupWriter(table, partial_block_manager), table_data_writer(table_data_writer) {
|
55
55
|
}
|
56
56
|
|
57
|
-
//!
|
57
|
+
//! MetadataWriter is a cursor on a given BlockManager. This returns the
|
58
58
|
//! cursor against which we should write payload data for the specified RowGroup.
|
59
|
-
|
59
|
+
MetadataWriter &table_data_writer;
|
60
60
|
|
61
61
|
public:
|
62
62
|
virtual void WriteColumnDataPointers(ColumnCheckpointState &column_checkpoint_state) override;
|
63
63
|
|
64
|
-
virtual
|
64
|
+
virtual MetadataWriter &GetPayloadWriter() override;
|
65
65
|
};
|
66
66
|
|
67
67
|
} // namespace duckdb
|
@@ -16,12 +16,12 @@ struct BoundCreateTableInfo;
|
|
16
16
|
//! The table data reader is responsible for reading the data of a table from the block manager
|
17
17
|
class TableDataReader {
|
18
18
|
public:
|
19
|
-
TableDataReader(
|
19
|
+
TableDataReader(MetadataReader &reader, BoundCreateTableInfo &info);
|
20
20
|
|
21
21
|
void ReadTableData();
|
22
22
|
|
23
23
|
private:
|
24
|
-
|
24
|
+
MetadataReader &reader;
|
25
25
|
BoundCreateTableInfo &info;
|
26
26
|
};
|
27
27
|
|
@@ -45,7 +45,7 @@ protected:
|
|
45
45
|
class SingleFileTableDataWriter : public TableDataWriter {
|
46
46
|
public:
|
47
47
|
SingleFileTableDataWriter(SingleFileCheckpointWriter &checkpoint_manager, TableCatalogEntry &table,
|
48
|
-
|
48
|
+
MetadataWriter &table_data_writer, MetadataWriter &meta_data_writer);
|
49
49
|
|
50
50
|
public:
|
51
51
|
virtual void FinalizeTable(TableStatistics &&global_stats, DataTableInfo *info) override;
|
@@ -54,9 +54,9 @@ public:
|
|
54
54
|
private:
|
55
55
|
SingleFileCheckpointWriter &checkpoint_manager;
|
56
56
|
// Writes the actual table data
|
57
|
-
|
57
|
+
MetadataWriter &table_data_writer;
|
58
58
|
// Writes the metadata of the table
|
59
|
-
|
59
|
+
MetadataWriter &meta_data_writer;
|
60
60
|
};
|
61
61
|
|
62
62
|
} // namespace duckdb
|
@@ -16,7 +16,7 @@ namespace duckdb {
|
|
16
16
|
class DatabaseInstance;
|
17
17
|
class ClientContext;
|
18
18
|
class ColumnSegment;
|
19
|
-
class
|
19
|
+
class MetadataReader;
|
20
20
|
class SchemaCatalogEntry;
|
21
21
|
class SequenceCatalogEntry;
|
22
22
|
class TableCatalogEntry;
|
@@ -33,7 +33,8 @@ public:
|
|
33
33
|
//! The database
|
34
34
|
AttachedDatabase &db;
|
35
35
|
|
36
|
-
virtual
|
36
|
+
virtual MetadataManager &GetMetadataManager() = 0;
|
37
|
+
virtual MetadataWriter &GetMetadataWriter() = 0;
|
37
38
|
virtual unique_ptr<TableDataWriter> GetTableDataWriter(TableCatalogEntry &table) = 0;
|
38
39
|
|
39
40
|
protected:
|
@@ -58,17 +59,17 @@ protected:
|
|
58
59
|
Catalog &catalog;
|
59
60
|
|
60
61
|
protected:
|
61
|
-
virtual void LoadCheckpoint(ClientContext &context,
|
62
|
-
virtual void ReadSchema(ClientContext &context,
|
63
|
-
virtual void ReadTable(ClientContext &context,
|
64
|
-
virtual void ReadView(ClientContext &context,
|
65
|
-
virtual void ReadSequence(ClientContext &context,
|
66
|
-
virtual void ReadMacro(ClientContext &context,
|
67
|
-
virtual void ReadTableMacro(ClientContext &context,
|
68
|
-
virtual void ReadIndex(ClientContext &context,
|
69
|
-
virtual void ReadType(ClientContext &context,
|
70
|
-
|
71
|
-
virtual void ReadTableData(ClientContext &context,
|
62
|
+
virtual void LoadCheckpoint(ClientContext &context, MetadataReader &reader);
|
63
|
+
virtual void ReadSchema(ClientContext &context, MetadataReader &reader);
|
64
|
+
virtual void ReadTable(ClientContext &context, MetadataReader &reader);
|
65
|
+
virtual void ReadView(ClientContext &context, MetadataReader &reader);
|
66
|
+
virtual void ReadSequence(ClientContext &context, MetadataReader &reader);
|
67
|
+
virtual void ReadMacro(ClientContext &context, MetadataReader &reader);
|
68
|
+
virtual void ReadTableMacro(ClientContext &context, MetadataReader &reader);
|
69
|
+
virtual void ReadIndex(ClientContext &context, MetadataReader &reader);
|
70
|
+
virtual void ReadType(ClientContext &context, MetadataReader &reader);
|
71
|
+
|
72
|
+
virtual void ReadTableData(ClientContext &context, MetadataReader &reader, BoundCreateTableInfo &bound_info);
|
72
73
|
};
|
73
74
|
|
74
75
|
class SingleFileCheckpointReader final : public CheckpointReader {
|
@@ -78,6 +79,7 @@ public:
|
|
78
79
|
}
|
79
80
|
|
80
81
|
void LoadFromStorage();
|
82
|
+
MetadataManager &GetMetadataManager();
|
81
83
|
|
82
84
|
//! The database
|
83
85
|
SingleFileStorageManager &storage;
|
@@ -98,16 +100,17 @@ public:
|
|
98
100
|
//! connection is available because right now the checkpointing cannot be done online. (TODO)
|
99
101
|
void CreateCheckpoint();
|
100
102
|
|
101
|
-
virtual
|
103
|
+
virtual MetadataWriter &GetMetadataWriter() override;
|
104
|
+
virtual MetadataManager &GetMetadataManager() override;
|
102
105
|
virtual unique_ptr<TableDataWriter> GetTableDataWriter(TableCatalogEntry &table) override;
|
103
106
|
|
104
107
|
BlockManager &GetBlockManager();
|
105
108
|
|
106
109
|
private:
|
107
110
|
//! The metadata writer is responsible for writing schema information
|
108
|
-
unique_ptr<
|
111
|
+
unique_ptr<MetadataWriter> metadata_writer;
|
109
112
|
//! The table data writer is responsible for writing the DataPointers used by the table chunks
|
110
|
-
unique_ptr<
|
113
|
+
unique_ptr<MetadataWriter> table_metadata_writer;
|
111
114
|
//! Because this is single-file storage, we can share partial blocks across
|
112
115
|
//! an entire checkpoint.
|
113
116
|
PartialBlockManager partial_block_manager;
|
@@ -33,7 +33,7 @@ struct RowGroupPointer {
|
|
33
33
|
uint64_t row_start;
|
34
34
|
uint64_t tuple_count;
|
35
35
|
//! The data pointers of the column segments stored in the row group
|
36
|
-
vector<
|
36
|
+
vector<MetaBlockPointer> data_pointers;
|
37
37
|
//! The versions information of the row group (if any)
|
38
38
|
shared_ptr<VersionNode> versions;
|
39
39
|
};
|
@@ -29,7 +29,7 @@ public:
|
|
29
29
|
block_id_t GetFreeBlockId() override {
|
30
30
|
throw InternalException("Cannot perform IO in in-memory database - GetFreeBlockId!");
|
31
31
|
}
|
32
|
-
bool IsRootBlock(
|
32
|
+
bool IsRootBlock(MetaBlockPointer root) override {
|
33
33
|
throw InternalException("Cannot perform IO in in-memory database - IsRootBlock!");
|
34
34
|
}
|
35
35
|
void MarkBlockAsFree(block_id_t block_id) override {
|
@@ -41,7 +41,7 @@ public:
|
|
41
41
|
void IncreaseBlockReferenceCount(block_id_t block_id) override {
|
42
42
|
throw InternalException("Cannot perform IO in in-memory database - IncreaseBlockReferenceCount!");
|
43
43
|
}
|
44
|
-
|
44
|
+
idx_t GetMetaBlock() override {
|
45
45
|
throw InternalException("Cannot perform IO in in-memory database - GetMetaBlock!");
|
46
46
|
}
|
47
47
|
void Read(Block &block) override {
|
@@ -14,7 +14,7 @@
|
|
14
14
|
#include "duckdb/common/sort/sort.hpp"
|
15
15
|
#include "duckdb/parser/parsed_expression.hpp"
|
16
16
|
#include "duckdb/planner/expression.hpp"
|
17
|
-
#include "duckdb/storage/
|
17
|
+
#include "duckdb/storage/metadata/metadata_writer.hpp"
|
18
18
|
#include "duckdb/execution/expression_executor.hpp"
|
19
19
|
#include "duckdb/common/types/constraint_conflict_info.hpp"
|
20
20
|
|
@@ -126,7 +126,7 @@ public:
|
|
126
126
|
}
|
127
127
|
|
128
128
|
//! Serializes the index and returns the pair of block_id offset positions
|
129
|
-
virtual BlockPointer Serialize(
|
129
|
+
virtual BlockPointer Serialize(MetadataWriter &writer);
|
130
130
|
//! Returns the serialized data pointer to the block and offset of the serialized index
|
131
131
|
BlockPointer GetSerializedDataPointer() const {
|
132
132
|
return serialized_data_pointer;
|
@@ -0,0 +1,88 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// duckdb/storage/metadata/metadata_manager.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
|
+
#include "duckdb/storage/buffer/buffer_handle.hpp"
|
17
|
+
|
18
|
+
namespace duckdb {
|
19
|
+
class DatabaseInstance;
|
20
|
+
|
21
|
+
struct MetadataBlock {
|
22
|
+
shared_ptr<BlockHandle> block;
|
23
|
+
block_id_t block_id;
|
24
|
+
vector<uint8_t> free_blocks;
|
25
|
+
|
26
|
+
void Serialize(Serializer &serializer);
|
27
|
+
static MetadataBlock Deserialize(Deserializer &source);
|
28
|
+
|
29
|
+
idx_t FreeBlocksToInteger();
|
30
|
+
void FreeBlocksFromInteger(idx_t blocks);
|
31
|
+
};
|
32
|
+
|
33
|
+
struct MetadataPointer {
|
34
|
+
idx_t block_index : 56;
|
35
|
+
uint8_t index : 8;
|
36
|
+
};
|
37
|
+
|
38
|
+
struct MetadataHandle {
|
39
|
+
MetadataPointer pointer;
|
40
|
+
BufferHandle handle;
|
41
|
+
};
|
42
|
+
|
43
|
+
class MetadataManager {
|
44
|
+
public:
|
45
|
+
//! The size of metadata blocks
|
46
|
+
static constexpr const idx_t METADATA_BLOCK_SIZE = 4088;
|
47
|
+
//! The amount of metadata blocks per storage block
|
48
|
+
static constexpr const idx_t METADATA_BLOCK_COUNT = 64;
|
49
|
+
|
50
|
+
public:
|
51
|
+
MetadataManager(BlockManager &block_manager, BufferManager &buffer_manager);
|
52
|
+
~MetadataManager();
|
53
|
+
|
54
|
+
MetadataHandle AllocateHandle();
|
55
|
+
MetadataHandle Pin(MetadataPointer pointer);
|
56
|
+
|
57
|
+
MetaBlockPointer GetDiskPointer(MetadataPointer pointer, uint32_t offset = 0);
|
58
|
+
MetadataPointer FromDiskPointer(MetaBlockPointer pointer);
|
59
|
+
MetadataPointer RegisterDiskPointer(MetaBlockPointer pointer);
|
60
|
+
|
61
|
+
static BlockPointer ToBlockPointer(MetaBlockPointer meta_pointer);
|
62
|
+
static MetaBlockPointer FromBlockPointer(BlockPointer block_pointer);
|
63
|
+
|
64
|
+
//! Flush all blocks to disk
|
65
|
+
void Flush();
|
66
|
+
|
67
|
+
void MarkBlocksAsModified();
|
68
|
+
|
69
|
+
idx_t BlockCount();
|
70
|
+
|
71
|
+
void Serialize(Serializer &serializer);
|
72
|
+
void Deserialize(Deserializer &source);
|
73
|
+
|
74
|
+
protected:
|
75
|
+
BlockManager &block_manager;
|
76
|
+
BufferManager &buffer_manager;
|
77
|
+
unordered_map<block_id_t, MetadataBlock> blocks;
|
78
|
+
unordered_map<block_id_t, idx_t> modified_blocks;
|
79
|
+
|
80
|
+
protected:
|
81
|
+
block_id_t AllocateNewBlock();
|
82
|
+
block_id_t GetNextBlockId();
|
83
|
+
|
84
|
+
void AddBlock(MetadataBlock new_block, bool if_exists = false);
|
85
|
+
void AddAndRegisterBlock(MetadataBlock block);
|
86
|
+
};
|
87
|
+
|
88
|
+
} // namespace duckdb
|
@@ -0,0 +1,54 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// duckdb/storage/metadata/metadata_reader.hpp
|
5
|
+
//
|
6
|
+
//
|
7
|
+
//===----------------------------------------------------------------------===//
|
8
|
+
|
9
|
+
#pragma once
|
10
|
+
|
11
|
+
#include "duckdb/storage/metadata/metadata_manager.hpp"
|
12
|
+
|
13
|
+
namespace duckdb {
|
14
|
+
|
15
|
+
enum class BlockReaderType { EXISTING_BLOCKS, REGISTER_BLOCKS };
|
16
|
+
|
17
|
+
class MetadataReader : public Deserializer {
|
18
|
+
public:
|
19
|
+
MetadataReader(MetadataManager &manager, MetaBlockPointer pointer,
|
20
|
+
BlockReaderType type = BlockReaderType::EXISTING_BLOCKS);
|
21
|
+
MetadataReader(MetadataManager &manager, BlockPointer pointer);
|
22
|
+
~MetadataReader() override;
|
23
|
+
|
24
|
+
public:
|
25
|
+
//! Read content of size read_size into the buffer
|
26
|
+
void ReadData(data_ptr_t buffer, idx_t read_size) override;
|
27
|
+
|
28
|
+
MetaBlockPointer GetMetaBlockPointer();
|
29
|
+
|
30
|
+
MetadataManager &GetMetadataManager() {
|
31
|
+
return manager;
|
32
|
+
}
|
33
|
+
|
34
|
+
private:
|
35
|
+
data_ptr_t BasePtr();
|
36
|
+
data_ptr_t Ptr();
|
37
|
+
|
38
|
+
void ReadNextBlock();
|
39
|
+
|
40
|
+
MetadataPointer FromDiskPointer(MetaBlockPointer pointer);
|
41
|
+
|
42
|
+
private:
|
43
|
+
MetadataManager &manager;
|
44
|
+
BlockReaderType type;
|
45
|
+
MetadataHandle block;
|
46
|
+
MetadataPointer next_pointer;
|
47
|
+
bool has_next_block;
|
48
|
+
idx_t index;
|
49
|
+
idx_t offset;
|
50
|
+
idx_t next_offset;
|
51
|
+
idx_t capacity;
|
52
|
+
};
|
53
|
+
|
54
|
+
} // namespace duckdb
|
@@ -0,0 +1,45 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// duckdb/storage/metadata/metadata_writer.hpp
|
5
|
+
//
|
6
|
+
//
|
7
|
+
//===----------------------------------------------------------------------===//
|
8
|
+
|
9
|
+
#pragma once
|
10
|
+
|
11
|
+
#include "duckdb/storage/metadata/metadata_manager.hpp"
|
12
|
+
|
13
|
+
namespace duckdb {
|
14
|
+
|
15
|
+
class MetadataWriter : public Serializer {
|
16
|
+
public:
|
17
|
+
explicit MetadataWriter(MetadataManager &manager);
|
18
|
+
~MetadataWriter() override;
|
19
|
+
|
20
|
+
public:
|
21
|
+
void WriteData(const_data_ptr_t buffer, idx_t write_size) override;
|
22
|
+
|
23
|
+
void Flush();
|
24
|
+
|
25
|
+
BlockPointer GetBlockPointer();
|
26
|
+
MetaBlockPointer GetMetaBlockPointer();
|
27
|
+
|
28
|
+
protected:
|
29
|
+
virtual MetadataHandle NextHandle();
|
30
|
+
|
31
|
+
private:
|
32
|
+
data_ptr_t BasePtr();
|
33
|
+
data_ptr_t Ptr();
|
34
|
+
|
35
|
+
void NextBlock();
|
36
|
+
|
37
|
+
private:
|
38
|
+
MetadataManager &manager;
|
39
|
+
MetadataHandle block;
|
40
|
+
MetadataPointer current_pointer;
|
41
|
+
idx_t capacity;
|
42
|
+
idx_t offset;
|
43
|
+
};
|
44
|
+
|
45
|
+
} // namespace duckdb
|
@@ -11,14 +11,14 @@
|
|
11
11
|
#include "duckdb/common/common.hpp"
|
12
12
|
#include "duckdb/common/map.hpp"
|
13
13
|
#include "duckdb/storage/storage_manager.hpp"
|
14
|
-
#include "duckdb/storage/
|
14
|
+
#include "duckdb/storage/metadata/metadata_writer.hpp"
|
15
15
|
#include "duckdb/storage/data_pointer.hpp"
|
16
16
|
|
17
17
|
namespace duckdb {
|
18
18
|
class DatabaseInstance;
|
19
19
|
class ClientContext;
|
20
20
|
class ColumnSegment;
|
21
|
-
class
|
21
|
+
class MetadataReader;
|
22
22
|
class SchemaCatalogEntry;
|
23
23
|
class SequenceCatalogEntry;
|
24
24
|
class TableCatalogEntry;
|
@@ -20,6 +20,7 @@
|
|
20
20
|
namespace duckdb {
|
21
21
|
|
22
22
|
class DatabaseInstance;
|
23
|
+
struct MetadataHandle;
|
23
24
|
|
24
25
|
struct StorageManagerOptions {
|
25
26
|
bool read_only = false;
|
@@ -45,7 +46,7 @@ public:
|
|
45
46
|
//! Return the next free block id
|
46
47
|
block_id_t GetFreeBlockId() override;
|
47
48
|
//! Returns whether or not a specified block is the root block
|
48
|
-
bool IsRootBlock(
|
49
|
+
bool IsRootBlock(MetaBlockPointer root) override;
|
49
50
|
//! Mark a block as free (immediately re-writeable)
|
50
51
|
void MarkBlockAsFree(block_id_t block_id) override;
|
51
52
|
//! Mark a block as modified (re-writeable after a checkpoint)
|
@@ -53,7 +54,7 @@ public:
|
|
53
54
|
//! Increase the reference count of a block. The block should hold at least one reference
|
54
55
|
void IncreaseBlockReferenceCount(block_id_t block_id) override;
|
55
56
|
//! Return the meta block id
|
56
|
-
|
57
|
+
idx_t GetMetaBlock() override;
|
57
58
|
//! Read the content of the block from disk
|
58
59
|
void Read(Block &block) override;
|
59
60
|
//! Write the given block to disk
|
@@ -78,7 +79,7 @@ private:
|
|
78
79
|
void ChecksumAndWrite(FileBuffer &handle, uint64_t location) const;
|
79
80
|
|
80
81
|
//! Return the blocks to which we will write the free list and modified blocks
|
81
|
-
vector<
|
82
|
+
vector<MetadataHandle> GetFreeListBlocks();
|
82
83
|
|
83
84
|
private:
|
84
85
|
AttachedDatabase &db;
|
@@ -99,11 +100,11 @@ private:
|
|
99
100
|
//! The list of blocks that will be added to the free list
|
100
101
|
unordered_set<block_id_t> modified_blocks;
|
101
102
|
//! The current meta block id
|
102
|
-
|
103
|
+
idx_t meta_block;
|
103
104
|
//! The current maximum block id, this id will be given away first after the free_list runs out
|
104
105
|
block_id_t max_block;
|
105
106
|
//! The block id where the free list can be found
|
106
|
-
|
107
|
+
idx_t free_list_id;
|
107
108
|
//! The current header iteration count
|
108
109
|
uint64_t iteration_count;
|
109
110
|
//! The storage manager options
|
@@ -65,9 +65,9 @@ struct DatabaseHeader {
|
|
65
65
|
//! The iteration count, increases by 1 every time the storage is checkpointed.
|
66
66
|
uint64_t iteration;
|
67
67
|
//! A pointer to the initial meta block
|
68
|
-
|
68
|
+
idx_t meta_block;
|
69
69
|
//! A pointer to the block containing the free list
|
70
|
-
|
70
|
+
idx_t free_list;
|
71
71
|
//! The number of blocks that is in the file as of this database header. If the file is larger than BLOCK_SIZE *
|
72
72
|
//! block_count any blocks appearing AFTER block_count are implicitly part of the free_list.
|
73
73
|
uint64_t block_count;
|
@@ -65,7 +65,7 @@ public:
|
|
65
65
|
|
66
66
|
virtual bool AutomaticCheckpoint(idx_t estimated_wal_bytes) = 0;
|
67
67
|
virtual unique_ptr<StorageCommitState> GenStorageCommitState(Transaction &transaction, bool checkpoint) = 0;
|
68
|
-
virtual bool IsCheckpointClean(
|
68
|
+
virtual bool IsCheckpointClean(MetaBlockPointer checkpoint_id) = 0;
|
69
69
|
virtual void CreateCheckpoint(bool delete_wal = false, bool force_checkpoint = false) = 0;
|
70
70
|
virtual DatabaseSize GetDatabaseSize() = 0;
|
71
71
|
virtual shared_ptr<TableIOManager> GetTableIOManager(BoundCreateTableInfo *info) = 0;
|
@@ -109,7 +109,7 @@ public:
|
|
109
109
|
public:
|
110
110
|
bool AutomaticCheckpoint(idx_t estimated_wal_bytes) override;
|
111
111
|
unique_ptr<StorageCommitState> GenStorageCommitState(Transaction &transaction, bool checkpoint) override;
|
112
|
-
bool IsCheckpointClean(
|
112
|
+
bool IsCheckpointClean(MetaBlockPointer checkpoint_id) override;
|
113
113
|
void CreateCheckpoint(bool delete_wal, bool force_checkpoint) override;
|
114
114
|
DatabaseSize GetDatabaseSize() override;
|
115
115
|
shared_ptr<TableIOManager> GetTableIOManager(BoundCreateTableInfo *info) override;
|
@@ -12,6 +12,7 @@
|
|
12
12
|
#include "duckdb/common/vector.hpp"
|
13
13
|
#include "duckdb/storage/data_pointer.hpp"
|
14
14
|
#include "duckdb/storage/table/table_statistics.hpp"
|
15
|
+
#include "duckdb/storage/metadata/metadata_manager.hpp"
|
15
16
|
|
16
17
|
namespace duckdb {
|
17
18
|
class BaseStatistics;
|
@@ -24,8 +25,7 @@ public:
|
|
24
25
|
TableStatistics table_stats;
|
25
26
|
idx_t total_rows;
|
26
27
|
idx_t row_group_count;
|
27
|
-
|
28
|
-
idx_t offset;
|
28
|
+
MetaBlockPointer block_pointer;
|
29
29
|
};
|
30
30
|
|
31
31
|
} // namespace duckdb
|
@@ -27,6 +27,7 @@ class DuckTransaction;
|
|
27
27
|
class BoundConstraint;
|
28
28
|
class RowGroupSegmentTree;
|
29
29
|
struct ColumnSegmentInfo;
|
30
|
+
class MetadataManager;
|
30
31
|
|
31
32
|
class RowGroupCollection {
|
32
33
|
public:
|
@@ -106,6 +107,7 @@ public:
|
|
106
107
|
BlockManager &GetBlockManager() {
|
107
108
|
return block_manager;
|
108
109
|
}
|
110
|
+
MetadataManager &GetMetadataManager();
|
109
111
|
DataTableInfo &GetTableInfo() {
|
110
112
|
return *info;
|
111
113
|
}
|
@@ -14,7 +14,7 @@
|
|
14
14
|
namespace duckdb {
|
15
15
|
struct DataTableInfo;
|
16
16
|
class PersistentTableData;
|
17
|
-
class
|
17
|
+
class MetadataReader;
|
18
18
|
|
19
19
|
class RowGroupSegmentTree : public SegmentTree<RowGroup, true> {
|
20
20
|
public:
|
@@ -29,7 +29,7 @@ protected:
|
|
29
29
|
RowGroupCollection &collection;
|
30
30
|
idx_t current_row_group;
|
31
31
|
idx_t max_row_group;
|
32
|
-
unique_ptr<
|
32
|
+
unique_ptr<MetadataReader> reader;
|
33
33
|
};
|
34
34
|
|
35
35
|
} // namespace duckdb
|
@@ -47,7 +47,7 @@ public:
|
|
47
47
|
void VerifyForeignKey(const vector<PhysicalIndex> &fk_keys, DataChunk &chunk, ConflictManager &conflict_manager);
|
48
48
|
|
49
49
|
//! Serialize all indexes owned by this table, returns a vector of block info of all indexes
|
50
|
-
vector<BlockPointer> SerializeIndexes(duckdb::
|
50
|
+
vector<BlockPointer> SerializeIndexes(duckdb::MetadataWriter &writer);
|
51
51
|
|
52
52
|
vector<column_t> GetRequiredColumns();
|
53
53
|
|
@@ -13,6 +13,7 @@
|
|
13
13
|
namespace duckdb {
|
14
14
|
class BlockManager;
|
15
15
|
class DataTable;
|
16
|
+
class MetadataManager;
|
16
17
|
|
17
18
|
class TableIOManager {
|
18
19
|
public:
|
@@ -27,6 +28,8 @@ public:
|
|
27
28
|
|
28
29
|
//! The block manager used for storing row group data
|
29
30
|
virtual BlockManager &GetBlockManagerForRowData() = 0;
|
31
|
+
|
32
|
+
virtual MetadataManager &GetMetadataManager() = 0;
|
30
33
|
};
|
31
34
|
|
32
35
|
} // namespace duckdb
|
@@ -39,8 +39,7 @@ class TransactionManager;
|
|
39
39
|
class ReplayState {
|
40
40
|
public:
|
41
41
|
ReplayState(AttachedDatabase &db, ClientContext &context, Deserializer &source)
|
42
|
-
: db(db), context(context), catalog(db.GetCatalog()), source(source), deserialize_only(false)
|
43
|
-
checkpoint_id(INVALID_BLOCK) {
|
42
|
+
: db(db), context(context), catalog(db.GetCatalog()), source(source), deserialize_only(false) {
|
44
43
|
}
|
45
44
|
|
46
45
|
AttachedDatabase &db;
|
@@ -49,7 +48,7 @@ public:
|
|
49
48
|
Deserializer &source;
|
50
49
|
optional_ptr<TableCatalogEntry> current_table;
|
51
50
|
bool deserialize_only;
|
52
|
-
|
51
|
+
MetaBlockPointer checkpoint_id;
|
53
52
|
|
54
53
|
public:
|
55
54
|
void ReplayEntry(WALType entry_type);
|
@@ -157,7 +156,7 @@ public:
|
|
157
156
|
void Delete();
|
158
157
|
void Flush();
|
159
158
|
|
160
|
-
void WriteCheckpoint(
|
159
|
+
void WriteCheckpoint(MetaBlockPointer meta_block);
|
161
160
|
|
162
161
|
protected:
|
163
162
|
AttachedDatabase &database;
|
@@ -2,10 +2,15 @@
|
|
2
2
|
#include "duckdb/storage/buffer_manager.hpp"
|
3
3
|
#include "duckdb/storage/buffer/block_handle.hpp"
|
4
4
|
#include "duckdb/storage/buffer/buffer_pool.hpp"
|
5
|
+
#include "duckdb/storage/metadata/metadata_manager.hpp"
|
5
6
|
|
6
7
|
namespace duckdb {
|
7
8
|
|
8
|
-
|
9
|
+
BlockManager::BlockManager(BufferManager &buffer_manager)
|
10
|
+
: buffer_manager(buffer_manager), metadata_manager(make_uniq<MetadataManager>(*this, buffer_manager)) {
|
11
|
+
}
|
12
|
+
|
13
|
+
shared_ptr<BlockHandle> BlockManager::RegisterBlock(block_id_t block_id) {
|
9
14
|
lock_guard<mutex> lock(blocks_lock);
|
10
15
|
// check if the block already exists
|
11
16
|
auto entry = blocks.find(block_id);
|
@@ -19,19 +24,11 @@ shared_ptr<BlockHandle> BlockManager::RegisterBlock(block_id_t block_id, bool is
|
|
19
24
|
}
|
20
25
|
// create a new block pointer for this block
|
21
26
|
auto result = make_shared<BlockHandle>(*this, block_id);
|
22
|
-
// for meta block, cache the handle in meta_blocks
|
23
|
-
if (is_meta_block) {
|
24
|
-
meta_blocks[block_id] = result;
|
25
|
-
}
|
26
27
|
// register the block pointer in the set of blocks as a weak pointer
|
27
28
|
blocks[block_id] = weak_ptr<BlockHandle>(result);
|
28
29
|
return result;
|
29
30
|
}
|
30
31
|
|
31
|
-
void BlockManager::ClearMetaBlockHandles() {
|
32
|
-
meta_blocks.clear();
|
33
|
-
}
|
34
|
-
|
35
32
|
shared_ptr<BlockHandle> BlockManager::ConvertToPersistent(block_id_t block_id, shared_ptr<BlockHandle> old_block) {
|
36
33
|
// pin the old block to ensure we have it loaded in memory
|
37
34
|
auto old_handle = buffer_manager.Pin(old_block);
|
@@ -79,6 +76,10 @@ void BlockManager::UnregisterBlock(block_id_t block_id, bool can_destroy) {
|
|
79
76
|
}
|
80
77
|
}
|
81
78
|
|
79
|
+
MetadataManager &BlockManager::GetMetadataManager() {
|
80
|
+
return *metadata_manager;
|
81
|
+
}
|
82
|
+
|
82
83
|
void BlockManager::Truncate() {
|
83
84
|
}
|
84
85
|
|
@@ -36,7 +36,7 @@ void SingleFileRowGroupWriter::WriteColumnDataPointers(ColumnCheckpointState &co
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
|
39
|
+
MetadataWriter &SingleFileRowGroupWriter::GetPayloadWriter() {
|
40
40
|
return table_data_writer;
|
41
41
|
}
|
42
42
|
|