Path DetailsMarkerPainter::getPath(const LayoutPoint& origin) const { Path result = getCanonicalPath(); result.transform(AffineTransform().scale(m_layoutDetailsMarker.contentWidth().toFloat(), m_layoutDetailsMarker.contentHeight().toFloat())); result.translate(FloatSize(origin.x().toFloat(), origin.y().toFloat())); return result; }
std::shared_ptr<TextureResource> TextureResource::get(const std::string& path, bool tile) { std::shared_ptr<ResourceManager>& rm = ResourceManager::getInstance(); const std::string canonicalPath = getCanonicalPath(path); if(canonicalPath.empty()) { std::shared_ptr<TextureResource> tex(new TextureResource("", tile)); rm->addReloadable(tex); //make sure we get properly deinitialized even though we do nothing on reinitialization return tex; } TextureKeyType key(canonicalPath, tile); auto foundTexture = sTextureMap.find(key); if(foundTexture != sTextureMap.end()) { if(!foundTexture->second.expired()) { return foundTexture->second.lock(); } } // need to create it std::shared_ptr<TextureResource> tex; // is it an SVG? if(key.first.substr(key.first.size() - 4, std::string::npos) == ".svg") { // probably // don't add it to our map because 2 svgs might be rasterized at different sizes tex = std::shared_ptr<SVGResource>(new SVGResource(key.first, tile)); sTextureList.push_back(tex); // add it to our list though rm->addReloadable(tex); tex->reload(rm); return tex; }else{ // normal texture tex = std::shared_ptr<TextureResource>(new TextureResource(key.first, tile)); sTextureMap[key] = std::weak_ptr<TextureResource>(tex); sTextureList.push_back(tex); rm->addReloadable(tex); tex->reload(ResourceManager::getInstance()); return tex; } }
Path Path::getParent() const { if (isEmpty()) return ""; std::string result; std::vector<std::string> segments(split()); // if our path is absolute with a single segment, // be sure to keep the prefix component if (!isAbsolute() || segments.size() > 1) { segments.pop_back(); // peel the last one } for (auto const& s : segments) { result.append(s).append(SEPARATOR_STR); } return getCanonicalPath(result); }
//============================================================================== std::shared_ptr<SharedLibrary> SharedLibraryManager::load( const boost::filesystem::path& path) { // Check if the given path exits const bool exists = boost::filesystem::exists(path); if (!exists) { dtwarn << "[SharedLibraryManager::load] The given path doesn't exist. " << "Returning nullptr.\n"; return nullptr; } // Convert the given path to the canonical path const auto canonicalPath = boost::filesystem::canonical(path); const auto iter = mLibraries.find(canonicalPath); const auto found = iter != mLibraries.end(); if (found) { auto lib = iter->second.lock(); // This check could fail if all instances to the library go out of scope, // since iter->second is a std::weak_ptr. In that case, we remove the // destructed library from the list and create new one. if (lib) return lib; else mLibraries.erase(iter); } const auto newLib = std::make_shared<SharedLibrary>( SharedLibrary::ProtectedConstruction, canonicalPath); if (!newLib->isValid()) return nullptr; mLibraries[canonicalPath] = newLib; assert(canonicalPath == newLib->getCanonicalPath()); return newLib; }
Path::Path(const std::string& path) : m_path(getCanonicalPath(path)) { }
int Server::main(const std::vector<std::string> & /*args*/) { Logger * log = &logger(); UseSSL use_ssl; ThreadStatus thread_status; registerFunctions(); registerAggregateFunctions(); registerTableFunctions(); registerStorages(); registerDictionaries(); CurrentMetrics::set(CurrentMetrics::Revision, ClickHouseRevision::get()); CurrentMetrics::set(CurrentMetrics::VersionInteger, ClickHouseRevision::getVersionInteger()); /** Context contains all that query execution is dependent: * settings, available functions, data types, aggregate functions, databases... */ global_context = std::make_unique<Context>(Context::createGlobal()); global_context->setGlobalContext(*global_context); global_context->setApplicationType(Context::ApplicationType::SERVER); bool has_zookeeper = config().has("zookeeper"); zkutil::ZooKeeperNodeCache main_config_zk_node_cache([&] { return global_context->getZooKeeper(); }); zkutil::EventPtr main_config_zk_changed_event = std::make_shared<Poco::Event>(); if (loaded_config.has_zk_includes) { auto old_configuration = loaded_config.configuration; ConfigProcessor config_processor(config_path); loaded_config = config_processor.loadConfigWithZooKeeperIncludes( main_config_zk_node_cache, main_config_zk_changed_event, /* fallback_to_preprocessed = */ true); config_processor.savePreprocessedConfig(loaded_config, config().getString("path", DBMS_DEFAULT_PATH)); config().removeConfiguration(old_configuration.get()); config().add(loaded_config.configuration.duplicate(), PRIO_DEFAULT, false); } const auto memory_amount = getMemoryAmount(); #if defined(__linux__) /// After full config loaded { if (config().getBool("mlock_executable", false)) { if (hasLinuxCapability(CAP_IPC_LOCK)) { LOG_TRACE(log, "Will mlockall to prevent executable memory from being paged out. It may take a few seconds."); if (0 != mlockall(MCL_CURRENT)) LOG_WARNING(log, "Failed mlockall: " + errnoToString(ErrorCodes::SYSTEM_ERROR)); else LOG_TRACE(log, "The memory map of clickhouse executable has been mlock'ed"); } else { LOG_INFO(log, "It looks like the process has no CAP_IPC_LOCK capability, binary mlock will be disabled." " It could happen due to incorrect ClickHouse package installation." " You could resolve the problem manually with 'sudo setcap cap_ipc_lock=+ep /usr/bin/clickhouse'." " Note that it will not work on 'nosuid' mounted filesystems."); } } } #endif std::string path = getCanonicalPath(config().getString("path", DBMS_DEFAULT_PATH)); std::string default_database = config().getString("default_database", "default"); /// Check that the process' user id matches the owner of the data. const auto effective_user_id = geteuid(); struct stat statbuf; if (stat(path.c_str(), &statbuf) == 0 && effective_user_id != statbuf.st_uid) { const auto effective_user = getUserName(effective_user_id); const auto data_owner = getUserName(statbuf.st_uid); std::string message = "Effective user of the process (" + effective_user + ") does not match the owner of the data (" + data_owner + ")."; if (effective_user_id == 0) { message += " Run under 'sudo -u " + data_owner + "'."; throw Exception(message, ErrorCodes::MISMATCHING_USERS_FOR_PROCESS_AND_DATA); } else { LOG_WARNING(log, message); } } global_context->setPath(path); /// Create directories for 'path' and for default database, if not exist. Poco::File(path + "data/" + default_database).createDirectories(); Poco::File(path + "metadata/" + default_database).createDirectories(); StatusFile status{path + "status"}; SCOPE_EXIT({ /** Ask to cancel background jobs all table engines, * and also query_log. * It is important to do early, not in destructor of Context, because * table engines could use Context on destroy. */ LOG_INFO(log, "Shutting down storages."); global_context->shutdown(); LOG_DEBUG(log, "Shutted down storages."); /** Explicitly destroy Context. It is more convenient than in destructor of Server, because logger is still available. * At this moment, no one could own shared part of Context. */ global_context.reset(); LOG_DEBUG(log, "Destroyed global context."); });
std::string Server::getDefaultCorePath() const { return getCanonicalPath(config().getString("path", DBMS_DEFAULT_PATH)) + "cores"; }
void Path::concatToSelf(const Path& path) { if (!path.isEmpty()) { if (path.isAbsolute()) { m_path = path.getPath(); } else if (m_path.back() != SEPARATOR) { m_path = getCanonicalPath(m_path + SEPARATOR + path.getPath()); } else { m_path = getCanonicalPath(m_path + path.getPath()); } } }