Skip to content

Commit 6de2b89

Browse files
committed
Propagate requestId into some more SpannerException values
1 parent 35481f6 commit 6de2b89

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ private List<Partition> partitionReadUsingIndex(
274274
return partitionReadUsingIndex(
275275
partitionOptions, table, index, keys, columns, true, option);
276276
}
277+
e.setRequestId(reqId);
277278
throw e;
278279
}
279280
}
@@ -332,6 +333,7 @@ private List<Partition> partitionQuery(
332333
if (!isFallback && maybeMarkUnimplementedForPartitionedOps(e)) {
333334
return partitionQuery(partitionOptions, statement, true, option);
334335
}
336+
e.setRequestId(reqId);
335337
throw e;
336338
}
337339
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/PartitionedDmlTransaction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ long executeStreamingPartitionedUpdate(
127127
request = newTransactionRequestFrom(statement, options);
128128
// Create a new xGoogSpannerRequestId.
129129
reqId = session.getRequestIdCreator().nextRequestId(1 /*TODO: infer channelId*/, 0);
130+
} catch (SpannerException e) {
131+
e.setRequestId(reqId);
132+
throw e;
130133
}
131134
}
132135
if (!foundStats) {
@@ -226,7 +229,8 @@ private ByteString initTransaction(final Options options) {
226229
if (tx.getId().isEmpty()) {
227230
throw SpannerExceptionFactory.newSpannerException(
228231
ErrorCode.INTERNAL,
229-
"Failed to init transaction, missing transaction id\n" + session.getName());
232+
"Failed to init transaction, missing transaction id\n" + session.getName(),
233+
reqId);
230234
}
231235
return tx.getId();
232236
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/ResumableStreamIterator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ private void backoffSleep(Context context, long backoffMillis) throws SpannerExc
187187
}
188188
if (latch.await(backoffMillis, TimeUnit.MILLISECONDS)) {
189189
// Woken by context cancellation.
190-
throw newSpannerExceptionForCancellation(context, null, null /*TODO: requestId*/);
190+
throw newSpannerExceptionForCancellation(context, null, this.xGoogRequestId);
191191
}
192192
} catch (InterruptedException interruptExcept) {
193-
throw newSpannerExceptionForCancellation(context, interruptExcept, null /*TODO: requestId*/);
193+
throw newSpannerExceptionForCancellation(context, interruptExcept, this.xGoogRequestId);
194194
} finally {
195195
context.removeListener(listener);
196196
}
@@ -324,6 +324,7 @@ && prepareIteratorForRetryOnDifferentGrpcChannel()) {
324324
}
325325
span.addAnnotation("Stream broken. Not safe to retry", spannerException);
326326
span.setStatus(spannerException);
327+
spannerException.setRequestId(this.xGoogRequestId);
327328
throw spannerException;
328329
} catch (RuntimeException e) {
329330
span.addAnnotation("Stream broken. Not safe to retry", e);

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerException.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public String getResourceName() {
5757

5858
private final ErrorCode code;
5959
private final ApiException apiException;
60-
private final XGoogSpannerRequestId requestId;
60+
private XGoogSpannerRequestId requestId;
6161

6262
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
6363
SpannerException(
@@ -197,4 +197,9 @@ public ErrorDetails getErrorDetails() {
197197
}
198198
return null;
199199
}
200+
201+
/** Sets the requestId. This method is meant to be used internally and not by customers. */
202+
public void setRequestId(XGoogSpannerRequestId reqId) {
203+
this.requestId = reqId;
204+
}
200205
}

0 commit comments

Comments
 (0)