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

Port transactions spec tests to unified format #1310

Merged
merged 10 commits into from Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,6 +19,7 @@
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCommandException;
import com.mongodb.MongoNamespace;
import com.mongodb.MongoWriteConcernException;
import com.mongodb.ReadPreference;
import com.mongodb.ServerCursor;
import com.mongodb.WriteConcern;
Expand All @@ -34,6 +35,8 @@
import com.mongodb.internal.bulk.UpdateRequest;
import com.mongodb.internal.bulk.WriteRequest;
import com.mongodb.internal.client.model.AggregationLevel;
import com.mongodb.internal.diagnostics.logging.Logger;
import com.mongodb.internal.diagnostics.logging.Loggers;
import com.mongodb.internal.operation.AggregateOperation;
import com.mongodb.internal.operation.BatchCursor;
import com.mongodb.internal.operation.CommandReadOperation;
Expand Down Expand Up @@ -70,6 +73,7 @@
import static java.util.Collections.singletonList;

public final class CollectionHelper<T> {
private static final Logger LOGGER = Loggers.getLogger("test");

private final Codec<T> codec;
private final CodecRegistry registry = MongoClientSettings.getDefaultCodecRegistry();
Expand All @@ -89,7 +93,18 @@ public static void drop(final MongoNamespace namespace) {
}

public static void drop(final MongoNamespace namespace, final WriteConcern writeConcern) {
new DropCollectionOperation(namespace, writeConcern).execute(getBinding());
// This loop is a workaround for unanticipated failures of the create command when run on a sharded cluster < 4.2.
stIncMale marked this conversation as resolved.
Show resolved Hide resolved
// In practice the command tends to succeed on the first attempt after a failure
boolean success = false;
Copy link
Contributor Author

@jyemin jyemin Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On sharded clusters < 4.2, drop sometimes fails on the first try with a write concern error. Trying again works around it. Same for create below, except with a different exception. :(

I'm curious whether other drivers will run into this. I imagine they will and if so a DRIVERS ticket is probably in order. What do you think @jmikola ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall encountering a PHPLIB build failure for drop or create in this context. If you want to open a DRIVERS ticket, I'd suggest including the server errors in the description and immediately opening a specs PR with the desired clarification while this is still fresh on your mind.

while (!success) {
stIncMale marked this conversation as resolved.
Show resolved Hide resolved
try {
new DropCollectionOperation(namespace, writeConcern).execute(getBinding());
success = true;
} catch (MongoWriteConcernException e) {
LOGGER.info("Retrying drop collection after a write concern error: " + e);
// repeat until success!
}
}
}

public static void dropDatabase(final String name) {
Expand Down Expand Up @@ -154,7 +169,23 @@ public void create(final String collectionName, final CreateCollectionOptions op
if (validationOptions.getValidationAction() != null) {
operation.validationAction(validationOptions.getValidationAction());
}
operation.execute(getBinding());

// This loop is a workaround for unanticipated failures of the create command when run on a sharded cluster < 4.2
// In practice the command tends to succeed on the first attempt after a failure
boolean success = false;
while (!success) {
try {
operation.execute(getBinding());
success = true;
} catch (MongoCommandException e) {
if ("Interrupted".equals(e.getErrorCodeName())) {
LOGGER.info("Retrying create collection after a write concern error: " + e);
// repeat until success!
} else {
throw e;
}
}
}
}

public void killCursor(final MongoNamespace namespace, final ServerCursor serverCursor) {
Expand Down Expand Up @@ -394,7 +425,7 @@ public List<BsonDocument> listIndexes(){
return indexes;
}

public void killAllSessions() {
public static void killAllSessions() {
try {
new CommandReadOperation<>("admin", new BsonDocument("killAllSessions", new BsonArray()),
new BsonDocumentCodec()).execute(getBinding());
Expand Down
220 changes: 0 additions & 220 deletions driver-core/src/test/resources/transactions-convenient-api/README.rst

This file was deleted.