Skip to content

Commit

Permalink
refactor: Using reqwest-hickory-resolver as global dns client (databe…
Browse files Browse the repository at this point in the history
…ndlabs#14476)

* refactor: Using reqwest-hickory-resolver as global dns client

Signed-off-by: Xuanwo <[email protected]>

* format toml

Signed-off-by: Xuanwo <[email protected]>

---------

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Jan 30, 2024
1 parent ccb3b9b commit 943b6c9
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 116 deletions.
173 changes: 61 additions & 112 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ opendal = { version = "0.44.2", features = [
"services-ipfs",
"services-moka",
"services-huggingface",
"trust-dns",
] }
sled = { git = "https://github.com/datafuse-extras/sled", tag = "v0.34.7-datafuse.1", default-features = false }

Expand Down Expand Up @@ -160,8 +159,8 @@ reqwest = { version = "0.11.19", default-features = false, features = [
"json",
"rustls-tls",
"rustls-tls-native-roots",
"trust-dns",
] }
reqwest-hickory-resolver = "0.0.2"
semver = "1.0.14"
serfig = "0.1.0"
tokio = { version = "1.35.0", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion src/common/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ databend-common-exception = { path = "../exception" }

# Crates.io dependencies
anyerror = { workspace = true }
hickory-resolver = "0.24"
hyper = "0.14.20"
jwt-simple = "0.11.0"
log = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
tonic = { workspace = true }
trust-dns-resolver = { version = "0.22.0", features = ["system-config"] }

[build-dependencies]

Expand Down
2 changes: 1 addition & 1 deletion src/common/grpc/src/dns_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use databend_common_base::base::tokio;
use databend_common_base::base::tokio::task::JoinHandle;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;
use hickory_resolver::TokioAsyncResolver;
use hyper::client::connect::dns::Name;
use hyper::client::HttpConnector;
use hyper::service::Service;
Expand All @@ -38,7 +39,6 @@ use tonic::transport::Certificate;
use tonic::transport::Channel;
use tonic::transport::ClientTlsConfig;
use tonic::transport::Endpoint;
use trust_dns_resolver::TokioAsyncResolver;

use crate::RpcClientTlsConfig;

Expand Down
1 change: 1 addition & 0 deletions src/common/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ordered-float = { workspace = true }
parquet = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true }
reqwest-hickory-resolver = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

Expand Down
1 change: 1 addition & 0 deletions src/common/storage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(lazy_cell)]
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
10 changes: 10 additions & 0 deletions src/common/storage/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use std::env;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Result;
use std::sync::Arc;
use std::sync::LazyLock;
use std::time::Duration;

use anyhow::anyhow;
Expand Down Expand Up @@ -55,12 +57,17 @@ use opendal::raw::HttpClient;
use opendal::services;
use opendal::Builder;
use opendal::Operator;
use reqwest_hickory_resolver::HickoryResolver;

use crate::runtime_layer::RuntimeLayer;
use crate::StorageConfig;

static PROMETHEUS_CLIENT_LAYER_INSTANCE: OnceCell<PrometheusClientLayer> = OnceCell::new();

/// The global dns resolver for opendal.
static GLOBAL_HICKORY_RESOLVER: LazyLock<Arc<HickoryResolver>> =
LazyLock::new(|| Arc::new(HickoryResolver::default()));

/// init_operator will init an opendal operator based on storage config.
pub fn init_operator(cfg: &StorageParams) -> Result<Operator> {
let op = match &cfg {
Expand Down Expand Up @@ -306,6 +313,9 @@ fn init_s3_operator(cfg: &StorageS3Config) -> Result<impl Builder> {
let http_builder = {
let mut builder = reqwest::ClientBuilder::new();

// Set dns resolver.
builder = builder.dns_resolver(GLOBAL_HICKORY_RESOLVER.clone());

// Pool max idle per host controls connection pool size.
// Default to no limit, set to `0` for disable it.
let pool_max_idle_per_host = env::var("_DATABEND_INTERNAL_POOL_MAX_IDLE_PER_HOST")
Expand Down

0 comments on commit 943b6c9

Please sign in to comment.