github-actions[bot] commented on code in PR #32869: URL: https://github.com/apache/doris/pull/32869#discussion_r1539547367
########## be/src/util/dns_cache.h: ########## @@ -0,0 +1,52 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <chrono> +#include <iostream> +#include <shared_mutex> +#include <string> +#include <thread> +#include <unordered_map> + +namespace doris { +class DNSCache { +public: + DNSCache(); + ~DNSCache(); + + // get ip by hostname + Status get(const std::string& hostname, std::string* ip); Review Comment: warning: unknown type name 'Status' [clang-diagnostic-error] ```cpp Status get(const std::string& hostname, std::string* ip); ^ ``` ########## be/src/util/dns_cache.h: ########## @@ -0,0 +1,52 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <chrono> +#include <iostream> +#include <shared_mutex> +#include <string> +#include <thread> +#include <unordered_map> + +namespace doris { +class DNSCache { +public: + DNSCache(); + ~DNSCache(); + + // get ip by hostname + Status get(const std::string& hostname, std::string* ip); + +private: + // update the ip of hostname in cache + Status _update(const std::string& hostname); Review Comment: warning: unknown type name 'Status' [clang-diagnostic-error] ```cpp Status _update(const std::string& hostname); ^ ``` ########## be/src/util/dns_cache.h: ########## @@ -0,0 +1,52 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <chrono> +#include <iostream> +#include <shared_mutex> +#include <string> +#include <thread> +#include <unordered_map> + +namespace doris { +class DNSCache { +public: + DNSCache(); + ~DNSCache(); + + // get ip by hostname + Status get(const std::string& hostname, std::string* ip); + +private: + // update the ip of hostname in cache + Status _update(const std::string& hostname); + + // a function for refresh daemon thread + // update cache at fix internal + void _refresh_cache(); + +private: Review Comment: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] ```suggestion ``` <details> <summary>Additional context</summary> **be/src/util/dns_cache.h:35:** previously declared here ```cpp private: ^ ``` </details> ########## be/src/util/dns_cache.cpp: ########## @@ -0,0 +1,84 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "util/dns_cache.h" + +#include "service/backend_options.h" +#include "util/network_util.h" + +namespace doris { + +DNSCache::DNSCache() { + refresh_thread = std::thread(&DNSCache::_refresh_cache, this); + refresh_thread.detach(); +} + +DNSCache::~DNSCache() { + stop_refresh = true; + if (refresh_thread.joinable()) { + refresh_thread.join(); + } +} + +Status DNSCache::get(const std::string& hostname, std::string* ip) { + { + std::shared_lock<std::shared_mutex> lock(mutex); + auto it = cache.find(hostname); + if (it != cache.end()) { + *ip = it->second; + return Status::OK(); + } + } + // Update if not found + RETURN_IF_ERROR(_update(hostname)); + { + std::shared_lock<std::shared_mutex> lock(mutex); + *ip = cache[hostname]; + return Status::OK(); + } +} + +Status DNSCache::_update(const std::string& hostname) { + std::string real_ip = ""; + RETURN_IF_ERROR(hostname_to_ip(hostname, real_ip, BackendOptions::is_bind_ipv6())); + std::unique_lock<std::shared_mutex> lock(mutex); + auto it = cache.find(hostname); + if (it == cache.end() || it->second != real_ip) { + cache[hostname] = real_ip; + LOG(INFO) << "update hostname " << hostname << "'s ip to " << real_ip; + } + return Status::OK(); +} + +void DNSCache::_refresh_cache() { Review Comment: warning: method '_refresh_cache' can be made const [readability-make-member-function-const] ```suggestion void DNSCache::_refresh_cache() const { ``` be/src/util/dns_cache.h:41: ```diff - void _refresh_cache(); + void _refresh_cache() const; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org