diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index f7814fcf276..4d04b8ba69b 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -1521,21 +1521,27 @@ void MergeTreeData::loadDataParts(bool skip_sanity_checks) for (const auto & disk_ptr : disks) { defined_disk_names.insert(disk_ptr->getName()); + } + /// In case of delegate disks it is not enough to traverse `disks`, + /// because for example cache or encrypted disk which wrap s3 disk and s3 disk itself can be put into different storage policies. + /// But disk->exists returns the same thing for both disks. + for (const auto & [disk_name, disk] : getContext()->getDisksMap()) + { /// As encrypted disk can use the same path of its nested disk, /// we need to take it into account here. - const auto & delegate = disk_ptr->getDelegateDiskIfExists(); - if (delegate && disk_ptr->getPath() == delegate->getPath()) + const auto & delegate = disk->getDelegateDiskIfExists(); + if (delegate && disk->getPath() == delegate->getPath()) defined_disk_names.insert(delegate->getName()); - /// As cache is implemented on object storage layer, not on disk level, e.g. - /// we have such structure: - /// DiskObjectStorage(CachedObjectStorage(...(CachedObjectStored(ObjectStorage)...))) - /// and disk_ptr->getName() here is the name of last delegate - ObjectStorage. - /// So now we need to add cache layers to defined disk names. - if (disk_ptr->supportsCache()) + if (disk->supportsCache()) { - auto caches = disk_ptr->getCacheLayersNames(); + /// As cache is implemented on object storage layer, not on disk level, e.g. + /// we have such structure: + /// DiskObjectStorage(CachedObjectStorage(...(CachedObjectStored(ObjectStorage)...))) + /// and disk_ptr->getName() here is the name of last delegate - ObjectStorage. + /// So now we need to add cache layers to defined disk names. + auto caches = disk->getCacheLayersNames(); defined_disk_names.insert(caches.begin(), caches.end()); } } diff --git a/tests/integration/test_encrypted_disk/configs/storage.xml b/tests/integration/test_encrypted_disk/configs/storage.xml index a6fff813f2e..1e48c80d50f 100644 --- a/tests/integration/test_encrypted_disk/configs/storage.xml +++ b/tests/integration/test_encrypted_disk/configs/storage.xml @@ -15,7 +15,23 @@ encrypted disk_s3 1234567812345678 + encrypted/ + + encrypted + disk_s3 + 1234567812345678 + + + disk_s3 + s3_cache/ + 1Gi + + + encrypted + s3_cache + 1234567812345678 + encrypted disk_local @@ -73,6 +89,20 @@ + + +
+ disk_s3_encrypted_default_path +
+
+
_ + + +
+ encrypted_s3_cache +
+
+
diff --git a/tests/integration/test_encrypted_disk/test.py b/tests/integration/test_encrypted_disk/test.py index 8e2935a1603..681df89dd0f 100644 --- a/tests/integration/test_encrypted_disk/test.py +++ b/tests/integration/test_encrypted_disk/test.py @@ -273,24 +273,25 @@ def test_read_in_order(): def test_restart(): - node.query( - """ - DROP TABLE IF EXISTS encrypted_test; - CREATE TABLE encrypted_test ( - id Int64, - data String - ) ENGINE=MergeTree() - ORDER BY id - SETTINGS disk='disk_s3_encrypted' - """ - ) + for policy in ["disk_s3_encrypted_default_path", "encrypted_s3_cache"]: + node.query( + f""" + DROP TABLE IF EXISTS encrypted_test; + CREATE TABLE encrypted_test ( + id Int64, + data String + ) ENGINE=MergeTree() + ORDER BY id + SETTINGS disk='{policy}' + """ + ) - node.query("INSERT INTO encrypted_test VALUES (0,'data'),(1,'data')") - select_query = "SELECT * FROM encrypted_test ORDER BY id FORMAT Values" - assert node.query(select_query) == "(0,'data'),(1,'data')" + node.query("INSERT INTO encrypted_test VALUES (0,'data'),(1,'data')") + select_query = "SELECT * FROM encrypted_test ORDER BY id FORMAT Values" + assert node.query(select_query) == "(0,'data'),(1,'data')" - node.restart_clickhouse() + node.restart_clickhouse() - assert node.query(select_query) == "(0,'data'),(1,'data')" + assert node.query(select_query) == "(0,'data'),(1,'data')" - node.query("DROP TABLE IF EXISTS encrypted_test NO DELAY;") + node.query("DROP TABLE encrypted_test NO DELAY;")