| 721 | } |
| 722 | |
| 723 | XMLDocumentPtr ConfigProcessor::processConfig( |
| 724 | bool * has_zk_includes, |
| 725 | zkutil::ZooKeeperNodeCache * zk_node_cache, |
| 726 | const Coordination::EventPtr & zk_changed_event, |
| 727 | bool is_config_changed) |
| 728 | { |
| 729 | if (is_config_changed) |
| 730 | LOG_DEBUG(log, "Processing configuration file '{}'.", path); |
| 731 | |
| 732 | XMLDocumentPtr config; |
| 733 | |
| 734 | if (fs::exists(path)) |
| 735 | { |
| 736 | config = parseConfig(path, dom_parser); |
| 737 | } |
| 738 | else |
| 739 | { |
| 740 | /// When we can use a config embedded in the binary. |
| 741 | if (auto it = embedded_configs.find(path); it != embedded_configs.end()) |
| 742 | { |
| 743 | if (is_config_changed) |
| 744 | LOG_DEBUG(log, "There is no file '{}', will use embedded config.", path); |
| 745 | config = dom_parser.parseMemory(it->second.data(), it->second.size()); |
| 746 | } |
| 747 | else |
| 748 | throw Exception(ErrorCodes::FILE_DOESNT_EXIST, "Configuration file {} doesn't exist and there is no embedded config", path); |
| 749 | } |
| 750 | |
| 751 | std::vector<std::string> contributing_files; |
| 752 | contributing_files.push_back(path); |
| 753 | |
| 754 | for (auto & merge_file : getConfigMergeFiles(path)) |
| 755 | { |
| 756 | try |
| 757 | { |
| 758 | if (is_config_changed) |
| 759 | LOG_DEBUG(log, "Merging configuration file '{}'.", merge_file); |
| 760 | |
| 761 | XMLDocumentPtr with; |
| 762 | with = parseConfig(merge_file, dom_parser); |
| 763 | if (!merge(config, with)) |
| 764 | { |
| 765 | LOG_DEBUG( |
| 766 | log, "Merging bypassed - configuration file '{}' " |
| 767 | "doesn't belong to configuration '{}' - merging root node name '{}' doesn't match '{}'", |
| 768 | merge_file, path, getRootNode(with.get())->nodeName(), getRootNode(config.get())->nodeName()); |
| 769 | continue; |
| 770 | } |
| 771 | |
| 772 | contributing_files.push_back(merge_file); |
| 773 | } |
| 774 | catch (Exception & e) |
| 775 | { |
| 776 | e.addMessage("while merging config '" + path + "' with '" + merge_file + "'"); |
| 777 | throw; |
| 778 | } |
| 779 | catch (Poco::Exception & e) |
| 780 | { |