This is an automated email from the ASF dual-hosted git repository. zwoop pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 93ee51a PR#5867: Explain how to use open_con(). 93ee51a is described below commit 93ee51a65f0cef90be03d953b59066270619274f Author: Oknet Xu <xuc...@skyguard.com.cn> AuthorDate: Fri Aug 23 17:06:30 2019 +0800 PR#5867: Explain how to use open_con(). The DNS sub-system has 2 work modes: - Primary-Secondary mode - Round-Robin mode The `open_con()` and `open_cons()` are shared with these 2 modes. Within the Primary-Secondary mode: - The `DNSHandler::ip` is used to store the Primary DNS server address. - The `validate_ip()` is the API to load the first DNS server address into The `DNSHandler::ip`. - The `open_con()` is the API to update `DNSHandler::ip` with `target` and connect to the address, but you cannot update `DNSHandler::ip` with it self. Within the Round-Robin mode: - The `DNSHandler::ip` is useless. - The `open_con()` is the API to connect to `target`. The SplitDNS is only available in the Primary-Secondary mode: - I suspect that the Round-Robin mode is a feature that was added later. - The author only made this functionality for the DNS sub-system, and forgot to do it for SplitDNS. (cherry picked from commit 678ab7a778d66f83475b478868f254aa62ff8344) --- iocore/dns/DNS.cc | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc index 8d91744..6713003 100644 --- a/iocore/dns/DNS.cc +++ b/iocore/dns/DNS.cc @@ -468,6 +468,15 @@ DNSHandler::open_cons(sockaddr const *target, bool failed, int icon) Open (and close) connections as necessary and also assures that the epoll fd struct is properly updated. + target == nullptr : + open connection to DNSHandler::ip. + generally, the icon should be 0 if target == nullptr. + + target != nullptr and icon == 0 : + open connection to target, and the target is assigned to DNSHandler::ip. + + target != nullptr and icon > 0 : + open connection to target. */ void DNSHandler::open_con(sockaddr const *target, bool failed, int icon, bool over_tcp) @@ -475,6 +484,8 @@ DNSHandler::open_con(sockaddr const *target, bool failed, int icon, bool over_tc ip_port_text_buffer ip_text; PollDescriptor *pd = get_PollDescriptor(dnsProcessor.thread); + ink_assert(target != &ip.sa); + if (!icon && target) { ats_ip_copy(&ip, target); } else if (!target) { @@ -549,6 +560,12 @@ DNSHandler::startEvent(int /* event ATS_UNUSED */, Event *e) dns_handler_initialized = 1; SET_HANDLER(&DNSHandler::mainEvent); if (dns_ns_rr) { + /* Round Robin mode: + * Establish a connection to each DNS server to make it a connection pool. + * For each DNS Request, a connection is picked up from the pool by round robin method. + * + * The first DNS server is assigned to DNSHandler::ip within open_con() function. + */ int max_nscount = m_res->nscount; if (max_nscount > MAX_NAMED) { max_nscount = MAX_NAMED; @@ -565,6 +582,18 @@ DNSHandler::startEvent(int /* event ATS_UNUSED */, Event *e) } dns_ns_rr_init_down = 0; } else { + /* Primary - Secondary mode: + * Establish a connection to the Primary DNS server. + * It always send DNS requests to the Primary DNS server. + * If the Primary DNS server dies, + * - it will attempt to send DNS requests to the secondary DNS server until the Primary DNS server is back. + * - and keep to detect the health of the Primary DNS server. + * If DNSHandler::recv_dns() got a valid DNS response from the Primary DNS server, + * - it means that the Primary DNS server returns. + * - it send all DNS requests to the Primary DNS server. + * + * The first DNS server is the Primary DNS server, and it is assigned to DNSHandler::ip within validate_ip() function. + */ open_cons(nullptr); // use current target address. n_con = 1; } @@ -587,8 +616,8 @@ DNSHandler::startEvent_sdns(int /* event ATS_UNUSED */, Event *e) this->validate_ip(); SET_HANDLER(&DNSHandler::mainEvent); - open_cons(&ip.sa, false, n_con); - ++n_con; // TODO should n_con be zeroed? + open_cons(nullptr, false, 0); + n_con = 1; return EVENT_CONT; } @@ -647,7 +676,7 @@ DNSHandler::try_primary_named(bool reopen) if (reopen && ((t - last_primary_reopen) > DNS_PRIMARY_REOPEN_PERIOD)) { Debug("dns", "try_primary_named: reopening primary DNS connection"); last_primary_reopen = t; - open_cons(&ip.sa, true, 0); + open_cons(nullptr, true, 0); } if ((t - last_primary_retry) > DNS_PRIMARY_RETRY_PERIOD) { unsigned char buffer[MAX_DNS_REQUEST_LEN];