MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / iterateMetadataFiles

Method iterateMetadataFiles

src/Databases/DatabaseOnDisk.cpp:657–750  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

655}
656
657void DatabaseOnDisk::iterateMetadataFiles(const IteratingFunction & process_metadata_file) const
658{
659 auto db_disk = getDisk();
660 if (!db_disk->existsDirectory(metadata_path))
661 return;
662
663 auto process_tmp_drop_metadata_file = [&](const String & file_name)
664 {
665 chassert(getUUID() == UUIDHelpers::Nil);
666 static const char * tmp_drop_ext = ".sql.tmp_drop";
667 const std::string object_name = file_name.substr(0, file_name.size() - strlen(tmp_drop_ext));
668
669 if (db_disk->existsFileOrDirectory(fs::path(data_path) / object_name))
670 {
671 db_disk->replaceFile(getMetadataPath() + file_name, getMetadataPath() + object_name + ".sql");
672 LOG_WARNING(log, "Object {} was not dropped previously and will be restored", backQuote(object_name));
673 process_metadata_file(object_name + ".sql");
674 }
675 else
676 {
677 LOG_INFO(log, "Removing file {}", getMetadataPath() + file_name);
678 db_disk->removeFileIfExists(getMetadataPath() + file_name);
679 }
680 };
681
682 /// Metadata files to load: name and flag for .tmp_drop files
683 std::vector<std::pair<String, bool>> metadata_files;
684
685 for (const auto it = db_disk->iterateDirectory(metadata_path); it->isValid(); it->next())
686 {
687 auto sub_path = fs::path(it->path());
688 String file_name = it->name();
689 /// For '.svn', '.gitignore' directory and similar.
690 if (!file_name.empty() && file_name.at(0) == '.')
691 continue;
692
693 /// There are .sql.bak files - skip them.
694 if (endsWith(file_name, ".sql.bak"))
695 continue;
696
697 /// Permanently detached table flag
698 if (endsWith(file_name, ".sql.detached"))
699 continue;
700
701 if (endsWith(file_name, ".sql.tmp_drop"))
702 {
703 /// There are files that we tried to delete previously
704 metadata_files.emplace_back(file_name, false);
705 }
706 else if (endsWith(file_name, ".tmp_move_from") || endsWith(file_name, ".tmp_move_to"))
707 {
708 /// There are temp files generated in MetadataStorageFromPlainObjectStorageMoveFileOperation
709 LOG_INFO(log, "Removing file {}", sub_path.string());
710 db_disk->removeFileIfExists(sub_path);
711 }
712 else if (endsWith(file_name, ".sql.tmp"))
713 {
714 /// There are files .sql.tmp - delete

Callers

nothing calls this directly

Calls 15

backQuoteFunction · 0.85
uniqueFunction · 0.85
scheduleOrThrowMethod · 0.80
endsWithFunction · 0.50
ExceptionClass · 0.50
sortFunction · 0.50
minFunction · 0.50
nextFunction · 0.50
setThreadNameFunction · 0.50
getContextFunction · 0.50
existsDirectoryMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected