This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DNS TTL functionality to couch_replicator_httpc_pool
This feature periodically checks the DNS entry for the target URL. If DNS returns data that's different from the previous check, all open connections are gracefully closed in favor of new ones, which will perform a new DNS lookup upon connection establishment. BugzID: 41419
- Loading branch information
Showing
2 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-module(couch_replicator_dns). | ||
|
||
-include_lib("kernel/src/inet_dns.hrl"). | ||
-include_lib("ibrowse/include/ibrowse.hrl"). | ||
|
||
-export([ | ||
lookup/1 | ||
]). | ||
|
||
-spec lookup(iolist()) -> {ok, {term(), pos_integer()}} | {error, term()}. | ||
|
||
lookup(Url) -> | ||
case ibrowse_lib:parse_url(Url) of | ||
#url{host_type = hostname, host = Host} -> | ||
case inet_res:resolve(Host, any, any) of | ||
{error, {Error, _}} -> | ||
{error, Error}; | ||
{ok, #dns_rec{anlist=[Answer|_As]}} -> | ||
#dns_rr{data=Data, ttl=TTL} = Answer, | ||
{Data, TTL}; | ||
Else -> | ||
twig:log(warn, "Unknown DNS response: ~p", [Else]), | ||
{error, Else} | ||
end; | ||
#url{} -> | ||
{error, not_a_hostname}; | ||
Else -> | ||
{error, Else} | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters