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

Method initialize

src/Disks/DiskSelector.cpp:92–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void DiskSelector::initialize(
93 const Poco::Util::AbstractConfiguration & config, const String & config_prefix, ContextPtr context, DiskValidator disk_validator)
94try
95{
96 auto component_guard = Coordination::setCurrentComponent("DiskSelector::initialize");
97 Poco::Util::AbstractConfiguration::Keys keys;
98 config.keys(config_prefix, keys);
99
100 auto & factory = DiskFactory::instance();
101
102 bool has_default_disk = false;
103 bool has_local_disk = false;
104 for (const auto & disk_name : keys)
105 {
106 if (!std::all_of(disk_name.begin(), disk_name.end(), isWordCharASCII))
107 throw Exception(ErrorCodes::EXCESSIVE_ELEMENT_IN_CONFIG, "Disk name can contain only alphanumeric and '_' ({})", disk_name);
108
109 if (disk_name == DEFAULT_DISK_NAME)
110 has_default_disk = true;
111
112 if (disk_name == LOCAL_DISK_NAME)
113 has_local_disk = true;
114
115 const auto disk_config_prefix = config_prefix + "." + disk_name;
116
117 if (disk_validator && !disk_validator(config, disk_config_prefix, disk_name))
118 continue;
119 auto created_disk
120 = factory.create(disk_name, config, disk_config_prefix, context, disks, /*attach*/ false, /*custom_disk*/ false, skip_types);
121 if (created_disk.get())
122 {
123 recordDisk(disk_name, std::move(created_disk));
124 }
125 }
126 if (!has_default_disk)
127 {
128 recordDisk(DEFAULT_DISK_NAME, std::make_shared<DiskLocal>(DEFAULT_DISK_NAME, context->getPath(), 0, context, config, config_prefix));
129 }
130
131 if (!has_local_disk && (context->getApplicationType() == Context::ApplicationType::DISKS))
132 {
133 throw_away_local_on_update = true;
134 recordDisk(LOCAL_DISK_NAME, std::make_shared<DiskLocal>(LOCAL_DISK_NAME, "/", 0, context, config, config_prefix));
135 }
136 is_initialized = true;
137}
138catch (...)
139{
140 for (const auto & [name, disk] : disks)
141 disk->shutdown();
142 throw;
143}
144
145DiskSelectorPtr DiskSelector::updateFromConfig(
146 const Poco::Util::AbstractConfiguration & config, const String & config_prefix, ContextPtr context) const

Callers

nothing calls this directly

Calls 10

setCurrentComponentFunction · 0.85
keysMethod · 0.80
getApplicationTypeMethod · 0.80
ExceptionClass · 0.50
beginMethod · 0.45
endMethod · 0.45
createMethod · 0.45
getMethod · 0.45
getPathMethod · 0.45
shutdownMethod · 0.45

Tested by

no test coverage detected