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

always set schema caches from provider clients #33543

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 8 additions & 5 deletions internal/plugin/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
defer p.mu.Unlock()

// check the global cache if we can
if !p.Addr.IsZero() {
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks the caching. resp is the zero value, i.e. GetProviderSchemaOptional is always false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is intentional. Caching via GetProviderSchemaOptional must be opt-in to maintain current behavior with existing provider releases.

if resp, ok := providers.SchemaCache.Get(p.Addr); ok {
return resp
}
}

// If the local cache is non-zero, we know this instance has called
// GetProviderSchema at least once and we can return early.
if p.schema.Provider.Block != nil {
return p.schema
}
Expand Down Expand Up @@ -139,13 +141,14 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
}

// set the global cache if we can
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
if !p.Addr.IsZero() {
providers.SchemaCache.Set(p.Addr, resp)
} else {
// otherwise store it in the local cache
p.schema = resp
}

// always store this here in the client for providers that are not able to
// use GetProviderSchemaOptional
p.schema = resp

return resp
}

Expand Down
13 changes: 8 additions & 5 deletions internal/plugin6/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
defer p.mu.Unlock()

// check the global cache if we can
if !p.Addr.IsZero() {
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
if resp, ok := providers.SchemaCache.Get(p.Addr); ok {
return resp
}
}

// If the local cache is non-zero, we know this instance has called
// GetProviderSchema at least once and we can return early.
if p.schema.Provider.Block != nil {
return p.schema
}
Expand Down Expand Up @@ -139,13 +141,14 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
}

// set the global cache if we can
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
if !p.Addr.IsZero() {
providers.SchemaCache.Set(p.Addr, resp)
} else {
// otherwise store it in the local cache
p.schema = resp
}

// always store this here in the client for providers that are not able to
// use GetProviderSchemaOptional
p.schema = resp

return resp
}

Expand Down