-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(glue-alpha): race condition when creating mutiple indices #38016
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3e72ffe
fix(glue-alpha): fix partition index race condition when creating mul…
invalid-email-address c046164
remove ray snapshots
Abogical f9ad55b
restore accidentally deleted base-path-mapping snapshot
Abogical 0fa1b0d
fix: wrong assertions used in integ test.
Abogical 797aa8c
merge from main
otaviomacedo 1a41999
check existing partition indexes
otaviomacedo 87b8de4
bring back files and just delete when the index has disappeared
otaviomacedo 8b0be22
Add unit tests for the handler
otaviomacedo e194313
bundle dependency
otaviomacedo 55974fd
deduplicate grants
otaviomacedo bfc5945
Add bundling script for partition index handler and update dependencies
otaviomacedo 241b199
Updated snapshots
otaviomacedo fb88275
token validation, unique id
otaviomacedo 40c78c7
bundled js
otaviomacedo 3d96f57
reduce timeout
otaviomacedo 9f0a125
Merge branch 'main' into glue-fix-partition-index
otaviomacedo e10de05
update snapshots
otaviomacedo c250d25
update snapshots
otaviomacedo 62bfd24
new pkglint rule, snapshot update
otaviomacedo 944a70c
timeout
otaviomacedo 132c295
handling edge cases around create
otaviomacedo e785556
unique ids in case of tokens
otaviomacedo 6e0f924
key order-sensitive comparison
otaviomacedo 7217077
improvements to the state machine
otaviomacedo d84717b
Simplifications
otaviomacedo da247a7
handle ResourceNumberLimitExceededException
otaviomacedo 0c74d8d
handle ResourceNumberLimitExceededException
otaviomacedo 3cdffed
update test
otaviomacedo 93f990f
Merge branch 'main' into glue-fix-partition-index
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/@aws-cdk/aws-glue-alpha/lib/partition-index-handler/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // eslint-disable-next-line import/no-extraneous-dependencies | ||
| import { GlueClient, CreatePartitionIndexCommand, DeletePartitionIndexCommand, GetPartitionIndexesCommand } from '@aws-sdk/client-glue'; | ||
|
|
||
| class PartitionIndexError extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| this.name = 'PartitionIndexError'; | ||
| } | ||
| } | ||
|
|
||
| const glue = new GlueClient({}); | ||
|
|
||
| export async function onEvent(event: any) { | ||
| const { DatabaseName, TableName, IndexName, Keys } = event.ResourceProperties; | ||
|
|
||
| if (event.RequestType === 'Create') { | ||
| await glue.send(new CreatePartitionIndexCommand({ | ||
| DatabaseName, | ||
| TableName, | ||
| PartitionIndex: { IndexName, Keys }, | ||
| })); | ||
| return { PhysicalResourceId: IndexName }; | ||
| } else if (event.RequestType === 'Update') { | ||
| const oldKeys = event.OldResourceProperties?.Keys; | ||
| if (JSON.stringify(oldKeys) !== JSON.stringify(Keys)) { | ||
| // For auto-generated index names, this should be unreachable. CDK derives index names from keys, so key changes always produce a new resource | ||
| throw new PartitionIndexError('Partition index keys cannot be updated. Delete and recreate the index instead.'); | ||
| } | ||
| return { PhysicalResourceId: IndexName }; | ||
| } else if (event.RequestType === 'Delete') { | ||
| try { | ||
| await glue.send(new DeletePartitionIndexCommand({ | ||
| DatabaseName, | ||
| TableName, | ||
| IndexName, | ||
| })); | ||
| } catch (e: any) { | ||
| if (e.name === 'EntityNotFoundException') { | ||
| // eslint-disable-next-line no-console | ||
| console.log(`Partition index ${IndexName} not found on ${DatabaseName}.${TableName} - may have been deleted out-of-band`); | ||
| } else { | ||
| throw e; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| export async function isComplete(event: any) { | ||
| const { DatabaseName, TableName, IndexName } = event.ResourceProperties; | ||
|
|
||
| if (event.RequestType === 'Delete') { | ||
| const resp = await glue.send(new GetPartitionIndexesCommand({ DatabaseName, TableName })); | ||
|
otaviomacedo marked this conversation as resolved.
Outdated
|
||
| const index = (resp.PartitionIndexDescriptorList || []).find( | ||
| (i) => i.IndexName!.toLowerCase() === IndexName.toLowerCase(), | ||
| ); | ||
| if (!index || index.IndexStatus !== 'DELETING') { | ||
| return { IsComplete: true }; | ||
| } | ||
| return { IsComplete: false }; | ||
| } | ||
|
|
||
| const resp = await glue.send(new GetPartitionIndexesCommand({ DatabaseName, TableName })); | ||
| // Glue lowercases index names, so compare case-insensitively | ||
| const index = (resp.PartitionIndexDescriptorList || []).find( | ||
| (i) => i.IndexName!.toLowerCase() === IndexName.toLowerCase(), | ||
| ); | ||
|
|
||
| if (!index) return { IsComplete: false }; | ||
| if (index.IndexStatus === 'ACTIVE') return { IsComplete: true }; | ||
| if (index.IndexStatus === 'CREATING') return { IsComplete: false }; | ||
|
|
||
| const errorDetails = index.BackfillErrors?.length | ||
| ? ` Backfill errors: ${JSON.stringify(index.BackfillErrors)}` | ||
| : ''; | ||
| throw new PartitionIndexError(`Partition index ${IndexName} in unexpected state: ${index.IndexStatus}.${errorDetails}`); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...@aws-cdk/aws-glue-alpha/test/integ.connection.js.snapshot/aws-glue-connection.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.