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: stop append when writer is in shutdown state. #840

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ private void setException(Throwable t) {
* @return the message ID wrapped in a future.
*/
public ApiFuture<AppendRowsResponse> append(AppendRowsRequest message) {
if (shutdown.get()) {
throw new IllegalStateException("Cannot append to a shutdown writer");
}
appendAndRefreshAppendLock.lock();
Preconditions.checkState(!shutdown.get(), "Cannot append on a shut-down writer.");
Preconditions.checkNotNull(message, "Message is null.");
Expand Down Expand Up @@ -284,14 +287,9 @@ public ApiFuture<AppendRowsResponse> append(AppendRowsRequest message) {
* @throws Exception
*/
public void flushAll(long timeoutMillis) throws Exception {
appendAndRefreshAppendLock.lock();
try {
writeAllOutstanding();
synchronized (messagesWaiter) {
messagesWaiter.waitComplete(timeoutMillis);
}
} finally {
appendAndRefreshAppendLock.unlock();
writeAllOutstanding();
synchronized (messagesWaiter) {
messagesWaiter.waitComplete(timeoutMillis);
}
exceptionLock.lock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,4 +1049,28 @@ public void testShutdownWithConnectionError() throws Exception {
assertEquals("Request aborted due to previous failures", e.getCause().getMessage());
}
}

@Test
public void testAppendAfterShutdown() throws Exception {
StreamWriter writer =
getTestStreamWriterBuilder()
.setBatchingSettings(
StreamWriter.Builder.DEFAULT_BATCHING_SETTINGS
.toBuilder()
.setElementCountThreshold(1L)
.build())
.build();
testBigQueryWrite.addResponse(
AppendRowsResponse.newBuilder()
.setAppendResult(
AppendRowsResponse.AppendResult.newBuilder().setOffset(Int64Value.of(1)).build())
.build());
writer.shutdown();
try {
ApiFuture<AppendRowsResponse> appendFuture1 = sendTestMessage(writer, new String[] {"A"});
fail("Should fail with exception");
} catch (IllegalStateException e) {
assertEquals("Cannot append to a shutdown writer", e.getMessage());
}
}
}