Skip to content

Commit 62909f2

Browse files
authored
fix:add server_id system variable for odbc (#23578)
Adds the missing server_id system variable to MatrixOne so ODBC clients can read @@server_id during connection initialization without error. Also adds regression coverage in the distributed system variable tests. This prevents Tableau/ODBC connections from failing with “system variable does not exist.” Approved by: @fengttt, @heni02, @XuPeng-SH
1 parent 3dce54a commit 62909f2

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

pkg/frontend/variables.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,18 @@ func useTomlConfigOverOtherConfigs(CNServiceConfig *config.FrontendParameters, s
970970
sysVarsMp["version"] = verPrefix + verVal
971971
}
972972

973+
func resolveServerID(ses *Session) string {
974+
if ses == nil {
975+
return ""
976+
}
977+
rm := ses.getRoutineManager()
978+
if rm == nil || rm.baseService == nil {
979+
return ""
980+
}
981+
serviceID := rm.baseService.ID()
982+
return serviceID
983+
}
984+
973985
// Get return sys vars of accountId
974986
func (m *GlobalSysVarsMgr) Get(accountId uint32, ses *Session, ctx context.Context, bh BackgroundExec) (*SystemVariables, error) {
975987
sysVarsMp, err := ses.getGlobalSysVars(ctx, bh)
@@ -979,6 +991,7 @@ func (m *GlobalSysVarsMgr) Get(accountId uint32, ses *Session, ctx context.Conte
979991

980992
CNServiceConfig := getPu(ses.service).SV
981993
useTomlConfigOverOtherConfigs(CNServiceConfig, sysVarsMp)
994+
sysVarsMp["server_id"] = resolveServerID(ses)
982995

983996
m.Lock()
984997
defer m.Unlock()
@@ -1069,6 +1082,14 @@ var gSysVarsDefs = map[string]SystemVariable{
10691082
Type: InitSystemVariableStringType("version_comment"),
10701083
Default: "MatrixOne",
10711084
},
1085+
"server_id": {
1086+
Name: "server_id",
1087+
Scope: ScopeGlobal,
1088+
Dynamic: false,
1089+
SetVarHintApplies: false,
1090+
Type: InitSystemVariableStringType("server_id"),
1091+
Default: "",
1092+
},
10721093
"tx_isolation": {
10731094
Name: "tx_isolation",
10741095
Scope: ScopeBoth,

test/distributed/cases/system_variable/system_variables.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ set max_allowed_packet = default;
66
set wait_timeout = default;
77
set tx_isolation = default;
88
set tx_isolation = default;
9+
show variables like 'server_id';
10+
Variable_name Value
11+
server_id uuid
12+
select @@server_id;
13+
@@server_id
14+
uuid
915
show variables like 'auto%';
1016
Variable_name Value
1117
auto_generate_certs on

test/distributed/cases/system_variable/system_variables.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ set max_allowed_packet = default;
1111
set wait_timeout = default;
1212
set tx_isolation = default;
1313
set tx_isolation = default;
14+
-- @ignore:1
15+
show variables like 'server_id';
16+
-- @ignore:0
17+
select @@server_id;
1418

1519

1620
-- auto_increment_increment

0 commit comments

Comments
 (0)