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: handle immediate append error #8

Merged
merged 1 commit into from
Nov 29, 2023
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.
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
@@ -1,6 +1,7 @@
package com.vinted.flink.bigquery.sink.buffered;

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.bigquery.storage.v1.AppendRowsResponse;
import com.google.cloud.bigquery.storage.v1.JsonStreamWriter;
import com.google.protobuf.Descriptors;
Expand All @@ -26,8 +27,8 @@ protected ApiFuture<AppendRowsResponse> append(String traceId, Rows<A> rows) {

try {
return streamWriter(traceId, rows.getStream(), rows.getTable()).append(rowArray, rows.getOffset());
} catch (IOException | Descriptors.DescriptorValidationException e) {
throw new RuntimeException(e);
} catch (Throwable t) {
return ApiFutures.immediateFailedFuture(t);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vinted.flink.bigquery.sink.buffered;

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.bigquery.storage.v1.AppendRowsResponse;
import com.google.cloud.bigquery.storage.v1.ProtoRows;
import com.google.cloud.bigquery.storage.v1.StreamWriter;
Expand Down Expand Up @@ -39,6 +40,11 @@ protected ApiFuture<AppendRowsResponse> append(String traceId, Rows<A> rows) {

logger.trace("Trace-id {}, Writing rows stream {} to steamWriter for {} writer id {}", traceId, rows.getStream(), writer.getStreamName(), writer.getWriterId());

return writer.append(prows, rows.getOffset());
try {
return writer.append(prows, rows.getOffset());
} catch (Throwable t) {
logger.error("Trace-id {}, StreamWriter failed to append {}", traceId, t.getMessage());
return ApiFutures.immediateFailedFuture(t);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vinted.flink.bigquery.sink.defaultStream;

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.bigquery.storage.v1.AppendRowsResponse;
import com.google.cloud.bigquery.storage.v1.JsonStreamWriter;
import com.google.protobuf.Descriptors;
Expand Down Expand Up @@ -36,9 +37,9 @@ protected ApiFuture<AppendRowsResponse> append(String traceId, Rows<A> rows) {

try {
return writer.append(rowArray);
} catch (IOException | Descriptors.DescriptorValidationException e) {
logger.error("Trace-id {}, StreamWriter failed to append {}", traceId, e.getMessage());
throw new RuntimeException(e);
} catch (Throwable t) {
logger.error("Trace-id {}, StreamWriter failed to append {}", traceId, t.getMessage());
return ApiFutures.immediateFailedFuture(t);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vinted.flink.bigquery.sink.defaultStream;

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.bigquery.storage.v1.AppendRowsResponse;
import com.google.cloud.bigquery.storage.v1.ProtoRows;
import com.google.cloud.bigquery.storage.v1.StreamWriter;
Expand Down Expand Up @@ -44,6 +45,11 @@ protected ApiFuture<AppendRowsResponse> append(String traceId, Rows<A> rows) {
}

logger.trace("Trace-id {}, Writing rows stream {} to steamWriter for {} writer id {}", traceId, rows.getStream(), writer.getStreamName(), writer.getWriterId());
return writer.append(prows);
try {
return writer.append(prows);
} catch (Throwable t) {
logger.error("Trace-id {}, StreamWriter failed to append {}", traceId, t.getMessage());
return ApiFutures.immediateFailedFuture(t);
}
}
}