Skip to content

Commit

Permalink
fix(mirrormaker_replication_flow): race on create/update/delete opera… (
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov authored Dec 13, 2023
1 parent 5ebb9a3 commit 268e12f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ nav_order: 1

## [X.Y.Z] - YYYY-MM-DD

## [4.9.4] - 2023-12-13

- Fix race issues with `aiven_mirrormaker_replication_flow` on create/update/delete operations

## [4.9.3] - 2023-10-27

- Deprecating `project_user`, `account_team` and `account_team_member` resources
Expand Down
13 changes: 13 additions & 0 deletions internal/sdkprovider/service/kafka/mirrormaker_replication_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kafka

import (
"context"
"sync"

"github.com/aiven/aiven-go-client/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -13,6 +14,9 @@ import (
)

var (
// lockReplicationFlow a lock for any "write" operations.
// todo: remove the lock when API race is fixed
lockReplicationFlow = sync.Mutex{}
defaultReplicationPolicy = "org.apache.kafka.connect.mirror.DefaultReplicationPolicy"

replicationPolicies = []string{
Expand Down Expand Up @@ -111,6 +115,9 @@ func ResourceMirrorMakerReplicationFlow() *schema.Resource {
}

func resourceMirrorMakerReplicationFlowCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lockReplicationFlow.Lock()
defer lockReplicationFlow.Unlock()

client := m.(*aiven.Client)

project := d.Get("project").(string)
Expand Down Expand Up @@ -193,6 +200,9 @@ func resourceMirrorMakerReplicationFlowRead(ctx context.Context, d *schema.Resou
}

func resourceMirrorMakerReplicationFlowUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lockReplicationFlow.Lock()
defer lockReplicationFlow.Unlock()

client := m.(*aiven.Client)

project, serviceName, sourceCluster, targetCluster, err := schemautil.SplitResourceID4(d.Id())
Expand Down Expand Up @@ -227,6 +237,9 @@ func resourceMirrorMakerReplicationFlowUpdate(ctx context.Context, d *schema.Res
}

func resourceMirrorMakerReplicationFlowDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
lockReplicationFlow.Lock()
defer lockReplicationFlow.Unlock()

client := m.(*aiven.Client)

project, serviceName, sourceCluster, targetCluster, err := schemautil.SplitResourceID4(d.Id())
Expand Down

0 comments on commit 268e12f

Please sign in to comment.