Пример #1
0
void loadMetadata(Context & context)
{
	String path = context.getPath() + "metadata";

	/** There may exist 'force_restore_data' file, that means,
	  *  skip safety threshold on difference of data parts while initializing tables.
	  * This file is deleted after successful loading of tables.
	  * (flag is "one-shot")
	  */
	Poco::File force_restore_data_flag_file(context.getFlagsPath() + "force_restore_data");
	bool has_force_restore_data_flag = force_restore_data_flag_file.exists();

	/// For parallel tables loading.
	ThreadPool thread_pool(SettingMaxThreads().getAutoValue());

	/// Loop over databases.
	Poco::DirectoryIterator dir_end;
	for (Poco::DirectoryIterator it(path); it != dir_end; ++it)
	{
		if (!it->isDirectory())
			continue;

		/// For '.svn', '.gitignore' directory and similar.
		if (it.name().at(0) == '.')
			continue;

		String database = unescapeForFileName(it.name());

		/// There may exist .sql file with database creation statement.
		/// Or, if it is absent, then database with default engine is created.

		String database_attach_query;
		String database_metadata_file = it->path() + ".sql";

		if (Poco::File(database_metadata_file).exists())
		{
			ReadBufferFromFile in(database_metadata_file, 1024);
			readStringUntilEOF(database_attach_query, in);
		}
		else
			database_attach_query = "ATTACH DATABASE " + backQuoteIfNeed(database);

		executeCreateQuery(database_attach_query, context, database, it->path(), thread_pool, has_force_restore_data_flag);
	}

	thread_pool.wait();

	if (has_force_restore_data_flag)
		force_restore_data_flag_file.remove();
}
Пример #2
0
void loadMetadata(Context & context)
{
	String path = context.getPath() + "metadata";

	/// Используется для параллельной загрузки таблиц.
	ThreadPool thread_pool(SettingMaxThreads().getAutoValue());

	/// Цикл по базам данных
	Poco::DirectoryIterator dir_end;
	for (Poco::DirectoryIterator it(path); it != dir_end; ++it)
	{
		if (!it->isDirectory())
			continue;

		/// Для директории .svn
		if (it.name().at(0) == '.')
			continue;

		String database = unescapeForFileName(it.name());

		/// Для базы данных может быть расположен .sql файл, где описан запрос на её создание.
		/// А если такого файла нет, то создаётся база данных с движком по-умолчанию.

		String database_attach_query;
		String database_metadata_file = it->path() + ".sql";

		if (Poco::File(database_metadata_file).exists())
		{
			ReadBufferFromFile in(database_metadata_file, 1024);
			readStringUntilEOF(database_attach_query, in);
		}
		else
			database_attach_query = "ATTACH DATABASE " + backQuoteIfNeed(database);

		executeCreateQuery(database_attach_query, context, database, it->path(), thread_pool);
	}

	thread_pool.wait();
}