Skip to content

Commit 4072c7c

Browse files
Add logs to find the issue at root
1 parent 21733d5 commit 4072c7c

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -469,19 +469,19 @@ public void run() {
469469
// Those result sets will trigger initiateProduceRows() when the first results are received.
470470
// Non-streaming result sets do not trigger this callback, and for those result sets, we
471471
// need to eagerly start the ProduceRowsRunnable.
472-
synchronized (monitor) {
473-
if (state == State.STREAMING_IN_PROGRESS
474-
|| state == State.RUNNING
475-
|| state == State.CONSUMING) {
476-
return;
477-
}
478-
if (state == State.STREAMING_INITIALIZED) {
479-
state = State.STREAMING_IN_PROGRESS;
480-
}
481-
if (!initiateStreaming(AsyncResultSetImpl.this)) {
482-
initiateProduceRows();
483-
}
472+
// synchronized (monitor) {
473+
// if (state == State.STREAMING_IN_PROGRESS
474+
// || state == State.RUNNING
475+
// || state == State.CONSUMING) {
476+
// return;
477+
// }
478+
// if (state == State.STREAMING_INITIALIZED) {
479+
// state = State.STREAMING_IN_PROGRESS;
480+
// }
481+
if (!initiateStreaming(AsyncResultSetImpl.this)) {
482+
initiateProduceRows();
484483
}
484+
// }
485485
} catch (Throwable exception) {
486486
executionException = SpannerExceptionFactory.asSpannerException(exception);
487487
initiateProduceRows();
@@ -492,6 +492,7 @@ public void run() {
492492
/** Sets the callback for this {@link AsyncResultSet}. */
493493
@Override
494494
public ApiFuture<Void> setCallback(Executor exec, ReadyCallback cb) {
495+
System.out.println("Inside setCallback");
495496
synchronized (monitor) {
496497
Preconditions.checkState(!closed, "This AsyncResultSet has been closed");
497498
Preconditions.checkState(
@@ -510,7 +511,7 @@ public ApiFuture<Void> setCallback(Executor exec, ReadyCallback cb) {
510511

511512
private void initiateProduceRows() {
512513
synchronized (monitor) {
513-
if (this.state == State.STREAMING_IN_PROGRESS) {
514+
if (this.state == State.STREAMING_INITIALIZED) {
514515
this.state = State.RUNNING;
515516
}
516517
produceRowsInitiated = true;
@@ -660,7 +661,7 @@ public void onStreamMessage(PartialResultSet partialResultSet, boolean bufferIsF
660661
!partialResultSet.getResumeToken().isEmpty()
661662
|| bufferIsFull
662663
|| partialResultSet == GrpcStreamIterator.END_OF_STREAM;
663-
if (startJobThread || state != State.STREAMING_IN_PROGRESS) {
664+
if (startJobThread || state != State.STREAMING_INITIALIZED) {
664665
initiateProduceRows();
665666
}
666667
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ private ByteString generateTransactionName(String session) {
651651
counter = new AtomicLong();
652652
transactionCounters.put(session, counter);
653653
}
654+
System.out.printf("Generating session using Session ID %s\n", session);
654655
return ByteString.copyFromUtf8(
655656
String.format("%s/transactions/%d", session, counter.incrementAndGet()));
656657
}
@@ -1999,6 +2000,8 @@ private void ensureMostRecentTransaction(Session session, ByteString transaction
19992000
if (index > -1) {
20002001
long id = Long.parseLong(transactionId.toStringUtf8().substring(index + 1));
20012002
if (id != counter.get()) {
2003+
System.out.printf(
2004+
"Session ID %s TransactionId %s\n", session.getName(), transactionId.toStringUtf8());
20022005
throw Status.FAILED_PRECONDITION
20032006
.withDescription(
20042007
String.format(

google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnInvalidatedSessionTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@
6060
import org.junit.AfterClass;
6161
import org.junit.Before;
6262
import org.junit.BeforeClass;
63+
import org.junit.Rule;
6364
import org.junit.Test;
65+
import org.junit.rules.TestRule;
66+
import org.junit.rules.TestWatcher;
67+
import org.junit.runner.Description;
6468
import org.junit.runner.RunWith;
6569
import org.junit.runners.Parameterized;
6670
import org.junit.runners.Parameterized.Parameter;
@@ -75,6 +79,24 @@ public Long apply(StructReader input) {
7579
}
7680
}
7781

82+
@Rule
83+
public TestWatcher testWatcher = new TestWatcher() {
84+
@Override
85+
protected void succeeded(Description description) {
86+
System.out.println("Succeeded test: " + description.getMethodName());
87+
}
88+
89+
@Override
90+
protected void failed(Throwable e, Description description) {
91+
System.out.println("Failed test: " + description.getMethodName());
92+
}
93+
94+
@Override
95+
protected void starting(Description description) {
96+
System.out.println("Starting test: " + description.getMethodName());
97+
}
98+
};
99+
78100
private static final ToLongTransformer TO_LONG = new ToLongTransformer();
79101

80102
@Parameter(0)
@@ -1434,6 +1456,8 @@ private void asyncRunner_withReadFunction(
14341456
runner.runAsync(
14351457
txn -> {
14361458
AsyncResultSet rs = readFunction.apply(txn);
1459+
System.out.println(rs);
1460+
System.out.println("Creating a new AsyncResultSet");
14371461
ApiFuture<Void> fut =
14381462
rs.setCallback(
14391463
queryExecutor,
@@ -1450,6 +1474,7 @@ private void asyncRunner_withReadFunction(
14501474
}
14511475
}
14521476
});
1477+
System.out.println("After setCallback");
14531478
return ApiFutures.transform(
14541479
fut, input -> counter.get(), MoreExecutors.directExecutor());
14551480
},
@@ -1573,6 +1598,8 @@ private void asyncTransactionManager_readAsync(
15731598
context.then(
15741599
(transaction, ignored) -> {
15751600
AsyncResultSet rs = fn.apply(transaction);
1601+
System.out.println(rs);
1602+
System.out.println("1. Creating a new AsyncResultSet");
15761603
ApiFuture<Void> fut =
15771604
rs.setCallback(
15781605
queryExecutor,

0 commit comments

Comments
 (0)