set the block header size for the encrypted database files set the database to encrypted update the storage version to 1.4.0
426540 {
426541 if (InMemory()) {
426542 block_manager = make_uniq<InMemoryBlockManager>(BufferManager::GetBufferManager(
db), DEFAULT_BLOCK_ALLOC_SIZE,
426543 DEFAULT_BLOCK_HEADER_STORAGE_SIZE);
426545
426548 return;
426549 }
426550 if (
storage_options.compress_in_memory != CompressInMemory::AUTOMATIC) {
426551 throw InvalidInputException("COMPRESS can only be set for in-memory databases");
426552 }
426553
426554 auto &fs = FileSystem::Get(
db);
426555 auto &config = DBConfig::Get(
db);
426556
426557 StorageManagerOptions options;
426559 options.use_direct_io = config.options.use_direct_io;
426560 options.debug_initialize = config.options.debug_initialize;
426562
426564
426565 D_ASSERT(
storage_options.block_header_size == DEFAULT_ENCRYPTION_BLOCK_HEADER_SIZE);
426566 options.encryption_options.encryption_enabled = true;
426567 options.encryption_options.user_key = std::move(
storage_options.user_key);
426568 options.encryption_options.encryption_version =
storage_options.encryption_version;
426569 }
426570
426571 idx_t row_group_size = DEFAULT_ROW_GROUP_SIZE;
426574 if (row_group_size == 0) {
426575 throw NotImplementedException("Invalid row group size: %llu - row group size must be bigger than 0",
426576 row_group_size);
426577 }
426578 if (row_group_size % STANDARD_VECTOR_SIZE != 0) {
426579 throw NotImplementedException(
426580 "Invalid row group size: %llu - row group size must be divisible by the vector size (%llu)",
426581 row_group_size, STANDARD_VECTOR_SIZE);
426582 }
426583 }
426584
426585
426587
426588
426589
426591
426593
426594
426596
426599 } else {
426600
426601 options.block_alloc_size = Settings::Get<DefaultBlockSizeSetting>(config);
426602 }
426607
426608 Storage::VerifyBlockHeaderSize(
storage_options.block_header_size.GetIndex());
426611 } else {
426612
426613 options.block_header_size = config.options.default_block_header_size;
426614 }
426615 if (!options.storage_version.IsValid()) {
426616
426617 options.storage_version = config.options.serialization_compatibility.serialization_version;
426618 }
426619
426620
426621 auto sf_block_manager = make_uniq<SingleFileBlockManager>(
db,
path, options);
426622 sf_block_manager->CreateNewDatabase(context);
426625 wal = make_uniq<WriteAheadLog>(*
this,
wal_path);
426626
426627 } else {
426628
426629
426630
426631
426632
426634 options.encryption_options.encryption_enabled = true;
426635 D_ASSERT(
storage_options.block_header_size == DEFAULT_ENCRYPTION_BLOCK_HEADER_SIZE);
426636 }
426638 Storage::VerifyBlockHeaderSize(
storage_options.block_header_size.GetIndex());
426641 } else {
426642
426643 options.block_header_size = config.options.default_block_header_size;
426644 }
426645
426646
426647
426648
426649 auto sf_block_manager = make_uniq<SingleFileBlockManager>(
db,
path, options);
426650 sf_block_manager->LoadExistingDatabase(context);
426653
426655
426657 if (block_alloc_size !=
block_manager->GetBlockAllocSize()) {
426658 throw InvalidInputException(
426659 "block size parameter does not match the file's block size, got %llu, expected %llu",
426661 }
426662 }
426663
426665
426667 if (block_header_size !=
block_manager->GetBlockHeaderSize()) {
426668 throw InvalidInputException(
426669 "block header size does not match the file's block header size, got %llu, expected %llu",
426671 }
426672 }
426673
426674 unique_ptr<ActiveTimer> timer = nullptr;
426675
426676
426677 auto client_context = context.GetClientContext();
426678 if (client_context) {
426679 auto profiler = client_context->client_data->profiler;
426680 timer = make_uniq<ActiveTimer>(profiler->StartTimer(MetricType::ATTACH_LOAD_STORAGE_LATENCY));
426681 }
426682
426683
426684 auto checkpoint_reader = SingleFileCheckpointReader(*this);
426685 checkpoint_reader.LoadFromStorage();
426686
426687
426688 if (timer) {
426689 timer->EndTimer();
426690 timer = nullptr;
426691 }
426692
426693
426694 if (client_context) {
426695 auto profiler = client_context->client_data->profiler;
426696 timer = make_uniq<ActiveTimer>(profiler->StartTimer(MetricType::ATTACH_REPLAY_WAL_LATENCY));
426697 }
426698
426699
426702
426703
426704 if (timer) {
426705 timer->EndTimer();
426706 }
426707 }
426708
426709 if (row_group_size > 122880ULL && GetStorageVersion() < 4) {
426710 throw InvalidInputException("Unsupported row group size %llu - row group sizes >= 122_880 are only supported "
426711 "with STORAGE_VERSION '1.2.0' or above.\nExplicitly specify a newer storage "
426712 "version when creating the database to enable larger row groups",
426713 row_group_size);
426714 }
426715
426717}
string wal_path
The WAL path.
Definition duckdb.cpp:11209
optional_idx storage_version
The serialization compatibility version when reading and writing from this database.
Definition duckdb.cpp:11220
StorageOptions storage_options
Storage options passed in through configuration.
Definition duckdb.cpp:11226
string GetWALPath(const string &suffix=".wal")
The path to the WAL, derived from the database file path.
Definition duckdb.cpp:426470
static unique_ptr< WriteAheadLog > Replay(QueryContext context, StorageManager &storage_manager, const string &wal_path)
Replay and initialize the WAL, QueryContext is passed for metric collection purposes only!...
Definition duckdb.cpp:444090
static void VerifyBlockAllocSize(const idx_t block_alloc_size)
Ensures that a user-provided block allocation size matches all requirements.
Definition duckdb.cpp:426037