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

style: add Error Prone and suppress existing errors #3621

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -72,6 +72,8 @@ public StreamObserver<SpannerAsyncActionRequest> executeActionAsync(
// Create a top-level OpenTelemetry span for streaming request.
Tracer tracer = WorkerProxy.openTelemetrySdk.getTracer(CloudClientExecutor.class.getName());
Span span = tracer.spanBuilder("java_systest_execute_actions_stream").setNoParent().startSpan();
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("MustBeClosedChecker")
Scope scope = span.makeCurrent();

final String traceId = span.getSpanContext().getTraceId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ protected boolean isRouteToLeader() {
return false;
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@GuardedBy("lock")
@Override
void beforeReadOrQueryLocked() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Span getSpan() {

@Override
public Scope inScope() {
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("MustBeClosedChecker")
final io.opentelemetry.context.Scope openTelemetryScope = span.makeCurrent();
return openTelemetryScope::close;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,8 @@ void appendToOptions(Options options) {
options.filter = filter;
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("EqualsHashCode")
@Override
public boolean equals(Object o) {
if (o == this) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ public PooledSessionFuture replaceSession(
}
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Override
public PooledSessionFuture denyListSession(
RetryOnDifferentGrpcChannelException retryException, PooledSessionFuture session) {
Expand Down Expand Up @@ -1760,6 +1762,8 @@ public ApiFuture<Empty> asyncClose() {
return ApiFutures.immediateFuture(Empty.getDefaultInstance());
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Override
public void close() {
synchronized (lock) {
Expand Down Expand Up @@ -1840,12 +1844,16 @@ public SessionImpl getDelegate() {
return this.delegate;
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Override
public void markBusy(ISpan span) {
this.delegate.setCurrentSpan(span);
this.state = SessionState.BUSY;
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private void markClosing() {
this.state = SessionState.CLOSING;
}
Expand Down Expand Up @@ -2082,6 +2090,8 @@ void maintainPool() {
removeLongRunningSessions(currTime);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private void removeIdleSessions(Instant currTime) {
synchronized (lock) {
// Determine the minimum last use time for a session to be deemed to still be alive. Remove
Expand Down Expand Up @@ -2181,6 +2191,8 @@ void removeLongRunningSessions(Instant currentTime) {
}
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private void removeLongRunningSessions(
final Instant currentTime,
final InactiveTransactionRemovalOptions inactiveTransactionRemovalOptions) {
Expand Down Expand Up @@ -2680,6 +2692,8 @@ private void invalidateSession(PooledSession session) {
}
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private Tuple<PooledSession, Integer> findSessionToKeepAlive(
Queue<PooledSession> queue, Instant keepAliveThreshold, int numAlreadyChecked) {
int numChecked = 0;
Expand Down Expand Up @@ -2871,6 +2885,8 @@ private void releaseSession(PooledSession session, boolean isNewSession) {
}

/** Releases a session back to the pool. This might cause one of the waiters to be unblocked. */
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private void releaseSession(
PooledSession session, boolean isNewSession, @Nullable Integer position) {
Preconditions.checkNotNull(session);
Expand Down Expand Up @@ -2931,13 +2947,17 @@ private void releaseSession(
* running many small, quick queries using a small number of parallel threads. This can cause a
* high TPS, without actually having a high degree of parallelism.
*/
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@VisibleForTesting
boolean shouldRandomize() {
return this.options.getRandomizePositionQPSThreshold() > 0
&& this.transactionsPerSecond >= this.options.getRandomizePositionQPSThreshold()
&& this.numSessionsInUse >= this.numChannels;
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private boolean isUnbalanced(PooledSession session) {
int channel = session.getChannel();
int numChannels = sessionClient.getSpanner().getOptions().getNumChannels();
Expand Down Expand Up @@ -3040,10 +3060,14 @@ private void handleCreateSessionsFailure(SpannerException e, int count) {
}
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
void setResourceNotFoundException(ResourceNotFoundException e) {
this.resourceNotFoundException = MoreObjects.firstNonNull(this.resourceNotFoundException, e);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private void decrementPendingClosures(int count) {
pendingClosure -= count;
if (pendingClosure == 0) {
Expand All @@ -3056,6 +3080,8 @@ private void decrementPendingClosures(int count) {
* {@code IllegalStateException}. The returned future blocks till all the sessions created in this
* pool have been closed.
*/
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
ListenableFuture<Void> closeAsync(ClosedException closedException) {
ListenableFuture<Void> retFuture = null;
synchronized (lock) {
Expand Down Expand Up @@ -3253,6 +3279,8 @@ public void onSessionCreateFailure(Throwable t, int createFailureForSessionCount
* Initializes and creates Spanner session relevant metrics using OpenCensus. When coupled with an
* exporter, it allows users to monitor client behavior.
*/
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private void initOpenCensusMetricsCollection(
MetricRegistry metricRegistry,
List<LabelValue> labelValues,
Expand Down Expand Up @@ -3386,6 +3414,8 @@ private void initOpenCensusMetricsCollection(
* Initializes and creates Spanner session relevant metrics using OpenTelemetry. When coupled with
* an exporter, it allows users to monitor client behavior.
*/
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private void initOpenTelemetryMetricsCollection(
OpenTelemetry openTelemetry,
Attributes attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ public void close() {
close(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
void close(long timeout, TimeUnit unit) {
List<ListenableFuture<Void>> closureFutures;
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,8 @@ public static void enableOpenCensusTraces() {
* Always resets the activeTracingFramework. This variable is used for internal testing, and is
* not a valid production scenario
*/
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@ObsoleteApi(
"The OpenCensus project is deprecated. Use enableOpenTelemetryTraces to switch to OpenTelemetry traces")
@VisibleForTesting
Expand Down Expand Up @@ -1892,6 +1894,8 @@ private ApiTracerFactory createApiTracerFactory(
return new CompositeTracerFactory(apiTracerFactories);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
private ApiTracerFactory getDefaultApiTracerFactory() {
if (isEnableApiTracing()) {
if (activeTracingFramework == TracingFramework.OPEN_TELEMETRY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ ISpan getBlankSpan() {
}
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("MustBeClosedChecker")
IScope withSpan(ISpan span) {
if (SpannerOptions.getActiveTracingFramework().equals(TracingFramework.OPEN_TELEMETRY)) {
OpenTelemetrySpan openTelemetrySpan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ public <ReqT, RespT> ApiCallContext configure(
}
future.addListener(
new Runnable() {
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Override
public void run() {
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public void testGetExecuteBatchDmlRequestBuilderWithPriority() {
assertEquals(Priority.PRIORITY_LOW, request.getRequestOptions().getPriority());
}

@Test
public void executeSqlRequestBuilderWithRequestOptions() {
ExecuteSqlRequest request =
context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,8 @@ public void singleUse() {
DatabaseClientImpl client =
(DatabaseClientImpl)
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
Set<PooledSessionFuture> checkedOut = client.pool.checkedOutSessions;
assertThat(checkedOut).isEmpty();
try (ResultSet rs = client.singleUse().executeQuery(SELECT1)) {
Expand Down Expand Up @@ -3986,6 +3988,8 @@ public void testCreateSessionsFailure_shouldNotPropagateToCloseMethod() {
@Test
public void testReadWriteTransaction_usesOptions() {
SessionPool pool = mock(SessionPool.class);
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("DoNotMock")
PooledSessionFuture session = mock(PooledSessionFuture.class);
when(pool.getSession()).thenReturn(session);
TransactionOption option = mock(TransactionOption.class);
Expand All @@ -4002,6 +4006,8 @@ public void testReadWriteTransaction_usesOptions() {
@Test
public void testTransactionManager_usesOptions() {
SessionPool pool = mock(SessionPool.class);
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("DoNotMock")
PooledSessionFuture session = mock(PooledSessionFuture.class);
when(pool.getSession()).thenReturn(session);
TransactionOption option = mock(TransactionOption.class);
Expand All @@ -4015,6 +4021,8 @@ public void testTransactionManager_usesOptions() {
@Test
public void testRunAsync_usesOptions() {
SessionPool pool = mock(SessionPool.class);
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("DoNotMock")
PooledSessionFuture session = mock(PooledSessionFuture.class);
when(pool.getSession()).thenReturn(session);
TransactionOption option = mock(TransactionOption.class);
Expand All @@ -4028,6 +4036,8 @@ public void testRunAsync_usesOptions() {
@Test
public void testTransactionManagerAsync_usesOptions() {
SessionPool pool = mock(SessionPool.class);
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("DoNotMock")
PooledSessionFuture session = mock(PooledSessionFuture.class);
when(pool.getSession()).thenReturn(session);
TransactionOption option = mock(TransactionOption.class);
Expand Down Expand Up @@ -4365,6 +4375,8 @@ public void singleUseNoAction_ClearsCheckedOutSession() {
DatabaseClientImpl client =
(DatabaseClientImpl)
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
Set<PooledSessionFuture> checkedOut = client.pool.checkedOutSessions;
assertThat(checkedOut).isEmpty();

Expand All @@ -4380,6 +4392,8 @@ public void singleUseReadOnlyTransactionNoAction_ClearsCheckedOutSession() {
DatabaseClientImpl client =
(DatabaseClientImpl)
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
Set<PooledSessionFuture> checkedOut = client.pool.checkedOutSessions;
assertThat(checkedOut).isEmpty();

Expand All @@ -4393,6 +4407,8 @@ public void readWriteTransactionNoAction_ClearsCheckedOutSession() {
DatabaseClientImpl client =
(DatabaseClientImpl)
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
Set<PooledSessionFuture> checkedOut = client.pool.checkedOutSessions;
assertThat(checkedOut).isEmpty();

Expand All @@ -4406,6 +4422,8 @@ public void readOnlyTransactionNoAction_ClearsCheckedOutSession() {
DatabaseClientImpl client =
(DatabaseClientImpl)
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
Set<PooledSessionFuture> checkedOut = client.pool.checkedOutSessions;
assertThat(checkedOut).isEmpty();

Expand All @@ -4419,6 +4437,8 @@ public void transactionManagerNoAction_ClearsCheckedOutSession() {
DatabaseClientImpl client =
(DatabaseClientImpl)
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
Set<PooledSessionFuture> checkedOut = client.pool.checkedOutSessions;
assertThat(checkedOut).isEmpty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public void testUnspecifiedDialectDefaultsToGoogleStandardSqlDialect() {
assertEquals(Dialect.GOOGLE_STANDARD_SQL, database.getDialect());
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("SetUnrecognized")
@Test
public void testUnrecognizedDialectThrowsException() {
assertThrows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ public void idleSessionCleanup() throws Exception {
pool.closeAsync(new SpannerImpl.ClosedException()).get(5L, TimeUnit.SECONDS);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Test
public void longRunningTransactionsCleanup_whenActionSetToClose_verifyInactiveSessionsClosed()
throws Exception {
Expand Down Expand Up @@ -856,6 +858,8 @@ public void longRunningTransactionsCleanup_whenActionSetToClose_verifyInactiveSe
pool.closeAsync(new SpannerImpl.ClosedException()).get(5L, TimeUnit.SECONDS);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Test
public void longRunningTransactionsCleanup_whenActionSetToWarn_verifyInactiveSessionsOpen()
throws Exception {
Expand Down Expand Up @@ -904,6 +908,8 @@ public void longRunningTransactionsCleanup_whenActionSetToWarn_verifyInactiveSes
pool.closeAsync(new SpannerImpl.ClosedException()).get(5L, TimeUnit.SECONDS);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Test
public void
longRunningTransactionsCleanup_whenUtilisationBelowThreshold_verifyInactiveSessionsOpen()
Expand Down Expand Up @@ -947,6 +953,8 @@ public void longRunningTransactionsCleanup_whenActionSetToWarn_verifyInactiveSes
pool.closeAsync(new SpannerImpl.ClosedException()).get(5L, TimeUnit.SECONDS);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Test
public void
longRunningTransactionsCleanup_whenAllAreExpectedlyLongRunning_verifyInactiveSessionsOpen()
Expand Down Expand Up @@ -1013,6 +1021,8 @@ public void longRunningTransactionsCleanup_whenActionSetToWarn_verifyInactiveSes
pool.closeAsync(new SpannerImpl.ClosedException()).get(5L, TimeUnit.SECONDS);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Test
public void longRunningTransactionsCleanup_whenBelowDurationThreshold_verifyInactiveSessionsOpen()
throws Exception {
Expand Down Expand Up @@ -1058,6 +1068,8 @@ public void longRunningTransactionsCleanup_whenBelowDurationThreshold_verifyInac
pool.closeAsync(new SpannerImpl.ClosedException()).get(5L, TimeUnit.SECONDS);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Test
public void longRunningTransactionsCleanup_whenException_doNothing() throws Exception {
Clock clock = mock(Clock.class);
Expand Down Expand Up @@ -1101,6 +1113,8 @@ public void longRunningTransactionsCleanup_whenException_doNothing() throws Exce
pool.closeAsync(new SpannerImpl.ClosedException()).get(5L, TimeUnit.SECONDS);
}

// Suppressed for initial Error Prone rollout.
@SuppressWarnings("GuardedBy")
@Test
public void
longRunningTransactionsCleanup_whenTaskRecurrenceBelowThreshold_verifyInactiveSessionsOpen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static List<PooledSession> mockedSessions(int... channels) {

static PooledSessionFuture mockedCheckedOutSession(int channel) {
PooledSession session = mockedSession(channel);
// Suppressed for initial Error Prone rollout.
@SuppressWarnings("DoNotMock")
PooledSessionFuture future = mock(PooledSessionFuture.class);
when(future.get()).thenReturn(session);
when(future.isDone()).thenReturn(true);
Expand Down
Loading