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

Method updateMetadataFile

src/Interpreters/DatabaseCatalog.cpp:777–812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

775}
776
777void DatabaseCatalog::updateMetadataFile(const String & database_name, const ASTPtr & create_query)
778{
779 std::lock_guard lock{databases_mutex};
780 if (!create_query)
781 throw Exception(ErrorCodes::THERE_IS_NO_QUERY, "Unable to show the create query of database {}", backQuoteIfNeed(database_name));
782
783 auto * ast_create_query = create_query->as<ASTCreateQuery>();
784 ast_create_query->attach = true;
785
786 WriteBufferFromOwnString statement_buf;
787 IAST::FormatSettings format_settings(/*one_line=*/false);
788 ast_create_query->format(statement_buf, format_settings);
789 writeChar('\n', statement_buf);
790 String statement = statement_buf.str();
791
792 auto metadata_file_path = getMetadataFilePath(database_name);
793 auto metadata_tmp_file_path = getMetadataTmpFilePath(database_name);
794 auto default_db_disk = getContext()->getDatabaseDisk();
795
796 writeMetadataFile(
797 default_db_disk,
798 /*file_path=*/metadata_tmp_file_path,
799 /*content=*/statement,
800 getContext()->getSettingsRef()[Setting::fsync_metadata]);
801
802 try
803 {
804 /// rename atomically replaces the old file with the new one.
805 default_db_disk->replaceFile(metadata_tmp_file_path, metadata_file_path);
806 }
807 catch (...)
808 {
809 default_db_disk->removeFileIfExists(metadata_tmp_file_path);
810 throw;
811 }
812}
813
814DatabasePtr DatabaseCatalog::getDatabase(std::string_view database_name) const
815{

Callers 1

alterDatabaseCommentMethod · 0.80

Calls 10

backQuoteIfNeedFunction · 0.85
writeCharFunction · 0.85
writeMetadataFileFunction · 0.85
getDatabaseDiskMethod · 0.80
ExceptionClass · 0.70
getContextFunction · 0.50
formatMethod · 0.45
strMethod · 0.45
replaceFileMethod · 0.45
removeFileIfExistsMethod · 0.45

Tested by

no test coverage detected