Skip to content

Commit

Permalink
Add additional log messages and javadoc around reads (apache#29640)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielm authored and JayajP committed Dec 27, 2023
1 parent 482ec84 commit 8edf57c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ public void processElement(ProcessContext c) throws Exception {
}
} catch (SpannerException e) {
serviceCallMetric.call(e.getErrorCode().getGrpcStatusCode().toString());
LOG.error("Error while processing element", e);
LOG.error(
"Error while reading partition for operation: " + op.getReadOperation().toString(), e);
throw (e);
}
serviceCallMetric.call("ok");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.apache.beam.sdk.values.PCollectionView;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** A naive version of Spanner read that doesn't use the Batch API. */
@VisibleForTesting
Expand All @@ -44,6 +46,8 @@
abstract class NaiveSpannerRead
extends PTransform<PCollection<ReadOperation>, PCollection<Struct>> {

private static final Logger LOG = LoggerFactory.getLogger(NaiveSpannerRead.class);

public static NaiveSpannerRead create(
SpannerConfig spannerConfig,
PCollectionView<Transaction> txView,
Expand Down Expand Up @@ -109,6 +113,7 @@ public void processElement(ProcessContext c) throws Exception {
}
} catch (SpannerException e) {
serviceCallMetric.call(e.getErrorCode().getGrpcStatusCode().toString());
LOG.error("Error while reading operation: " + op.toString(), e);
throw (e);
}
serviceCallMetric.call("ok");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ abstract static class Builder {

abstract Builder setKeySet(KeySet keySet);

/**
* Note: {@link PartitionOptions} are currently ignored. See <a
* href="https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.PartitionOptions">
* PartitionOptions in RPC documents</a>
*/
abstract Builder setPartitionOptions(PartitionOptions partitionOptions);

abstract ReadOperation build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,11 @@ public Read withIndex(String index) {
return withReadOperation(getReadOperation().withIndex(index));
}

/**
* Note that {@link PartitionOptions} are currently ignored. See <a
* href="https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.PartitionOptions">
* PartitionOptions in RPC documents</a>
*/
public Read withPartitionOptions(PartitionOptions partitionOptions) {
return withReadOperation(getReadOperation().withPartitionOptions(partitionOptions));
}
Expand Down Expand Up @@ -2165,6 +2170,7 @@ public void processElement(ProcessContext c) throws Exception {
// fall through and retry individual mutationGroups.
} else if (failureMode == FailureMode.FAIL_FAST) {
mutationGroupsWriteFail.inc(mutations.size());
LOG.error("Failed to write a batch of mutation groups", e);
throw e;
} else {
throw new IllegalArgumentException("Unknown failure mode " + failureMode);
Expand Down

0 comments on commit 8edf57c

Please sign in to comment.