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

Feature: add redshift extension #301

Merged
merged 12 commits into from
Sep 13, 2023
Merged

Feature: add redshift extension #301

merged 12 commits into from
Sep 13, 2023

Conversation

cyyeh
Copy link
Member

@cyyeh cyyeh commented Sep 11, 2023

Description

Basically, the PR content is the same as the closed one #297. However, I updated the content based on code review feedback from @kokokuo

Issue ticket number

None

Additional Context

@vercel
Copy link

vercel bot commented Sep 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vulcan-sql-document ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 13, 2023 3:41am

@cyyeh cyyeh changed the title add redshift extension Feature: add redshift extension Sep 11, 2023
this.logger.debug(
`Errors occurred, release connection from ${profileName}`
);
redshiftClient.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does .destory function here close the connection? We might reuse these clients so we should not close connections when error occurs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've deleted .destroy function


// definition of describeStatementResponse.Status
// https://github.com/aws/aws-sdk-js-v3/blob/29056f4ca545f7e5cf951b915bb52178305fc305/clients/client-redshift-data/src/models/models_0.ts#L604
while (!describeStatementResponse || describeStatementResponse.Status !== 'FINISHED') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add some exponential backoffs while polling status.

Copy link
Member Author

@cyyeh cyyeh Sep 12, 2023

Choose a reason for hiding this comment

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

I added this package to enable exponential backoff.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I meant we can break between sending requests to avoid exceeding AWS API rate limiting. But I think your approach is okay, we'll retry automatically when the API returns an error.

  while (!describeStatementResponse || describeStatementResponse.Status !== 'FINISHED') {
      const describeStatementCommand = new DescribeStatementCommand(describeStatementRequestInput);
      describeStatementResponse = await redshiftClient.send(describeStatementCommand)

      if (
        describeStatementResponse.Status === 'ABORTED' || 
        describeStatementResponse.Status === 'FAILED'
      ) {
        throw describeStatementResponse.Error
      }

      // Sleep here before the next iteration
    }

"Id": describeStatementResponse.Id
};
const getStatementResultCommand = new GetStatementResultCommand(getStatementResultCommandParams);
const getStatementResultResponse = await redshiftClient.send(getStatementResultCommand);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the result might return in batches, we ought to handle the NextToken of the response, store the token then fetch the next chunk data when we get request from downstream might be a good idea.

new Readable({
...
 read() {
   if(nextToken) { 
      // GetStatementResultCommand with nextToken
   }
 }
})

Copy link
Member Author

Choose a reason for hiding this comment

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

I've handled the NextToken condition at line 155.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, we won't lose data in this way.
If we encounter performance issues in the future, we could consider taking backpressure in Node.js streams into account~

@oscar60310
Copy link
Contributor

I have no further issues, many thanks!

@codecov
Copy link

codecov bot commented Sep 13, 2023

Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

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

Thanks @oscar60310 for reviewing! ❤️
Thanks for fixing the test case issue, LGTM 👍

@kokokuo kokokuo merged commit 9de213f into develop Sep 13, 2023
6 checks passed
@kokokuo kokokuo deleted the feature/add-redshift branch September 13, 2023 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants