Skip to content

Commit 56b94ce

Browse files
authored
Fix issue where credentials from import foreign schema were lost after restarting session. Closes #504
1 parent 940d285 commit 56b94ce

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

fdw.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,21 @@ func goFdwGetRelSize(state *C.FdwPlanState, root *C.PlannerInfo, rows *C.double,
133133

134134
pluginHub := hub.GetHub()
135135

136+
// get connection name
137+
connName := GetSchemaNameFromForeignTableId(types.Oid(state.foreigntableid))
138+
139+
log.Println("[TRACE] connection name:", connName)
140+
141+
// here we are loading the server options(again) so that they are not lost after the session is restarted
142+
serverOpts := GetForeignServerOptionsFromFTableId(types.Oid(state.foreigntableid))
143+
err := pluginHub.ProcessImportForeignSchemaOptions(serverOpts, connName)
144+
if err != nil {
145+
FdwError(sperr.WrapWithMessage(err, "failed to process options"))
146+
}
147+
136148
// reload connection config
137149
// TODO remove need for fdw to load connection config
138-
_, err := pluginHub.LoadConnectionConfig()
150+
_, err = pluginHub.LoadConnectionConfig()
139151
if err != nil {
140152
log.Printf("[ERROR] LoadConnectionConfig failed %v ", err)
141153
FdwError(err)

hub/hub_local.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ func (l *HubLocal) SetConnectionConfig(connectionName, configString string) erro
6868

6969
func (l *HubLocal) UpdateConnectionConfig(connectionName, configString string) error {
7070
log.Printf("[INFO] HubLocal UpdateConnectionConfig: connection: %s, config: %s", connectionName, configString)
71+
72+
// if the connection already exists and the config is the same, do nothing
73+
// this situation could arise when a session is restarted, the server options are loaded again, and
74+
// the connection config is set again which results in the cache getting cleared
75+
if conn, ok := l.connections[connectionName]; ok && conn.Config == configString {
76+
return nil
77+
}
78+
7179
l.connections[connectionName] =
7280
&proto.ConnectionConfig{
7381
Connection: connectionName,

0 commit comments

Comments
 (0)