Skip to content

Commit

Permalink
STREAM-166: make CDC delete single threaded (#288)
Browse files Browse the repository at this point in the history
CDC delete operation should also be single threaded similar to enable.
  • Loading branch information
pgier authored Aug 15, 2023
1 parent fc9f9af commit 5f41462
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/provider/resource_cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func resourceCDC() *schema.Resource {
}
}

// cdcDisableMutex forces only a one CDC disable at a time to prevent most concurrency issues
var cdcDisableMutex sync.Mutex

func resourceCDCDelete(ctx context.Context, resourceData *schema.ResourceData, meta interface{}) diag.Diagnostics {
streamingClient := meta.(astraClients).astraStreamingClient.(*astrastreaming.ClientWithResponses)
client := meta.(astraClients).astraClient.(*astra.ClientWithResponses)
Expand Down Expand Up @@ -129,6 +132,10 @@ func resourceCDCDelete(ctx context.Context, resourceData *schema.ResourceData, m
TableName: table,
TopicPartitions: resourceData.Get("topic_partitions").(int),
}

cdcDisableMutex.Lock()
defer cdcDisableMutex.Unlock()

getDeleteCDCResponse, err := streamingClientv3.DeleteCDC(ctx, tenantName, &deleteCDCParams, deleteRequestBody)

if err != nil {
Expand All @@ -139,11 +146,15 @@ func resourceCDCDelete(ctx context.Context, resourceData *schema.ResourceData, m
return diag.Errorf("Error deleting cdc %s", body)
}

// We don't have a good way to verify that the delete operation completed, so just wait a few seconds
// before the next delete is performed.
const cdcDeleteWaitTime = time.Second * 3
time.Sleep(cdcDeleteWaitTime)

// Deleted. Remove from state.
resourceData.SetId("")

return nil

}

type CDCStatusResponse []CDCStatus
Expand Down

0 comments on commit 5f41462

Please sign in to comment.