Skip to content

Commit 5e15d1b

Browse files
authored
Merge pull request #7617 from zhang2014/feat/auto_discover_ip
feat(cluster): auto discover ip when ip is unspecified or loop back
2 parents a57ddb1 + d880358 commit 5e15d1b

File tree

13 files changed

+73
-29
lines changed

13 files changed

+73
-29
lines changed

.github/actions/test_sqllogic_standalone_linux/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ runs:
2323
sha: ${{ github.sha }}
2424
target: ${{ inputs.target }}
2525

26-
- name: Run sqllogic Tests with Standalone mode with embedded meta-store
26+
- name: Run sqllogic Tests with Standalone mode
2727
shell: bash
2828
run: |
2929
docker run --rm --tty --net=host \

.github/workflows/dev-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
- uses: ./.github/actions/test_stateless_cluster_linux
130130

131131
test_sqllogic_standalone_linux:
132-
timeout-minutes: 15
132+
timeout-minutes: 30
133133
name: test_sqllogic_${{ matrix.dirs }}_standalone_linux
134134
runs-on: [self-hosted, X64, Linux, development]
135135
needs: build_gnu

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/ci/ci-run-sqllogic-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
set -e
55

66
echo "Starting standalone DatabendQuery and DatabendMeta"
7-
./scripts/ci/deploy/databend-query-standalone-embedded-meta.sh
7+
./scripts/ci/deploy/databend-query-standalone.sh
88

99
SCRIPT_PATH="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
1010
cd "$SCRIPT_PATH/../../tests/logictest" || exit

src/meta/client/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pub static METACLI_COMMIT_SEMVER: Lazy<Version> = Lazy::new(|| {
4141
/// Oldest compatible nightly metasrv version
4242
pub static MIN_METASRV_SEMVER: Version = Version {
4343
major: 0,
44-
minor: 7,
45-
patch: 63,
44+
minor: 8,
45+
patch: 30,
4646
pre: Prerelease::EMPTY,
4747
build: BuildMetadata::EMPTY,
4848
};

src/meta/store/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ impl MetaStore {
5555
MetaStore::R(_) => false,
5656
}
5757
}
58+
59+
pub async fn get_local_addr(&self) -> std::result::Result<Option<String>, MetaError> {
60+
match self {
61+
MetaStore::L(_) => Ok(None),
62+
MetaStore::R(grpc_client) => {
63+
let client_info = grpc_client.get_client_info().await?;
64+
Ok(Some(client_info.client_addr))
65+
}
66+
}
67+
}
5868
}
5969

6070
#[async_trait::async_trait]

src/query/management/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ common-exception = { path = "../../common/exception" }
1919
common-functions = { path = "../functions" }
2020
common-io = { path = "../../common/io" }
2121
common-meta-api = { path = "../../meta/api" }
22+
common-meta-store = { path = "../../meta/store" }
2223
common-meta-types = { path = "../../meta/types" }
2324
common-proto-conv = { path = "../../meta/proto-conv" }
2425
common-protos = { path = "../../meta/protos" }

src/query/management/src/cluster/cluster_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ pub trait ClusterApi: Sync + Send {
2828

2929
// Keep the tenant's cluster node alive.
3030
async fn heartbeat(&self, node: &NodeInfo, seq: Option<u64>) -> Result<u64>;
31+
32+
async fn get_local_addr(&self) -> Result<Option<String>>;
3133
}

src/query/management/src/cluster/cluster_mgr.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
use std::ops::Add;
16-
use std::sync::Arc;
1716
use std::time::Duration;
1817
use std::time::UNIX_EPOCH;
1918

@@ -22,6 +21,7 @@ use common_base::base::unescape_for_key;
2221
use common_exception::ErrorCode;
2322
use common_exception::Result;
2423
use common_meta_api::KVApi;
24+
use common_meta_store::MetaStore;
2525
use common_meta_types::KVMeta;
2626
use common_meta_types::MatchSeq;
2727
use common_meta_types::NodeInfo;
@@ -35,14 +35,14 @@ use crate::cluster::ClusterApi;
3535
pub static CLUSTER_API_KEY_PREFIX: &str = "__fd_clusters";
3636

