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

fix(bigquery/storage/managedwriter): fix incorrect error retention #6659

Merged
merged 3 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions bigquery/storage/managedwriter/managed_stream.go
Expand Up @@ -358,11 +358,8 @@ func (ms *ManagedStream) appendWithRetry(pw *pendingWrite, opts ...gax.CallOptio
}
continue
}
// We've got a non-retriable error, so propagate that up. and mark the write done.
ms.mu.Lock()
ms.err = appendErr
// Mark the pending write done. This will not be returned to the user, they'll receive the returned error.
pw.markDone(nil, appendErr, ms.fc)
ms.mu.Unlock()
return appendErr
}
recordStat(ms.ctx, AppendRequests, 1)
Expand Down
39 changes: 39 additions & 0 deletions bigquery/storage/managedwriter/managed_stream_test.go
Expand Up @@ -300,7 +300,46 @@ func TestManagedStream_AppendWithDeadline(t *testing.T) {
if ct := ms.fc.count(); ct != wantCount {
t.Errorf("flowcontroller post-append count mismatch, got %d want %d", ct, wantCount)
}
}

func TestManagedStream_ContextExpiry(t *testing.T) {
// Issue: retaining error from append as stream error
// https://github.com/googleapis/google-cloud-go/issues/6657
ctx := context.Background()

ms := &ManagedStream{
ctx: ctx,
streamSettings: defaultStreamSettings(),
fc: newFlowController(0, 0),
open: openTestArc(&testAppendRowsClient{},
func(req *storagepb.AppendRowsRequest) error {
// Append is intentionally slow.
return nil
}, nil),
}
ms.schemaDescriptor = &descriptorpb.DescriptorProto{
Name: proto.String("testDescriptor"),
}
fakeData := [][]byte{
[]byte("foo"),
}

// Create a context and immediately cancel it.
cancelCtx, cancel := context.WithCancel(ctx)
cancel()

// First, append with an invalid context.
pw := newPendingWrite(cancelCtx, fakeData)
err := ms.appendWithRetry(pw)
if err != context.Canceled {
t.Errorf("expected cancelled context error, got: %v", err)
}

// a second append with a valid context should succeed
_, err = ms.AppendRows(ctx, fakeData)
if err != nil {
t.Errorf("expected second append to succeed, but failed: %v", err)
}
}

func TestManagedStream_AppendDeadlocks(t *testing.T) {
Expand Down