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

Retriable error #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -15,9 +15,13 @@
*/
package com.google.cloud.teleport.v2.templates.transforms;

import com.datastax.oss.driver.api.core.DriverException;
import com.datastax.oss.driver.api.core.DriverExecutionException;
import com.datastax.oss.driver.api.core.DriverTimeoutException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.nosan.embedded.cassandra.CassandraException;
import com.google.cloud.spanner.Mutation;
import com.google.cloud.spanner.SpannerException;
import com.google.cloud.teleport.v2.spanner.ddl.Ddl;
Expand Down Expand Up @@ -56,6 +60,7 @@
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.values.KV;
import org.apache.beam.sdk.values.TupleTag;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -251,12 +256,37 @@ public void processElement(ProcessContext c) {
outputWithTag(c, Constants.PERMANENT_ERROR_TAG, ex.getMessage(), spannerRec);
}
} catch (Exception ex) {
handleExceptions(ex, c, spannerRec);
LOG.error("Failed to write to source", ex);
// outputWithTag(c, Constants.PERMANENT_ERROR_TAG, ex.getMessage(), spannerRec);
}
}
}

private void handleExceptions(Exception ex, ProcessContext c, TrimmedShardedDataChangeRecord spannerRec) {
if (ex instanceof DriverException) {
LOG.error("Cassandra-related exception occurred: ", ex);
if (isRetryableCassandraError((com.datastax.driver.core.exceptions.DriverException) ex)) {
outputWithTag(c, Constants.RETRYABLE_ERROR_TAG, ex.getMessage(), spannerRec);
retryableRecordCountMetric.inc();
} else {
outputWithTag(c, Constants.PERMANENT_ERROR_TAG, ex.getMessage(), spannerRec);
}
} else {
LOG.error("Unexpected exception while writing to source", ex);
outputWithTag(c, Constants.PERMANENT_ERROR_TAG, ex.getMessage(), spannerRec);
}
}

private boolean isRetryableCassandraError(com.datastax.driver.core.exceptions.DriverException ex) {
return ex instanceof com.datastax.driver.core.exceptions.NoHostAvailableException ||
ex instanceof com.datastax.driver.core.exceptions.UnavailableException ||
ex instanceof com.datastax.driver.core.exceptions.ReadTimeoutException ||
ex instanceof com.datastax.driver.core.exceptions.WriteTimeoutException ||
ex instanceof com.datastax.driver.core.exceptions.OverloadedException ||
ex instanceof com.datastax.driver.core.exceptions.OperationTimedOutException;
}

private Mutation getShadowTableMutation(
String tableName,
String shadowTableName,
Expand Down
Loading