Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make enable_partition_table_access a config #1182

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions proxy/src/grpc/sql_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ impl Proxy {

let req_context = req.context.as_ref().unwrap();
let schema = &req_context.database;
match self.handle_sql(ctx, schema, &req.sql, false).await? {
match self
.handle_sql(
ctx,
schema,
&req.sql,
self.access_partition_table.enable_other,
)
.await?
{
SqlResponse::Forwarded(resp) => Ok(resp),
SqlResponse::Local(output) => convert_output(&output, self.resp_compress_min_length),
}
Expand Down Expand Up @@ -138,7 +146,12 @@ impl Proxy {
let resp_compress_min_length = self.resp_compress_min_length;
let output = self
.as_ref()
.fetch_sql_query_output(ctx, schema, &req.sql, false)
.fetch_sql_query_output(
ctx,
schema,
&req.sql,
self.access_partition_table.enable_other,
)
.await?;

match output {
Expand Down
7 changes: 6 additions & 1 deletion proxy/src/http/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ impl Proxy {
let ctx = Context::new(ctx.timeout, None);

match self
.handle_sql(&ctx, schema, &req.query, true)
.handle_sql(
&ctx,
schema,
&req.query,
self.access_partition_table.enable_http,
)
.await
.map_err(|e| {
error!("Handle sql query failed, ctx:{ctx:?}, req:{req:?}, err:{e}");
Expand Down
19 changes: 19 additions & 0 deletions proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use interpreters::{
use log::{error, info};
use query_frontend::plan::Plan;
use router::{endpoint::Endpoint, Router};
use serde::{Deserialize, Serialize};
use snafu::{OptionExt, ResultExt};
use table_engine::{
engine::{EngineRuntimes, TableState},
Expand All @@ -92,6 +93,21 @@ use crate::{
// Because the clock may have errors, choose 1 hour as the error buffer
const QUERY_EXPIRED_BUFFER: Duration = Duration::from_secs(60 * 60);

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AccessPartitionTableConfig {
pub enable_http: bool,
pub enable_other: bool,
}

impl Default for AccessPartitionTableConfig {
fn default() -> Self {
Self {
enable_http: true,
enable_other: false,
}
}
}

pub struct Proxy {
router: Arc<dyn Router + Send + Sync>,
forwarder: ForwarderRef,
Expand All @@ -102,6 +118,7 @@ pub struct Proxy {
hotspot_recorder: Arc<HotspotRecorder>,
engine_runtimes: Arc<EngineRuntimes>,
cluster_with_meta: bool,
access_partition_table: AccessPartitionTableConfig,
}

impl Proxy {
Expand All @@ -117,6 +134,7 @@ impl Proxy {
hotspot_recorder: Arc<HotspotRecorder>,
engine_runtimes: Arc<EngineRuntimes>,
cluster_with_meta: bool,
access_partition_table: AccessPartitionTableConfig,
) -> Self {
let forwarder = Arc::new(Forwarder::new(
forward_config,
Expand All @@ -134,6 +152,7 @@ impl Proxy {
hotspot_recorder,
engine_runtimes,
cluster_with_meta,
access_partition_table,
}
}

Expand Down
6 changes: 5 additions & 1 deletion server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::collections::HashMap;
use cluster::config::SchemaConfig;
use common_types::schema::TIMESTAMP_COLUMN;
use meta_client::types::ShardId;
use proxy::{forward, hotspot};
use proxy::{forward, hotspot, AccessPartitionTableConfig};
use router::{
endpoint::Endpoint,
rule_based::{ClusterView, RuleList},
Expand Down Expand Up @@ -137,6 +137,9 @@ pub struct ServerConfig {

/// Whether to deduplicate requests
pub enable_query_dedup: bool,

/// Whether enable to access partition table
pub enable_partition_table_access: AccessPartitionTableConfig,
}

impl Default for ServerConfig {
Expand All @@ -158,6 +161,7 @@ impl Default for ServerConfig {
hotspot: hotspot::Config::default(),
remote_client: remote_engine_client::Config::default(),
enable_query_dedup: false,
enable_partition_table_access: AccessPartitionTableConfig::default(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ impl Builder {
hotspot_recorder.clone(),
engine_runtimes.clone(),
self.cluster.is_some(),
self.server_config.enable_partition_table_access,
));

let http_service = http::Builder::new(http_config)
Expand Down