Skip to content
Draft
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 @@ -40,7 +40,7 @@
* @since 5.2
*/
@Alpha(Reason.CLIENT)
public final class MongoOperationTimeoutException extends MongoTimeoutException {
public final class MongoOperationTimeoutException extends MongoClientException {
private static final long serialVersionUID = 1L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private void logAndThrowTimeoutException(
"Timed out while waiting for a server that matches %s. Client view of cluster state is %s",
serverSelector, clusterDescription.getShortDescription());

MongoTimeoutException exception = operationContext.getTimeoutContext().hasTimeoutMS()
MongoClientException exception = operationContext.getTimeoutContext().hasTimeoutMS()
? new MongoOperationTimeoutException(message) : new MongoTimeoutException(message);

logServerSelectionFailed(operationContext, clusterId, exception, serverSelector, clusterDescription);
Expand Down Expand Up @@ -590,7 +590,7 @@ private static void logServerSelectionFailed(
final ServerSelector serverSelector,
final ClusterDescription clusterDescription) {
if (STRUCTURED_LOGGER.isRequired(DEBUG, clusterId)) {
String failureDescription = failure instanceof MongoTimeoutException
String failureDescription = failure instanceof MongoTimeoutException || failure instanceof MongoOperationTimeoutException
// This hardcoded message guarantees that the `FAILURE` entry for `MongoTimeoutException` does not include
// any information that is specified via other entries, e.g., `SELECTOR` and `TOPOLOGY_DESCRIPTION`.
// The logging spec requires us to avoid such duplication of information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.mongodb.internal.connection;

import com.mongodb.MongoClientException;
import com.mongodb.MongoConnectionPoolClearedException;
import com.mongodb.MongoException;
import com.mongodb.MongoInterruptedException;
import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoServerUnavailableException;
import com.mongodb.MongoTimeoutException;
import com.mongodb.annotations.NotThreadSafe;
Expand Down Expand Up @@ -256,7 +258,7 @@ public void getAsync(final OperationContext operationContext, final SingleResult
private Throwable checkOutFailed(final Throwable t, final OperationContext operationContext, final StartTime checkoutStart) {
Throwable result = t;
Reason reason;
if (t instanceof MongoTimeoutException) {
if (t instanceof MongoTimeoutException || t instanceof MongoOperationTimeoutException) {
reason = Reason.TIMEOUT;
} else if (t instanceof MongoOpenConnectionInternalException) {
reason = Reason.CONNECTION_ERROR;
Expand Down Expand Up @@ -334,7 +336,7 @@ public int getGeneration() {

private PooledConnection getPooledConnection(final Timeout maxWaitTimeout,
final StartTime startTime,
final TimeoutContext timeoutContext) throws MongoTimeoutException {
final TimeoutContext timeoutContext) throws MongoClientException {
try {
UsageTrackingInternalConnection internalConnection = maxWaitTimeout.call(NANOSECONDS,
() -> pool.get(-1L, NANOSECONDS),
Expand Down Expand Up @@ -363,9 +365,9 @@ private PooledConnection getPooledConnectionImmediate() {
return internalConnection == null ? null : new PooledConnection(internalConnection);
}

private MongoTimeoutException createTimeoutException(final StartTime startTime,
@Nullable final MongoTimeoutException cause,
final TimeoutContext timeoutContext) {
private MongoClientException createTimeoutException(final StartTime startTime,
@Nullable final MongoTimeoutException cause,
final TimeoutContext timeoutContext) {
long elapsedMs = startTime.elapsed().toMillis();
int numPinnedToCursor = pinnedStatsManager.getNumPinnedToCursor();
int numPinnedToTransaction = pinnedStatsManager.getNumPinnedToTransaction();
Expand Down Expand Up @@ -425,6 +427,7 @@ ConcurrentPool<UsageTrackingInternalConnection> getPool() {
void doMaintenance() {
Predicate<Exception> silentlyComplete = e ->
e instanceof MongoInterruptedException || e instanceof MongoTimeoutException
|| e instanceof MongoOperationTimeoutException
|| e instanceof MongoConnectionPoolClearedException || ConcurrentPool.isPoolClosedException(e);
try {
pool.prune();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private MongoClientException createResolvedToMultipleHostsException() {
+ "to multiple hosts");
}

private MongoTimeoutException createTimeoutException(final TimeoutContext timeoutContext) {
private MongoClientException createTimeoutException(final TimeoutContext timeoutContext) {
MongoException localSrvResolutionException = srvResolutionException;
String message;
if (localSrvResolutionException == null) {
Expand All @@ -334,7 +334,7 @@ private MongoTimeoutException createTimeoutException(final TimeoutContext timeou
return createTimeoutException(timeoutContext, message);
}

private static MongoTimeoutException createTimeoutException(final TimeoutContext timeoutContext, final String message) {
private static MongoClientException createTimeoutException(final TimeoutContext timeoutContext, final String message) {
return timeoutContext.hasTimeoutMS() ? new MongoOperationTimeoutException(message) : new MongoTimeoutException(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.mongodb.MongoExecutionTimeoutException;
import com.mongodb.MongoNamespace;
import com.mongodb.MongoNodeIsRecoveringException;
import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoNotPrimaryException;
import com.mongodb.MongoSocketException;
import com.mongodb.MongoTimeoutException;
Expand Down Expand Up @@ -103,6 +104,7 @@ private void addErrorLabels(final MongoException e) {
private static boolean shouldAddUnknownTransactionCommitResultLabel(final MongoException e) {

if (e instanceof MongoSocketException || e instanceof MongoTimeoutException
|| e instanceof MongoOperationTimeoutException
|| e instanceof MongoNotPrimaryException || e instanceof MongoNodeIsRecoveringException
|| e instanceof MongoExecutionTimeoutException) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.mongodb.MongoClientException;
import com.mongodb.MongoException;
import com.mongodb.MongoInternalException;
import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoQueryException;
import com.mongodb.MongoSocketException;
import com.mongodb.MongoTimeoutException;
Expand Down Expand Up @@ -203,6 +204,7 @@ private <T> RequestContext getContext(final Subscriber<T> subscriber) {
private void labelException(@Nullable final ClientSession session, @Nullable final Throwable t) {
if (session != null && session.hasActiveTransaction()
&& (t instanceof MongoSocketException || t instanceof MongoTimeoutException
|| t instanceof MongoOperationTimeoutException
|| (t instanceof MongoQueryException && ((MongoQueryException) t).getErrorCode() == 91))
&& !((MongoException) t).hasErrorLabel(UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL)) {
((MongoException) t).addLabel(TRANSIENT_TRANSACTION_ERROR_LABEL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.mongodb.MongoClientException;
import com.mongodb.MongoException;
import com.mongodb.MongoInternalException;
import com.mongodb.MongoOperationTimeoutException;
import com.mongodb.MongoQueryException;
import com.mongodb.MongoSocketException;
import com.mongodb.MongoTimeoutException;
Expand Down Expand Up @@ -535,6 +536,7 @@ private RequestContext getRequestContext() {

private void labelException(final ClientSession session, final MongoException e) {
if (session.hasActiveTransaction() && (e instanceof MongoSocketException || e instanceof MongoTimeoutException
|| e instanceof MongoOperationTimeoutException
|| e instanceof MongoQueryException && e.getCode() == 91)
&& !e.hasErrorLabel(UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL)) {
e.addLabel(TRANSIENT_TRANSACTION_ERROR_LABEL);
Expand Down