Skip to content

Commit

Permalink
internal/plugin+internal/plugin6: Fix provider schema caching
Browse files Browse the repository at this point in the history
Reference: #33482

The intention of this logic is to use the global provider schema cache if it is available for a given provider address based on the `GetProviderSchemaOptional` server capability. Previously the logic was errantly checking the named return early, which was not populated yet with the server response. This flips the logic to properly use the server response to determine whether the cache should be set, thereby still gating the caching based on the server capability.

In a configuration with 19 `hashicorp/aws` provider instances and an associated data source, this drops the received `GetProviderSchema` calls from 39(?) to 1. Maximum RSS dropped from 1.22 GB to 189 MB.
  • Loading branch information
bflad committed Aug 30, 2023
1 parent 12fdf1f commit a33297f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/plugin/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
defer p.mu.Unlock()

// check the global cache if we can
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
if !p.Addr.IsZero() {
if resp, ok := providers.SchemaCache.Get(p.Addr); ok {
return resp
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
}

// set the global cache if we can
if !p.Addr.IsZero() {
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
providers.SchemaCache.Set(p.Addr, resp)
}

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

// check the global cache if we can
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
if !p.Addr.IsZero() {
if resp, ok := providers.SchemaCache.Get(p.Addr); ok {
return resp
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
}

// set the global cache if we can
if !p.Addr.IsZero() {
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
providers.SchemaCache.Set(p.Addr, resp)
}

Expand Down

0 comments on commit a33297f

Please sign in to comment.