3737
pub struct ClusterMgr {
38-
kv_api: Arc<dyn KVApi>,
38+
metastore: MetaStore,
3939
lift_time: Duration,
4040
cluster_prefix: String,
4141
}
4242

4343
impl ClusterMgr {
4444
pub fn create(
45-
kv_api: Arc<dyn KVApi>,
45+
metastore: MetaStore,
4646
tenant: &str,
4747
cluster_id: &str,
4848
lift_time: Duration,
@@ -54,7 +54,7 @@ impl ClusterMgr {
5454
}
5555

5656
Ok(ClusterMgr {
57-
kv_api,
57+
metastore,
5858
lift_time,
5959
cluster_prefix: format!(
6060
"{}/{}/{}/databend_query",
@@ -87,7 +87,7 @@ impl ClusterApi for ClusterMgr {
8787
let value = Operation::Update(serde_json::to_vec(&node)?);
8888
let node_key = format!("{}/{}", self.cluster_prefix, escape_for_key(&node.id)?);
8989
let upsert_node = self
90-
.kv_api
90+
.metastore
9191
.upsert_kv(UpsertKVReq::new(&node_key, seq, value, meta));
9292

9393
let res = upsert_node.await?.added_or_else(|v| {
@@ -101,7 +101,7 @@ impl ClusterApi for ClusterMgr {
101101
}
102102

103103
async fn get_nodes(&self) -> Result<Vec<NodeInfo>> {
104-
let values = self.kv_api.prefix_list_kv(&self.cluster_prefix).await?;
104+
let values = self.metastore.prefix_list_kv(&self.cluster_prefix).await?;
105105

106106
let mut nodes_info = Vec::with_capacity(values.len());
107107
for (node_key, value) in values {
@@ -116,7 +116,7 @@ impl ClusterApi for ClusterMgr {
116116

117117
async fn drop_node(&self, node_id: String, seq: Option<u64>) -> Result<()> {
118118
let node_key = format!("{}/{}", self.cluster_prefix, escape_for_key(&node_id)?);
119-
let upsert_node = self.kv_api.upsert_kv(UpsertKVReq::new(
119+
let upsert_node = self.metastore.upsert_kv(UpsertKVReq::new(
120120
&node_key,
121121
seq.into(),
122122
Operation::Delete,
@@ -145,7 +145,7 @@ impl ClusterApi for ClusterMgr {
145145
};
146146

147147
let upsert_meta =
148-
self.kv_api
148+
self.metastore
149149
.upsert_kv(UpsertKVReq::new(&node_key, seq, Operation::AsIs, meta));
150150

151151
match upsert_meta.await? {
@@ -157,4 +157,8 @@ impl ClusterApi for ClusterMgr {
157157
UpsertKVReply { .. } => self.add_node(node.clone()).await,
158158
}
159159
}
160+
161+
async fn get_local_addr(&self) -> Result<Option<String>> {
162+
Ok(self.metastore.get_local_addr().await?)
163+
}
160164
}

src/query/management/tests/it/cluster.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use common_exception::Result;
2121
use common_management::*;
2222
use common_meta_api::KVApi;
2323
use common_meta_embedded::MetaEmbedded;
24+
use common_meta_store::MetaStore;
2425
use common_meta_types::NodeInfo;
2526
use common_meta_types::SeqV;
2627

@@ -153,8 +154,8 @@ fn create_test_node_info() -> NodeInfo {
153154
}
154155
}
155156

156-
async fn new_cluster_api() -> Result<(Arc<MetaEmbedded>, ClusterMgr)> {
157-
let test_api = Arc::new(MetaEmbedded::new_temp().await?);
157+
async fn new_cluster_api() -> Result<(MetaStore, ClusterMgr)> {
158+
let test_api = MetaStore::L(Arc::new(MetaEmbedded::new_temp().await?));
158159
let cluster_manager = ClusterMgr::create(
159160
test_api.clone(),
160161
"test-tenant-id",

0 commit comments

Comments
 (0)