Skip to content

Commit

Permalink
[Snowflake] Don't wait to merge when auth expires (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 authored Jul 29, 2023
1 parent d76320e commit 4107d05
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion clients/snowflake/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ func (s *Store) GetConfigMap() *types.DwhToTablesConfigMap {
func (s *Store) Merge(ctx context.Context, tableData *optimization.TableData) error {
err := s.mergeWithStages(ctx, tableData)
if AuthenticationExpirationErr(err) {
logger.FromContext(ctx).WithError(err).Warn("authentication has expired, will reload the Snowflake store")
logger.FromContext(ctx).WithError(err).Warn("authentication has expired, will reload the Snowflake store and retry merging")
s.ReestablishConnection(ctx)
return s.Merge(ctx, tableData)
}

return err
Expand Down
9 changes: 3 additions & 6 deletions clients/snowflake/snowflake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,11 @@ func (s *SnowflakeTestSuite) TestExecuteMergeReestablishAuth() {

s.fakeStageStore.ExecReturnsOnCall(0, nil, fmt.Errorf("390114: Authentication token has expired. The user must authenticate again."))
err := s.stageStore.Merge(s.ctx, tableData)
assert.True(s.T(), AuthenticationExpirationErr(err), err)

s.fakeStageStore.ExecReturnsOnCall(1, nil, nil)
assert.Nil(s.T(), s.stageStore.Merge(s.ctx, tableData))
s.fakeStageStore.ExecReturns(nil, nil)
assert.NoError(s.T(), err, "transient errors like auth errors will be retried")

// 5 regular ones and then 1 additional one to re-establish auth.
assert.Equal(s.T(), s.fakeStageStore.ExecCallCount(), 6, "called merge")
baseline := 5
assert.Equal(s.T(), s.fakeStageStore.ExecCallCount(), baseline+1, "called merge")
}

func (s *SnowflakeTestSuite) TestExecuteMerge() {
Expand Down

0 comments on commit 4107d05

Please sign in to comment.