1#include "DiskFactory.h"
2
3namespace DB
4{
5namespace ErrorCodes
6{
7 extern const int LOGICAL_ERROR;
8 extern const int UNKNOWN_ELEMENT_IN_CONFIG;
9}
10
11DiskFactory & DiskFactory::instance()
12{
13 static DiskFactory factory;
14 return factory;
15}
16
17void DiskFactory::registerDiskType(const String & disk_type, DB::DiskFactory::Creator creator)
18{
19 if (!registry.emplace(disk_type, creator).second)
20 throw Exception("DiskFactory: the disk type '" + disk_type + "' is not unique", ErrorCodes::LOGICAL_ERROR);
21}
22
23DiskPtr DiskFactory::create(
24 const String & name,
25 const Poco::Util::AbstractConfiguration & config,
26 const String & config_prefix,
27 const Context & context) const
28{
29 const auto disk_type = config.getString(config_prefix + ".type", "local");
30
31 const auto found = registry.find(disk_type);
32 if (found == registry.end())
33 throw Exception{"DiskFactory: the disk '" + name + "' has unknown disk type: " + disk_type, ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG};
34
35 const auto & disk_creator = found->second;
36 return disk_creator(name, config, config_prefix, context);
37}
38
39}
40