Skip to content

Commit 2c54371

Browse files
committed
add settings
1 parent 8854254 commit 2c54371

6 files changed

Lines changed: 41 additions & 14 deletions

File tree

src/query/service/tests/it/storages/system.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ async fn test_system_columns_tolerates_broken_attached_table() -> anyhow::Result
663663
let catalog = ctx.get_catalog("default").await?;
664664
let database = catalog.get_database(&tenant, "default").await?;
665665

666+
// ATTACH schema refresh is opt-in; enable it so the resilience path under test is exercised.
667+
ctx.get_settings()
668+
.set_setting("enable_table_schema_refresh".to_string(), "1".to_string())?;
669+
666670
execute_command(ctx.clone(), "create table default.healthy(a int)").await?;
667671

668672
// Simulate a broken attached-table storage: any refresh from this S3 endpoint fails with 403.
@@ -739,4 +743,3 @@ async fn test_system_columns_tolerates_broken_attached_table() -> anyhow::Result
739743

740744
Ok(())
741745
}
742-

src/query/settings/src/settings_default.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,13 @@ impl DefaultSettings {
11211121
scope: SettingScope::Both,
11221122
range: Some(SettingRange::Numeric(0..=1)),
11231123
}),
1124+
("enable_table_schema_refresh", DefaultSettingValue {
1125+
value: UserSettingValue::UInt64(0),
1126+
desc: "Refresh table schema from storage when listing system.columns/statistics, so schema changes invisible to the meta server (currently only read-only ATTACH tables) are reflected. Disabled by default; each refreshed table costs one storage round-trip.",
1127+
mode: SettingMode::Both,
1128+
scope: SettingScope::Both,
1129+
range: Some(SettingRange::Numeric(0..=1)),
1130+
}),
11241131
("enable_experimental_row_access_policy", DefaultSettingValue {
11251132
value: UserSettingValue::UInt64(0),
11261133
desc: "experiment setting enable row access policy(disable by default).",

src/query/settings/src/settings_getter_setter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ impl Settings {
197197
Ok(self.try_get_u64("enable_auto_fix_missing_bloom_index")? != 0)
198198
}
199199

200+
pub fn get_enable_table_schema_refresh(&self) -> Result<bool> {
201+
Ok(self.try_get_u64("enable_table_schema_refresh")? != 0)
202+
}
203+
200204
// Get max_block_size.
201205
pub fn get_max_block_size(&self) -> Result<u64> {
202206
self.try_get_u64("max_block_size")

src/query/storages/system/src/columns_table.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,31 @@ pub(crate) async fn dump_tables(
279279
let (filtered_db_names, filtered_table_names) = extract_filters(&push_downs, &func_ctx)?;
280280

281281
// Use unified visibility collection from util.rs
282-
let db_with_tables =
283-
collect_visible_tables(ctx, &disabled_catalog, &filtered_db_names, &filtered_table_names)
284-
.await?;
282+
let db_with_tables = collect_visible_tables(
283+
ctx,
284+
&disabled_catalog,
285+
&filtered_db_names,
286+
&filtered_table_names,
287+
)
288+
.await?;
285289

286290
// A read-only ATTACH table keeps its current schema in the source snapshot, not on the meta
287-
// server, so the disabled catalog above hands back the schema frozen at ATTACH time. Refresh
288-
// each one through the original catalog to pick up source schema changes; a failure here must
289-
// not drop sibling tables, so fall back to the cached handle.
291+
// server, so the disabled catalog above hands back the schema frozen at ATTACH time. Refreshing
292+
// each one through the original catalog picks up source schema changes, but costs one S3
293+
// round-trip per ATTACH table, so it is opt-in via enable_table_schema_refresh. A refresh
294+
// failure must not drop sibling tables, so fall back to the cached handle.
295+
let refresh = ctx.get_settings().get_enable_table_schema_refresh()?;
290296
Ok(db_with_tables
291297
.into_iter()
292298
.map(|db| {
293-
let tables = db
294-
.tables
295-
.into_iter()
296-
.map(|table| refresh_attach_table(catalog, table))
297-
.collect();
299+
let tables = if refresh {
300+
db.tables
301+
.into_iter()
302+
.map(|table| refresh_attach_table(catalog, table))
303+
.collect()
304+
} else {
305+
db.tables
306+
};
298307
(db.name, tables)
299308
})
300309
.collect())

tests/suites/5_ee/04_attach_read_only/02_0005_attach_table_read_only.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ c1 VARCHAR NO 'c1'
2323
c2 VARCHAR NO 'c2'
2424
expects one row, 3 columns
2525
0 c1 c2
26+
system.columns hides source-side added columns when refresh is disabled (default)
27+
number
2628
system.columns should reflect the added columns
2729
c1
2830
c2

tests/suites/5_ee/04_attach_read_only/02_0005_attach_table_read_only.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ echo "desc attach_read_only;" | $BENDSQL_CLIENT_CONNECT
4949
echo "expects one row, 3 columns"
5050
echo "select * from attach_read_only order by number;" | $BENDSQL_CLIENT_CONNECT
5151

52-
echo "system.columns should reflect the added columns"
52+
echo "system.columns hides source-side added columns when refresh is disabled (default)"
5353
echo "select name from system.columns where database='default' and table='attach_read_only' order by name;" | $BENDSQL_CLIENT_CONNECT
54+
echo "system.columns should reflect the added columns"
55+
echo "set enable_table_schema_refresh=1; select name from system.columns where database='default' and table='attach_read_only' order by name;" | $BENDSQL_CLIENT_CONNECT
5456
echo "information_schema.columns should reflect the added columns"
55-
echo "select column_name from information_schema.columns where table_schema='default' and table_name='attach_read_only' order by column_name;" | $BENDSQL_CLIENT_CONNECT
57+
echo "set enable_table_schema_refresh=1; select column_name from information_schema.columns where table_schema='default' and table_name='attach_read_only' order by column_name;" | $BENDSQL_CLIENT_CONNECT
5658

5759

5860
echo "alter table drop column"

0 commit comments

Comments
 (0)